From 504841c81d874be8442c84475e954d47d523e67b Mon Sep 17 00:00:00 2001 From: CaptainOfHacks Date: Tue, 1 Mar 2022 21:28:53 +0200 Subject: [PATCH] change fake_ntoice_storage to real notice_storage --- tests/features/notice_fetcher/conftest.py | 16 +++++-- .../notice_fetcher/test_fetching_types.py | 46 ++++++++----------- .../notice_fetcher/test_notice_fetcher.py | 46 +++++++++---------- .../notice_fetcher/test_search_queries.py | 8 ++-- 4 files changed, 55 insertions(+), 61 deletions(-) diff --git a/tests/features/notice_fetcher/conftest.py b/tests/features/notice_fetcher/conftest.py index 158e28add..8296d2c99 100644 --- a/tests/features/notice_fetcher/conftest.py +++ b/tests/features/notice_fetcher/conftest.py @@ -1,12 +1,19 @@ import pytest +from pymongo import MongoClient +from ted_sws import config +from ted_sws.data_manager.adapters.notice_repository import NoticeRepository from ted_sws.notice_fetcher.adapters.ted_api import DEFAULT_TED_API_URL -from tests.fakes.fake_repository import FakeNoticeRepository +NOTICE_STORAGE_FEATURES_TEST_DB = "features_test_db_for_notice" + @pytest.fixture -def fake_notice_storage(): - return FakeNoticeRepository() +def notice_storage(): + url = config.MONGO_DB_AUTH_URL + mongodb_client = MongoClient(url) + mongodb_client.drop_database(NOTICE_STORAGE_FEATURES_TEST_DB) + return NoticeRepository(mongodb_client=mongodb_client, database_name=NOTICE_STORAGE_FEATURES_TEST_DB) @pytest.fixture @@ -18,6 +25,7 @@ def notice_identifier(): def notice_search_query(): return {"q": "ND=[067623-2022]"} + @pytest.fixture def notice_incorrect_search_query(): return {"q": "ND=067623-20224856"} @@ -26,5 +34,3 @@ def notice_incorrect_search_query(): @pytest.fixture def api_end_point(): return DEFAULT_TED_API_URL - - diff --git a/tests/features/notice_fetcher/test_fetching_types.py b/tests/features/notice_fetcher/test_fetching_types.py index 424faa363..79c7725cd 100644 --- a/tests/features/notice_fetcher/test_fetching_types.py +++ b/tests/features/notice_fetcher/test_fetching_types.py @@ -28,30 +28,26 @@ def step_impl(notice_identifier): return notice_identifier -@when("the call to the API is made", target_fixture="api_call") -def step_impl(identifier, api_url, fake_notice_storage): - NoticeFetcher(notice_repository=fake_notice_storage, +@when("the call to the API is made", target_fixture="notice_storage") +def step_impl(identifier, api_url, notice_storage): + NoticeFetcher(notice_repository=notice_storage, ted_api_adapter=TedAPIAdapter(request_api=TedRequestAPI(), ted_api_url=api_url)).fetch_notice_by_id( document_id=identifier) - return fake_notice_storage.get(reference=identifier) + return notice_storage -@then("a notice with that identifier and the notice metadata are available", target_fixture="fake_notice_storage") -def step_impl(api_call, fake_notice_storage): - # TODO remove target fixture and fake notice storage from this step when notice fetcher will have the - # storage facility added - notice = api_call +@then("a notice with that identifier and the notice metadata are available", target_fixture="notice_storage") +def step_impl(identifier, notice_storage): + notice = notice_storage.get(reference=identifier) assert isinstance(notice, Notice) assert notice.original_metadata assert notice.xml_manifestation - fake_notice_storage.add(notice) - return fake_notice_storage + return notice_storage @then("are stored") -def step_impl(fake_notice_storage, identifier): - # TODO replace fake notice storage with real one when it is available - assert fake_notice_storage.get(reference=identifier) +def step_impl(notice_storage, identifier): + assert notice_storage.get(reference=identifier) @given("search query") @@ -60,29 +56,25 @@ def step_impl(notice_search_query): @when("the call to the search API is made", target_fixture="api_call") -def step_impl(notice_search_query, api_end_point, fake_notice_storage): - NoticeFetcher(notice_repository=fake_notice_storage, - ted_api_adapter=TedAPIAdapter(request_api=TedRequestAPI(), ted_api_url=api_end_point)).fetch_notices_by_query( +def step_impl(notice_search_query, api_end_point, notice_storage): + NoticeFetcher(notice_repository=notice_storage, + ted_api_adapter=TedAPIAdapter(request_api=TedRequestAPI(), ted_api_url=api_end_point)).fetch_notices_by_query( query=notice_search_query) - return [fake_notice_storage.get(reference=reference) for reference in fake_notice_storage.list()] + return list(notice_storage.list()) @then("notices that match the search query result and their metadata are available", - target_fixture="fake_notice_storage") -def step_impl(api_call, fake_notice_storage, notice_identifier): - # TODO remove target fixture and fake notice storage from this step when notice fetcher will have the - # storage facility added + target_fixture="notice_storage") +def step_impl(api_call, notice_storage, notice_identifier): assert len(api_call) == 1 notice = api_call[0] assert isinstance(notice, Notice) assert notice.ted_id == notice_identifier assert notice.original_metadata assert notice.xml_manifestation - fake_notice_storage.add(notice) - return fake_notice_storage + return notice_storage @then("are stored") -def step_impl(fake_notice_storage, notice_identifier): - # TODO replace fake notice storage with real one when it is available - assert fake_notice_storage.get(reference=notice_identifier) +def step_impl(notice_storage, notice_identifier): + assert notice_storage.get(reference=notice_identifier) diff --git a/tests/features/notice_fetcher/test_notice_fetcher.py b/tests/features/notice_fetcher/test_notice_fetcher.py index e88559522..1658569c2 100644 --- a/tests/features/notice_fetcher/test_notice_fetcher.py +++ b/tests/features/notice_fetcher/test_notice_fetcher.py @@ -22,34 +22,31 @@ def step_impl(notice_search_query): return notice_search_query -@when("call to the API is made", target_fixture="api_call") -def step_impl(notice_search_query, api_end_point, fake_notice_storage): - NoticeFetcher(notice_repository=fake_notice_storage, - ted_api_adapter=TedAPIAdapter(request_api=TedRequestAPI(), ted_api_url=api_end_point)).fetch_notices_by_query( +@when("call to the API is made", target_fixture="notice_storage") +def step_impl(notice_search_query, api_end_point, notice_storage): + NoticeFetcher(notice_repository=notice_storage, + ted_api_adapter=TedAPIAdapter(request_api=TedRequestAPI(), ted_api_url=api_end_point)).fetch_notices_by_query( query=notice_search_query) - return [fake_notice_storage.get(reference=reference) for reference in fake_notice_storage.list()] + return notice_storage -@then("a notice and notice metadata is received from the API", target_fixture="fake_notice_storage") -def step_impl(api_call, fake_notice_storage): - # TODO remove target fixture and fake notice storage from this step when notice fetcher will have the - # storage facility added - assert isinstance(api_call, list) - assert len(api_call) > 0 - notice = api_call[0] +@then("a notice and notice metadata is received from the API", target_fixture="notice_storage") +def step_impl(notice_storage): + notices = list(notice_storage.list()) + assert isinstance(notices, list) + assert len(notices) > 0 + notice = notices[0] assert isinstance(notice, Notice) assert notice.xml_manifestation assert notice.original_metadata - fake_notice_storage.add(notice) - return fake_notice_storage + return notice_storage @then("the notice and notice metadata are stored") -def step_impl(fake_notice_storage, notice_identifier): - # TODO replace fake notice storage with real one when it is available - assert fake_notice_storage.get(reference=notice_identifier) - assert fake_notice_storage.get(reference=notice_identifier).original_metadata - assert fake_notice_storage.get(reference=notice_identifier).xml_manifestation +def step_impl(notice_storage, notice_identifier): + assert notice_storage.get(reference=notice_identifier) + assert notice_storage.get(reference=notice_identifier).original_metadata + assert notice_storage.get(reference=notice_identifier).xml_manifestation @scenario('test_notice_fetcher.feature', 'Fail to fetch a TED notice') @@ -63,18 +60,17 @@ def step_impl(notice_incorrect_search_query): @when("the call to the API is made", target_fixture="api_call_message") -def step_impl(notice_incorrect_search_query, api_end_point,fake_notice_storage): +def step_impl(notice_incorrect_search_query, api_end_point, notice_storage): with pytest.raises(Exception) as e: - NoticeFetcher(notice_repository=fake_notice_storage, - ted_api_adapter=TedAPIAdapter(request_api=TedRequestAPI(), ted_api_url=api_end_point)).fetch_notices_by_query( + NoticeFetcher(notice_repository=notice_storage, + ted_api_adapter=TedAPIAdapter(request_api=TedRequestAPI(), ted_api_url=api_end_point)).fetch_notices_by_query( query=notice_incorrect_search_query) return e @when("no notice or metadata is returned") -def step_impl(fake_notice_storage, notice_identifier): - # TODO replace fake notice storage with real one when is available - assert fake_notice_storage.get(notice_identifier) is None +def step_impl(notice_storage, notice_identifier): + assert notice_storage.get(notice_identifier) is None @then("an error message is received indicating the problem") diff --git a/tests/features/notice_fetcher/test_search_queries.py b/tests/features/notice_fetcher/test_search_queries.py index 96b9a695a..4c3899ccd 100644 --- a/tests/features/notice_fetcher/test_search_queries.py +++ b/tests/features/notice_fetcher/test_search_queries.py @@ -24,12 +24,12 @@ def step_impl(start, end): @when("the call to the API is executed", target_fixture="api_call") -def step_impl(dates, fake_notice_storage): +def step_impl(dates, notice_storage): start_date, end_date = dates - NoticeFetcher(notice_repository=fake_notice_storage, - ted_api_adapter=TedAPIAdapter(request_api=TedRequestAPI())).fetch_notices_by_date_range( + NoticeFetcher(notice_repository=notice_storage, + ted_api_adapter=TedAPIAdapter(request_api=TedRequestAPI())).fetch_notices_by_date_range( start_date=start_date, end_date=end_date) - return [fake_notice_storage.get(reference=reference) for reference in fake_notice_storage.list()] + return list(notice_storage.list()) @then("search result set is returned", target_fixture="search_result")