From 70be60322ed6b9a7cf5d92ebd6baefa9be830fe3 Mon Sep 17 00:00:00 2001 From: Dumitru Date: Fri, 6 Oct 2023 15:15:49 +0300 Subject: [PATCH] resolve bug --- .../services/daily_notices_metadata_services.py | 7 ++++--- tests/e2e/conftest.py | 5 +++++ .../test_notices_metadata_services.py | 14 +++++++++++--- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/ted_sws/supra_notice_manager/services/daily_notices_metadata_services.py b/ted_sws/supra_notice_manager/services/daily_notices_metadata_services.py index 04474568..dda6327e 100644 --- a/ted_sws/supra_notice_manager/services/daily_notices_metadata_services.py +++ b/ted_sws/supra_notice_manager/services/daily_notices_metadata_services.py @@ -89,11 +89,12 @@ def update_daily_notices_metadata_from_ted(start_date: date = None, # Getting from TED API dates that are not in the repository from date range for day in dates_not_in_repository: - ted_api_query = DAILY_NOTICES_METADATA_TED_API_QUERY + ted_api_query = DAILY_NOTICES_METADATA_TED_API_QUERY.copy() ted_api_query[TED_API_QUERY_FIELD] = ted_api_query[TED_API_QUERY_FIELD].format( aggregation_date=day.strftime(TED_API_WILDCARD_DATE_FORMAT)) - notice_ids = ted_api.get_by_query(ted_api_query, - result_fields=DAILY_NOTICES_METADATA_TED_API_QUERY_RESULT_FIELDS) + notice_ids = ted_api.get_by_query(ted_api_query, result_fields=DAILY_NOTICES_METADATA_TED_API_QUERY_RESULT_FIELDS) + if not notice_ids: + continue daily_notices_metadata = DailyNoticesMetadata(aggregation_date=day) daily_notices_metadata.ted_api_notice_ids = [notice[TED_API_NOTICE_ID_FIELD] for notice in notice_ids] daily_notices_metadata_repo.add(daily_notices_metadata) diff --git a/tests/e2e/conftest.py b/tests/e2e/conftest.py index a0fee080..4499a05b 100644 --- a/tests/e2e/conftest.py +++ b/tests/e2e/conftest.py @@ -85,3 +85,8 @@ def fake_notice_repository(fake_mongodb_client): @pytest.fixture def example_date(): return date(2021, 1, 7) + + +@pytest.fixture +def example_date_without_notices(): + return date(2021, 1, 9) \ No newline at end of file diff --git a/tests/e2e/supra_notice_manager/test_notices_metadata_services.py b/tests/e2e/supra_notice_manager/test_notices_metadata_services.py index f1f92064..7874238f 100644 --- a/tests/e2e/supra_notice_manager/test_notices_metadata_services.py +++ b/tests/e2e/supra_notice_manager/test_notices_metadata_services.py @@ -1,12 +1,13 @@ from ted_sws import config from ted_sws.core.model.supra_notice import DailyNoticesMetadata from ted_sws.data_manager.adapters.daily_notices_metadata_repository import DailyNoticesMetadataRepository -from ted_sws.supra_notice_manager.services.daily_notices_metadata_services import update_daily_notices_metadata_from_ted, \ - update_daily_notices_metadata_with_fetched_data from ted_sws.notice_fetcher.adapters.ted_api import TedAPIAdapter, TedRequestAPI +from ted_sws.supra_notice_manager.services.daily_notices_metadata_services import \ + update_daily_notices_metadata_from_ted, \ + update_daily_notices_metadata_with_fetched_data -def test_update_daily_notices_metadata_from_ted(fake_mongodb_client, example_date): +def test_update_daily_notices_metadata_from_ted(fake_mongodb_client, example_date, example_date_without_notices): """ Test update_daily_notices_metadata_from_ted function """ @@ -14,6 +15,13 @@ def test_update_daily_notices_metadata_from_ted(fake_mongodb_client, example_dat ted_api = TedAPIAdapter(TedRequestAPI(), config.TED_API_URL) daily_notices_metadata_repo = DailyNoticesMetadataRepository(fake_mongodb_client) + update_daily_notices_metadata_from_ted(start_date=example_date_without_notices, + end_date=example_date_without_notices, + ted_api=ted_api, + daily_notices_metadata_repo=daily_notices_metadata_repo) + + assert len(list(daily_notices_metadata_repo.list())) == 0 + update_daily_notices_metadata_from_ted(start_date=example_date, end_date=example_date, ted_api=ted_api,