indentation is not a multiple of 4
18
19 # amqp not supported with py3
20 try:
21 import carbon.amqp_listener 22 expected_plugins.append('amqp')
23 except ImportError:
24 pass
indentation is not a multiple of 4
19 # amqp not supported with py3
20 try:
21 import carbon.amqp_listener
22 expected_plugins.append('amqp') 23 except ImportError:
24 pass
25
indentation is not a multiple of 4
21 import carbon.amqp_listener
22 expected_plugins.append('amqp')
23 except ImportError:
24 pass 25
26 # Can't always test manhole because 'cryptography' can
27 # be a pain to install and we don't want to make the CI
indentation is not a multiple of 4
28 # flaky because of that.
29 try:
30 import carbon.manhole # NOQA
31 expected_plugins.append('manhole') 32 except ImportError:
33 pass
34
indentation is not a multiple of 4
30 import carbon.manhole # NOQA
31 expected_plugins.append('manhole')
32 except ImportError:
33 pass 34
35 expected_plugins = sorted(expected_plugins)
36 plugins = sorted(MetricReceiver.plugins.keys())
indentation is not a multiple of 4
37 self.assertEquals(expected_plugins, plugins)
38
39 class _FakeService(object):
40 def addService(_, __): 41 pass
42 fake_service = _FakeService()
43
indentation is not a multiple of 4
42 fake_service = _FakeService()
43
44 for plugin_name, plugin_class in MetricReceiver.plugins.items():
45 plugin_class.build(fake_service) 46
47
48class TestMetricReceiver(TestCase):
indentation is not a multiple of 4
358 self.send_request('cache-query-bulk', metrics=[])
359 self.assertEquals({'datapointsByMetric': {}}, self.response)
360
361 def test_cache_bulk_query_response(self):362 self.cache.store('carbon.foo', (600, 1.0))
363 self.cache.store('carbon.bar', (600, 2.0))
364
indentation is not a multiple of 4
354 self.send_request('cache-query-bulk', metrics=[])
355 self.assertIn('datapointsByMetric', self.response)
356
357 def test_cache_bulk_query_response_returns_empty_if_no_match(self):358 self.send_request('cache-query-bulk', metrics=[])
359 self.assertEquals({'datapointsByMetric': {}}, self.response)
360
indentation is not a multiple of 4
350 self.send_request('cache-query-bulk', metrics=[])
351 self.assertIsInstance(self.response, dict)
352
353 def test_cache_bulk_query_response_has_datapointsByMetric(self):354 self.send_request('cache-query-bulk', metrics=[])
355 self.assertIn('datapointsByMetric', self.response)
356
indentation is not a multiple of 4
346 self.send_request('cache-query', metric='carbon.foo')
347 self.assertEqual([(600, 1.0)], self.response['datapoints'])
348
349 def test_cache_bulk_query_returns_response_dict(self):350 self.send_request('cache-query-bulk', metrics=[])
351 self.assertIsInstance(self.response, dict)
352
indentation is not a multiple of 4
341 self.send_request('cache-query', metric='carbon.foo')
342 self.assertEquals({'datapoints': []}, self.response)
343
344 def test_cache_query_returns_cached_datapoints_if_matches(self):345 self.cache.store('carbon.foo', (600, 1.0))
346 self.send_request('cache-query', metric='carbon.foo')
347 self.assertEqual([(600, 1.0)], self.response['datapoints'])
indentation is not a multiple of 4
337 self.send_request('cache-query', metric='carbon.foo')
338 self.assertIn('datapoints', self.response)
339
340 def test_cache_query_returns_empty_if_no_match(self):341 self.send_request('cache-query', metric='carbon.foo')
342 self.assertEquals({'datapoints': []}, self.response)
343
indentation is not a multiple of 4
333 self.send_request('cache-query', metric='carbon.foo')
334 self.assertIsInstance(self.response, dict)
335
336 def test_cache_query_response_has_datapoints(self):337 self.send_request('cache-query', metric='carbon.foo')
338 self.assertIn('datapoints', self.response)
339
indentation is not a multiple of 4
329
330 self.assertIn('error', self.response)
331
332 def test_cache_query_returns_response_dict(self):333 self.send_request('cache-query', metric='carbon.foo')
334 self.assertIsInstance(self.response, dict)
335
indentation is not a multiple of 4
324 self.handler.connectionMade()
325 get_unpickler_mock.assert_called_once_with(insecure=False)
326
327 def test_invalid_request_type_returns_error(self):328 self.send_request('foo')
329
330 self.assertIn('error', self.response)
indentation is not a multiple of 4
316 self.handler.stringReceived(pickle.dumps(request))
317
318 @patch('carbon.protocols.get_unpickler')
319 def test_pickler_configured_on_connect(self, get_unpickler_mock):320 from twisted.internet.address import IPv4Address
321 address = IPv4Address('TCP', 'localhost', 7002)
322 self.handler.transport = Mock()
indentation is not a multiple of 4
315 request.update(kwargs)
316 self.handler.stringReceived(pickle.dumps(request))
317
318 @patch('carbon.protocols.get_unpickler')319 def test_pickler_configured_on_connect(self, get_unpickler_mock):
320 from twisted.internet.address import IPv4Address
321 address = IPv4Address('TCP', 'localhost', 7002)
indentation is not a multiple of 4
309 raw_response = arg
310 self.response = pickle.loads(raw_response)
311
312 def send_request(self, request_type, **kwargs):313 request = {}
314 request['type'] = request_type
315 request.update(kwargs)
indentation is not a multiple of 4
307 self.response = None
308 if arg:
309 raw_response = arg
310 self.response = pickle.loads(raw_response)311
312 def send_request(self, request_type, **kwargs):
313 request = {}
indentation is not a multiple of 4
306 def _save_response(self, arg):
307 self.response = None
308 if arg:
309 raw_response = arg310 self.response = pickle.loads(raw_response)
311
312 def send_request(self, request_type, **kwargs):
indentation is not a multiple of 4
303 self._metriccache_patch.stop()
304 del self.cache
305
306 def _save_response(self, arg):307 self.response = None
308 if arg:
309 raw_response = arg
indentation is not a multiple of 4
297 self._send_string_patch = patch.object(self.handler, 'sendString', self.send_string_mock)
298 self._send_string_patch.start()
299
300 def tearDown(self):301 self._settings_patch.stop()
302 self._send_string_patch.stop()
303 self._metriccache_patch.stop()
indentation is not a multiple of 4
285 self.cache = _MetricCache()
286
287 def _get_cache():
288 return self.cache289
290 self._metriccache_patch = patch('carbon.protocols.MetricCache', _get_cache)
291 self._metriccache_patch.start()
indentation is not a multiple of 4
270
271
272class TestCacheManagementHandler(TestCase):
273 def setUp(self):274 test_directory = os.path.dirname(os.path.realpath(__file__))
275 settings = {
276 'CONF_DIR': os.path.join(test_directory, 'data', 'conf-directory'),
Description
PEP8 recommends that Python code indentation be a multiple of four.