forked from omergertel/pyformance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest__influx_reporter.py
34 lines (27 loc) · 1.08 KB
/
test__influx_reporter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import os
import mock
try:
from urllib2 import Request
except ImportError:
from urllib.request import Request
from pyformance.reporters.influx import InfluxReporter
from pyformance import MetricsRegistry
from tests import TimedTestCase
class TestInfluxReporter(TimedTestCase):
def setUp(self):
super(TestInfluxReporter, self).setUp()
self.registry = MetricsRegistry()
def tearDown(self):
super(TestInfluxReporter, self).tearDown()
def test_report_now(self):
influx_reporter = InfluxReporter(registry=self.registry)
with mock.patch("pyformance.reporters.influx.urlopen") as patch:
influx_reporter.report_now()
patch.assert_called()
def test_create_database(self):
r1 = InfluxReporter(registry=self.registry, autocreate_database=True)
with mock.patch("pyformance.reporters.influx.urlopen") as patch:
r1.report_now()
if patch.call_count != 2:
raise AssertionError(
"Expected 2 calls to 'urlopen'. Received: {}".format(patch.call_count))