def test_init(self): self.config.remove_option('main', 'resources_api_server') with self.assertRaises(ConfigError) as e: ArchivariusBridge(self.config) self.config.set('main', 'resources_api_server', 'asfd') self.assertEqual( e.exception.message, 'In config dictionary empty or missing' ' \'resources_api_server\'') with self.assertRaises(ConfigError) as e: ArchivariusBridge(self.config) self.assertEqual(e.exception.message, 'Invalid \'resources_api_server\' url.') self.config.set('main', 'resources_api_server', 'http://localhost') self.config.set('main', 'retry_resource_items_queue_size', '-1') self.config.set('main', 'resource_items_queue_size', '-1') archivarius = ArchivariusBridge(self.config) self.assertEqual(archivarius.resource_items_queue.maxsize, None) self.assertEqual(archivarius.retry_resource_items_queue.maxsize, None) del archivarius self.config.set('main', 'retry_resource_items_queue_size', '1') self.config.set('main', 'resource_items_queue_size', '1') archivarius = ArchivariusBridge(self.config) self.assertEqual(archivarius.resource_items_queue.maxsize, 1) self.assertEqual(archivarius.retry_resource_items_queue.maxsize, 1)
def test_gevent_watcher(self, mock_APIClient, mock_riw_spawn, mock_spawn): bridge = ArchivariusBridge(self.config) self.assertEqual(bridge.workers_pool.free_count(), bridge.workers_max) self.assertEqual(bridge.retry_workers_pool.free_count(), bridge.retry_workers_max) bridge.resource_items_queue.put('item') bridge.retry_resource_items_queue.put('item') bridge.gevent_watcher() self.assertEqual(bridge.workers_pool.free_count(), bridge.workers_max - bridge.workers_min) self.assertEqual(bridge.retry_workers_pool.free_count(), bridge.retry_workers_max - bridge.retry_workers_min) del bridge
def test_init_storages(self): self.config.set('main', 'secret_storage', 's3') self.config.set('main', 's3.aws_access_key_id', 'AKIATEST') self.config.set('main', 's3.aws_secret_access_key', 'SECRET') self.config.set('main', 's3.bucket', 'BUCKET') archivarius = ArchivariusBridge(self.config) self.assertTrue(isinstance(archivarius.secret_archive, S3Storage)) del archivarius self.config.set('main', 'secret_storage', 'couchdb') archivarius = ArchivariusBridge(self.config) self.assertTrue(isinstance(archivarius.secret_archive, Database)) del archivarius
def test_fill_resource_items_queue(self, mock_ifilter): mock_ifilter.return_value = [ munchify({'id': uuid.uuid4().hex}), munchify({'id': uuid.uuid4().hex}) ] bridge = ArchivariusBridge(self.config) bridge.resources['tenders'] = { 'view_path': 'path', 'filter': MagicMock() } self.assertEqual(bridge.resource_items_queue.qsize(), 0) self.assertEqual(bridge.log_dict['add_to_resource_items_queue'], 0) bridge.fill_resource_items_queue('tenders') self.assertEqual(bridge.resource_items_queue.qsize(), 2) self.assertEqual(bridge.log_dict['add_to_resource_items_queue'], 2)
def test_init(self, mock_iter_entry_points): mock_iter_entry_points.return_value = [] self.config.remove_option('main', 'resources_api_server') with self.assertRaises(ConfigError) as e: ArchivariusBridge(self.config) self.config.set('main', 'resources_api_server', 'asfd') self.assertEqual( e.exception.message, 'In config dictionary empty or missing' ' \'resources_api_server\'') with self.assertRaises(ConfigError) as e: ArchivariusBridge(self.config) self.assertEqual(e.exception.message, 'Invalid \'resources_api_server\' url.') self.config.set('main', 'resources_api_server', 'http://localhost') self.config.set('main', 'retry_resource_items_queue_size', '-1') self.config.set('main', 'resource_items_queue_size', '-1') archivarius = ArchivariusBridge(self.config) self.assertEqual(archivarius.resource_items_queue.maxsize, None) self.assertEqual(archivarius.retry_resource_items_queue.maxsize, None) del archivarius self.config.set('main', 'retry_resource_items_queue_size', '1') self.config.set('main', 'resource_items_queue_size', '1') archivarius = ArchivariusBridge(self.config) self.assertEqual(archivarius.resource_items_queue.maxsize, 1) self.assertEqual(archivarius.retry_resource_items_queue.maxsize, 1) del archivarius tender_entrypoint = MagicMock() tender_entrypoint.name = 'tenders' tender_entrypoint.load.return_value = lambda x: x plan_entrypoint = MagicMock() plan_entrypoint.name = 'plans' plan_entrypoint.load.return_value = lambda x: x contract_entrypoint = MagicMock() contract_entrypoint.name = 'contracts' contract_entrypoint.load.return_value = lambda x: x mock_iter_entry_points.return_value = [ tender_entrypoint, plan_entrypoint, contract_entrypoint ] archivarius = ArchivariusBridge(self.config) self.assertNotEqual(archivarius.db.get('_design/contracts'), None) self.assertNotEqual(archivarius.db.get('_design/plans'), None) self.assertNotEqual(archivarius.db.get('_design/tenders'), None) del archivarius
def test_create_api_client(self, mock_APIClient): mock_APIClient.side_effect = [ RequestFailed(), munchify({'session': { 'headers': { 'User-Agent': 'test.agent' } }}) ] archivarius = ArchivariusBridge(self.config) self.assertEqual(archivarius.api_clients_queue.qsize(), 0) self.assertEqual(archivarius.log_dict['exceptions_count'], 0) archivarius.create_api_client() self.assertEqual(archivarius.log_dict['exceptions_count'], 1) self.assertEqual(archivarius.api_clients_queue.qsize(), 1) del archivarius
def test_fill_api_clients_queue(self, mock_APIClient): bridge = ArchivariusBridge(self.config) self.assertEqual(bridge.api_clients_queue.qsize(), 0) bridge.fill_api_clients_queue() self.assertEqual(bridge.api_clients_queue.qsize(), bridge.workers_min)