Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change fake_notice_storage to real notice_storage #17

Merged
merged 1 commit into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions tests/features/notice_fetcher/conftest.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"}
Expand All @@ -26,5 +34,3 @@ def notice_incorrect_search_query():
@pytest.fixture
def api_end_point():
return DEFAULT_TED_API_URL


46 changes: 19 additions & 27 deletions tests/features/notice_fetcher/test_fetching_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
46 changes: 21 additions & 25 deletions tests/features/notice_fetcher/test_notice_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions tests/features/notice_fetcher/test_search_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down