def test_broken_catalog(self, mock_reporter): mockV3Api = MockAPI(os.path.join(self.resources_dir, 'v3_cdn'), 'https://cdn.door43.org/') mockV3Api.add_host(os.path.join(self.resources_dir, 'broken_api'), 'https://api.door43.org/') mockS3 = MockS3Handler('ts_bucket') mockDb = MockDynamodbHandler() mockDb._load_db( os.path.join(TestTsV2Catalog.resources_dir, 'ready_new_db.json')) mockLog = MockLogger() mock_get_url = lambda url, catch_exception: mockV3Api.get_url( url, catch_exception) mock_download = lambda url, dest: mockV3Api.download_file(url, dest) event = self.make_event() converter = TsV2CatalogHandler(event=event, context=None, logger=mockLog, s3_handler=mockS3, dynamodb_handler=mockDb, url_handler=mock_get_url, download_handler=mock_download, url_exists_handler=lambda url: False) result = converter.run() self.assertFalse(result) self.assertIn( 'Failed to load the catalog json: No JSON object could be decoded', mockLog._messages)
def test_complete_status(self, mock_reporter): mockV3Api = MockAPI(self.resources_dir, 'https://cdn.door43.org/') mockS3 = MockS3Handler('ts_bucket') mockDb = MockDynamodbHandler() mockDb._load_db( os.path.join(TestTsV2Catalog.resources_dir, 'complete_db.json')) mockLog = MockLogger() mock_get_url = lambda url, catch_exception: mockV3Api.get_url( url, catch_exception) mock_download = lambda url, dest: mockV3Api.download_file(url, dest) event = self.make_event() converter = TsV2CatalogHandler(event=event, context=None, logger=mockLog, s3_handler=mockS3, dynamodb_handler=mockDb, url_handler=mock_get_url, download_handler=mock_download, url_exists_handler=lambda url: True) result = converter.run() self.assertTrue(result) self.assertEqual(0, len(mockS3._recent_uploads)) self.assertIn('Catalog already generated', mockLog._messages)