class WhenTestingWorkerConfigurationObject(unittest.TestCase): def setUp(self): self.worker_config = WorkerConfiguration( "correlation", "meniscus.personas.worker.correlation", "94d6176b-9188-4409-8648-7374d0326e6b", "8cc3b103-9b23-4e1c-afb1-8c5973621b55", "http://172.22.15.25:8080/v1") def test_worker_configuration(self): self.assertEqual(self.worker_config.personality, 'correlation') self.assertEqual(self.worker_config.personality_module, 'meniscus.personas.worker.correlation') self.assertEqual(self.worker_config.worker_token, '94d6176b-9188-4409-8648-7374d0326e6b') self.assertEqual(self.worker_config.worker_id, '8cc3b103-9b23-4e1c-afb1-8c5973621b55') self.assertEqual(self.worker_config.coordinator_uri, 'http://172.22.15.25:8080/v1') def test_worker_configuration_format(self): worker_dict = self.worker_config.format() self.assertEqual(worker_dict['personality'], 'correlation') self.assertEqual(worker_dict['personality_module'], 'meniscus.personas.worker.correlation') self.assertEqual(worker_dict['worker_token'], '94d6176b-9188-4409-8648-7374d0326e6b') self.assertEqual(worker_dict['worker_id'], '8cc3b103-9b23-4e1c-afb1-8c5973621b55') self.assertEqual(worker_dict['coordinator_uri'], 'http://172.22.15.25:8080/v1')
class WhenTestingWorkerConfigurationObject(unittest.TestCase): def setUp(self): self.worker_config = WorkerConfiguration( "worker", "worker01", "http://172.22.15.25:8080/v1") def test_worker_configuration(self): self.assertEqual(self.worker_config.personality, 'worker') self.assertEqual(self.worker_config.hostname, 'worker01') self.assertEqual(self.worker_config.coordinator_uri, 'http://172.22.15.25:8080/v1') def test_worker_configuration_format(self): worker_dict = self.worker_config.format() self.assertEqual(worker_dict['personality'], 'worker') self.assertEqual(worker_dict['hostname'], 'worker01') self.assertEqual(worker_dict['coordinator_uri'], 'http://172.22.15.25:8080/v1')
class WhenTestingConfigCache(unittest.TestCase): def setUp(self): self.cache_clear = MagicMock() self.cache_true = MagicMock(return_value=True) self.cache_false = MagicMock(return_value=False) self.cache_update = MagicMock() self.cache_set = MagicMock() self.cache_del = MagicMock() self.config = WorkerConfiguration( personality='worker', hostname='worker01', coordinator_uri='http://192.168.1.2/v1') self.config_json = jsonutils.dumps(self.config.format()) self.cache_get_config = MagicMock(return_value=self.config_json) def test_clear_calls_cache_clear(self): with patch.object(NativeProxy, 'cache_clear', self.cache_clear): config_cache = ConfigCache() config_cache.clear() self.cache_clear.assert_called_once_with(CACHE_CONFIG) def test_set_config_calls_cache_update(self): with patch.object( NativeProxy, 'cache_exists', self.cache_true ), patch.object(NativeProxy, 'cache_update', self.cache_update): config_cache = ConfigCache() config_cache.set_config(self.config) self.cache_update.assert_called_once_with( 'worker_configuration', jsonutils.dumps(self.config.format()), CONFIG_EXPIRES, CACHE_CONFIG) def test_set_config_calls_cache_set(self): with patch.object( NativeProxy, 'cache_exists', self.cache_false ), patch.object(NativeProxy, 'cache_set', self.cache_set): config_cache = ConfigCache() config_cache.set_config(self.config) self.cache_set.assert_called_once_with( 'worker_configuration', jsonutils.dumps(self.config.format()), CONFIG_EXPIRES, CACHE_CONFIG) def test_get_config_calls_returns_config(self): with patch.object( NativeProxy, 'cache_exists', self.cache_true ), patch.object(NativeProxy, 'cache_get', self.cache_get_config): config_cache = ConfigCache() config = config_cache.get_config() self.cache_get_config.assert_called_once_with( 'worker_configuration', CACHE_CONFIG) self.assertIsInstance(config, WorkerConfiguration) def test_get_config_calls_returns_none(self): with patch.object( NativeProxy, 'cache_exists', self.cache_false): config_cache = ConfigCache() config = config_cache.get_config() self.assertIs(config, None) def test_delete_config_calls_cache_del(self): with patch.object( NativeProxy, 'cache_exists', self.cache_true ), patch.object(NativeProxy, 'cache_del', self.cache_del): config_cache = ConfigCache() config_cache.delete_config() self.cache_del.assert_called_once_with( 'worker_configuration', CACHE_CONFIG) def test_delete_config_does_not_call_cache_del(self): with patch.object( NativeProxy, 'cache_exists', self.cache_false ), patch.object(NativeProxy, 'cache_del', self.cache_del): config_cache = ConfigCache() config_cache.delete_config() with self.assertRaises(AssertionError): self.cache_del.assert_called_once_with( 'worker_configuration', CACHE_CONFIG)
class WhenTestingConfigCache(unittest.TestCase): def setUp(self): self.cache_clear = MagicMock() self.cache_true = MagicMock(return_value=True) self.cache_false = MagicMock(return_value=False) self.cache_update = MagicMock() self.cache_set = MagicMock() self.cache_del = MagicMock() self.config = WorkerConfiguration( personality='worker', hostname='worker01', coordinator_uri='http://192.168.1.2/v1') self.config_json = jsonutils.dumps(self.config.format()) self.cache_get_config = MagicMock(return_value=self.config_json) def test_clear_calls_cache_clear(self): with patch.object(NativeProxy, 'cache_clear', self.cache_clear): config_cache = ConfigCache() config_cache.clear() self.cache_clear.assert_called_once_with(CACHE_CONFIG) def test_set_config_calls_cache_update(self): with patch.object(NativeProxy, 'cache_exists', self.cache_true), patch.object( NativeProxy, 'cache_update', self.cache_update): config_cache = ConfigCache() config_cache.set_config(self.config) self.cache_update.assert_called_once_with( 'worker_configuration', jsonutils.dumps(self.config.format()), CONFIG_EXPIRES, CACHE_CONFIG) def test_set_config_calls_cache_set(self): with patch.object(NativeProxy, 'cache_exists', self.cache_false), patch.object( NativeProxy, 'cache_set', self.cache_set): config_cache = ConfigCache() config_cache.set_config(self.config) self.cache_set.assert_called_once_with( 'worker_configuration', jsonutils.dumps(self.config.format()), CONFIG_EXPIRES, CACHE_CONFIG) def test_get_config_calls_returns_config(self): with patch.object(NativeProxy, 'cache_exists', self.cache_true), patch.object( NativeProxy, 'cache_get', self.cache_get_config): config_cache = ConfigCache() config = config_cache.get_config() self.cache_get_config.assert_called_once_with('worker_configuration', CACHE_CONFIG) self.assertIsInstance(config, WorkerConfiguration) def test_get_config_calls_returns_none(self): with patch.object(NativeProxy, 'cache_exists', self.cache_false): config_cache = ConfigCache() config = config_cache.get_config() self.assertIs(config, None) def test_delete_config_calls_cache_del(self): with patch.object(NativeProxy, 'cache_exists', self.cache_true), patch.object( NativeProxy, 'cache_del', self.cache_del): config_cache = ConfigCache() config_cache.delete_config() self.cache_del.assert_called_once_with('worker_configuration', CACHE_CONFIG) def test_delete_config_does_not_call_cache_del(self): with patch.object(NativeProxy, 'cache_exists', self.cache_false), patch.object( NativeProxy, 'cache_del', self.cache_del): config_cache = ConfigCache() config_cache.delete_config() with self.assertRaises(AssertionError): self.cache_del.assert_called_once_with('worker_configuration', CACHE_CONFIG)
class WhenTestingConfigCache(unittest.TestCase): def setUp(self): self.cache_clear = MagicMock() self.cache_true = MagicMock(return_value=True) self.cache_false = MagicMock(return_value=False) self.cache_update = MagicMock() self.cache_set = MagicMock() self.cache_del = MagicMock() self.config = WorkerConfiguration( personality='correlation', personality_module='meniscus.personas.worker.correlation.app', worker_id='fgc7104e-8d93-47dc-a49a-8fb0d39e5192', worker_token='bbd6307f-8d93-47dc-a49a-8fb0d39e5192', coordinator_uri='http://192.168.1.2/v1') self.config_json = jsonutils.dumps(self.config.format()) self.cache_get_config = MagicMock(return_value=self.config_json) self.routes = [ { "service_domain": "correlation|normalization|storage", "targets": [ { "worker_id": "488eb3fc-34dd-48ad-a1bb-99ee2a43bf1d", "ip_address_v4": "192.168.100.101", "ip_address_v6": "::1", "status": "online|draining" }, { "worker_id": "e0ac0dc3-694e-4522-94f0-fb25a4dbb8a1", "ip_address_v4": "192.168.100.102", "ip_address_v6": "::1", "status": "online|draining" }, { "worker_id": "64d7a5ab-55b6-4ff7-b362-0d67544bb6f8", "ip_address_v4": "192.168.100.103", "ip_address_v6": "::1", "status": "online|draining" } ] } ] self.routes_json = jsonutils.dumps(self.routes) self.cache_get_routes = MagicMock(return_value=self.routes_json) def test_clear_calls_cache_clear(self): with patch.object(NativeProxy, 'cache_clear', self.cache_clear): config_cache = ConfigCache() config_cache.clear() self.cache_clear.assert_called_once_with(CACHE_CONFIG) def test_set_config_calls_cache_update(self): with patch.object( NativeProxy, 'cache_exists', self.cache_true ), patch.object(NativeProxy, 'cache_update', self.cache_update): config_cache = ConfigCache() config_cache.set_config(self.config) self.cache_update.assert_called_once_with( 'worker_configuration', jsonutils.dumps(self.config.format()), CONFIG_EXPIRES, CACHE_CONFIG) def test_set_config_calls_cache_set(self): with patch.object( NativeProxy, 'cache_exists', self.cache_false ), patch.object(NativeProxy, 'cache_set', self.cache_set): config_cache = ConfigCache() config_cache.set_config(self.config) self.cache_set.assert_called_once_with( 'worker_configuration', jsonutils.dumps(self.config.format()), CONFIG_EXPIRES, CACHE_CONFIG) def test_get_config_calls_returns_config(self): with patch.object( NativeProxy, 'cache_exists', self.cache_true ), patch.object(NativeProxy, 'cache_get', self.cache_get_config): config_cache = ConfigCache() config = config_cache.get_config() self.cache_get_config.assert_called_once_with( 'worker_configuration', CACHE_CONFIG) self.assertIsInstance(config, WorkerConfiguration) def test_get_config_calls_returns_none(self): with patch.object( NativeProxy, 'cache_exists', self.cache_false): config_cache = ConfigCache() config = config_cache.get_config() self.assertIs(config, None) def test_delete_config_calls_cache_del(self): with patch.object( NativeProxy, 'cache_exists', self.cache_true ), patch.object(NativeProxy, 'cache_del', self.cache_del): config_cache = ConfigCache() config_cache.delete_config() self.cache_del.assert_called_once_with( 'worker_configuration', CACHE_CONFIG) def test_delete_config_does_not_call_cache_del(self): with patch.object( NativeProxy, 'cache_exists', self.cache_false ), patch.object(NativeProxy, 'cache_del', self.cache_del): config_cache = ConfigCache() config_cache.delete_config() with self.assertRaises(AssertionError): self.cache_del.assert_called_once_with( 'worker_configuration', CACHE_CONFIG)
class WhenTestingConfigCache(unittest.TestCase): def setUp(self): self.cache_clear = MagicMock() self.cache_true = MagicMock(return_value=True) self.cache_false = MagicMock(return_value=False) self.cache_update = MagicMock() self.cache_set = MagicMock() self.cache_del = MagicMock() self.config = WorkerConfiguration( personality='correlation', personality_module='meniscus.personas.worker.correlation.app', worker_id='fgc7104e-8d93-47dc-a49a-8fb0d39e5192', worker_token='bbd6307f-8d93-47dc-a49a-8fb0d39e5192', coordinator_uri='http://192.168.1.2/v1') self.config_json = jsonutils.dumps(self.config.format()) self.cache_get_config = MagicMock(return_value=self.config_json) self.routes = [{ "service_domain": "correlation|normalization|storage", "targets": [{ "worker_id": "488eb3fc-34dd-48ad-a1bb-99ee2a43bf1d", "ip_address_v4": "192.168.100.101", "ip_address_v6": "::1", "status": "online|draining" }, { "worker_id": "e0ac0dc3-694e-4522-94f0-fb25a4dbb8a1", "ip_address_v4": "192.168.100.102", "ip_address_v6": "::1", "status": "online|draining" }, { "worker_id": "64d7a5ab-55b6-4ff7-b362-0d67544bb6f8", "ip_address_v4": "192.168.100.103", "ip_address_v6": "::1", "status": "online|draining" }] }] self.routes_json = jsonutils.dumps(self.routes) self.cache_get_routes = MagicMock(return_value=self.routes_json) def test_clear_calls_cache_clear(self): with patch.object(NativeProxy, 'cache_clear', self.cache_clear): config_cache = ConfigCache() config_cache.clear() self.cache_clear.assert_called_once_with(CACHE_CONFIG) def test_set_config_calls_cache_update(self): with patch.object(NativeProxy, 'cache_exists', self.cache_true), patch.object( NativeProxy, 'cache_update', self.cache_update): config_cache = ConfigCache() config_cache.set_config(self.config) self.cache_update.assert_called_once_with( 'worker_configuration', jsonutils.dumps(self.config.format()), CONFIG_EXPIRES, CACHE_CONFIG) def test_set_config_calls_cache_set(self): with patch.object(NativeProxy, 'cache_exists', self.cache_false), patch.object( NativeProxy, 'cache_set', self.cache_set): config_cache = ConfigCache() config_cache.set_config(self.config) self.cache_set.assert_called_once_with( 'worker_configuration', jsonutils.dumps(self.config.format()), CONFIG_EXPIRES, CACHE_CONFIG) def test_get_config_calls_returns_config(self): with patch.object(NativeProxy, 'cache_exists', self.cache_true), patch.object( NativeProxy, 'cache_get', self.cache_get_config): config_cache = ConfigCache() config = config_cache.get_config() self.cache_get_config.assert_called_once_with('worker_configuration', CACHE_CONFIG) self.assertIsInstance(config, WorkerConfiguration) def test_get_config_calls_returns_none(self): with patch.object(NativeProxy, 'cache_exists', self.cache_false): config_cache = ConfigCache() config = config_cache.get_config() self.assertIs(config, None) def test_delete_config_calls_cache_del(self): with patch.object(NativeProxy, 'cache_exists', self.cache_true), patch.object( NativeProxy, 'cache_del', self.cache_del): config_cache = ConfigCache() config_cache.delete_config() self.cache_del.assert_called_once_with('worker_configuration', CACHE_CONFIG) def test_delete_config_does_not_call_cache_del(self): with patch.object(NativeProxy, 'cache_exists', self.cache_false), patch.object( NativeProxy, 'cache_del', self.cache_del): config_cache = ConfigCache() config_cache.delete_config() with self.assertRaises(AssertionError): self.cache_del.assert_called_once_with('worker_configuration', CACHE_CONFIG)