def test_influx_service_not_inited(self): self.setUpLogging() self.patch(storage_backends.influxdb_client, 'InfluxDBClient', fakestats.FakeInfluxDBClient) svc = InfluxStorageService( "fake_url", "fake_port", "fake_user", "fake_password", "fake_db", "fake_stats") svc._inited = False svc.thd_postStatsValue("test", "test", "test") self.assertLogged("Service.*not initialized")
def test_influx_service_not_inited(self): self.setUpLogging() self.patch(storage_backends.influxdb_client, 'InfluxDBClient', fakestats.FakeInfluxDBClient) svc = InfluxStorageService( "fake_url", "fake_port", "fake_user", "fake_password", "fake_db", "fake_stats") svc._inited = False svc.thd_postStatsValue("test", "test", "test") self.assertLogged("Service.*not initialized")
def test_influx_storage_service_fake_install(self): # use a fake InfluxDBClient to test InfluxStorageService in systems which # don't have influxdb installed. Primarily useful for test coverage. self.patch(storage_backends.influxdb_client, 'InfluxDBClient', fakestats.FakeInfluxDBClient) captures = [capture.CaptureProperty('test_builder', 'test')] new_storage_backends = [InfluxStorageService( "fake_url", "fake_port", "fake_user", "fake_password", "fake_db", captures )] self.stats_service.reconfigService(new_storage_backends)
def test_influxdb_not_installed(self): captures = [capture.CaptureProperty('test_builder', 'test')] try: # Try to import import influxdb # pylint: disable=import-outside-toplevel # consume it somehow to please pylint [influxdb] except ImportError: with self.assertRaises(config.ConfigErrors): InfluxStorageService("fake_url", "fake_port", "fake_user", "fake_password", "fake_db", captures) # if instead influxdb is installed, then initialize it - no errors # should be realized else: new_storage_backends = [ InfluxStorageService("fake_url", "fake_port", "fake_user", "fake_password", "fake_db", captures) ] yield self.stats_service.reconfigService(new_storage_backends)
def test_influx_storage_service_post_value(self): # test the thd_postStatsValue method of InfluxStorageService self.patch(storage_backends.influxdb_client, 'InfluxDBClient', fakestats.FakeInfluxDBClient) svc = InfluxStorageService("fake_url", "fake_port", "fake_user", "fake_password", "fake_db", "fake_stats") post_data = {'name': 'test', 'value': 'test'} context = {'x': 'y'} svc.thd_postStatsValue(post_data, "test_series_name", context) data = { 'measurement': "test_series_name", 'fields': { "name": "test", "value": "test" }, 'tags': { 'x': 'y' } } points = [data] self.assertEqual(svc.client.points, points)
def test_influx_storage_service_post_value(self): # test the thd_postStatsValue method of InfluxStorageService self.patch(storage_backends.influxdb_client, 'InfluxDBClient', fakestats.FakeInfluxDBClient) svc = InfluxStorageService( "fake_url", "fake_port", "fake_user", "fake_password", "fake_db", "fake_stats") post_data = { 'name': 'test', 'value': 'test' } context = {'x': 'y'} svc.thd_postStatsValue(post_data, "test_series_name", context) data = { 'measurement': "test_series_name", 'fields': { "name": "test", "value": "test" }, 'tags': {'x': 'y'} } points = [data] self.assertEquals(svc.client.points, points)