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

add changes #6

Merged
merged 6 commits into from
Feb 11, 2022
Merged

add changes #6

merged 6 commits into from
Feb 11, 2022

Conversation

CaptainOfHacks
Copy link
Collaborator

  • move e2e tests from unit tests
  • Create FakeRequest for HTTP API tests
  • Use dependecy injection for NoticeFetcher and TedDocumentSearch

- move e2e tests from unit tests
- Create FakeRequest for HTTP API tests
- Use dependecy injection for NoticeFetcher and TedDocumentSearch
@codecov
Copy link

codecov bot commented Feb 10, 2022

Codecov Report

Merging #6 (efd8ced) into main (35b7c65) will increase coverage by 0.35%.
The diff coverage is 91.30%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main       #6      +/-   ##
==========================================
+ Coverage   87.71%   88.06%   +0.35%     
==========================================
  Files          18       18              
  Lines         236      243       +7     
==========================================
+ Hits          207      214       +7     
  Misses         29       29              
Impacted Files Coverage Δ
ted_sws/notice_fetcher/services/notice_fetcher.py 94.59% <85.71%> (+0.30%) ⬆️
ted_sws/notice_fetcher/adapters/ted_api.py 93.18% <92.30%> (+0.32%) ⬆️
ted_sws/notice_fetcher/adapters/ted_api_abc.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 35b7c65...efd8ced. Read the comment docs.

Copy link
Collaborator

@costezki costezki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

documents_content += response_body["results"]
decoded_documents_content = []
for document_content in documents_content:
print(f"Document content: {document_content['content']}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's start thinking of logging from the very start.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -3,6 +3,12 @@
from typing import List


class RequestAPI(abc.ABC):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value of this abstract class is to define the call methods.
I would recommend defining those here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done



class NoticeFetcherABC(abc.ABC):
"""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we decide to have only functions in the service layer of the application, then the class NoticeFetcher class can be merged into DocumetnSearch class. This is to be discussed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We decide to keep adapter logic separate of notice fetcher service logic.


def test_notice_fetcher_by_identifier():
document_id = "067623-2022"
notice = NoticeFetcher(document_search=TedDocumentSearch(request_api=TedRequestAPI())).get_notice_by_id(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use a fixture here for TedDocumentSearch.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -0,0 +1,42 @@
import datetime
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks grteat!

from ted_sws.notice_fetcher.adapters.ted_api_abc import DocumentSearchABC, RequestAPI
from tests.unit.notice_fetcher.conftest import get_api_response

FAKE_RESPONSE = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be a fixture?



def test_notice_fetcher_by_identifier():
document_id = "067623-2022"
notice = NoticeFetcher().get_notice_by_id(document_id=document_id)
notice = NoticeFetcher(document_search=TedDocumentSearch(request_api=FakeRequestAPI())).get_notice_by_id(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TedDocumentSearch shall be coming from a fixture.

@@ -20,19 +23,21 @@ def test_notice_fetcher_by_identifier():
def test_notice_fetcher_by_search_query():
query = {"q": "ND=[67623-2022]"}

notices = NoticeFetcher().get_notices_by_query(query=query)
notices = NoticeFetcher(document_search=TedDocumentSearch(request_api=FakeRequestAPI())).get_notices_by_query(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

injected dependencies are from fixtures.

notices = NoticeFetcher().get_notices_by_date_range(start_date=datetime.date(2022, 2, 3),
end_date=datetime.date(2022, 2, 3))
xml_text = "<NOTICE_DATA>"
notices = NoticeFetcher(document_search=TedDocumentSearch(request_api=FakeRequestAPI())).get_notices_by_date_range(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem


assert isinstance(notices, list)
assert len(notices) == 95
assert len(notices) == 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well done

@CaptainOfHacks CaptainOfHacks merged commit 7c52c3a into main Feb 11, 2022
@CaptainOfHacks CaptainOfHacks deleted the feature/TED-80 branch February 11, 2022 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants