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

Feature/ted 84 #15

Merged
merged 13 commits into from
Mar 1, 2022
Merged

Feature/ted 84 #15

merged 13 commits into from
Mar 1, 2022

Conversation

CaptainOfHacks
Copy link
Collaborator

No description provided.

@codecov
Copy link

codecov bot commented Feb 25, 2022

Codecov Report

Merging #15 (b3fecf4) into main (b0e42b8) will increase coverage by 0.58%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #15      +/-   ##
==========================================
+ Coverage   95.21%   95.80%   +0.58%     
==========================================
  Files          19       20       +1     
  Lines         355      381      +26     
==========================================
+ Hits          338      365      +27     
+ Misses         17       16       -1     
Impacted Files Coverage Δ
ted_sws/data_manager/__init__.py 100.00% <ø> (ø)
ted_sws/notice_fetcher/services/notice_fetcher.py 100.00% <ø> (ø)
ted_sws/data_manager/adapters/notice_repository.py 100.00% <100.00%> (ø)
ted_sws/domain/adapters/repository_abc.py 100.00% <100.00%> (ø)
ted_sws/domain/model/notice.py 97.81% <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 62958f3...b3fecf4. Read the comment docs.

requirements.txt Outdated
python-dotenv~=0.19.2
pymongo~=4.0.1
mongomock==4.0.0
Copy link
Collaborator

Choose a reason for hiding this comment

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

mongomock should go into the requirements -dev.txt


def __init__(self,mongodb_client: MongoClient, database_name: str = None):
mongodb_client = mongodb_client
notice_db = mongodb_client[database_name if database_name else self._database_name]
Copy link
Collaborator

Choose a reason for hiding this comment

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

We need to check how safe it is to assume that we can refer to a DB even in cases it does not exist. This shall be tested.

mongodb_client['db_name'] might not be a safe operation.

:return:
"""
notice_dict = notice.dict()
notice_dict["_id"] = notice_dict["ted_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 propose to move this logic into the model directly.
We could "export" (.to_dict) an `_id' key that is equal to the ted_id.

:param reference:
:return: Notice
"""
result_dict = self.collection.find_one({"ted_id": reference})
Copy link
Collaborator

Choose a reason for hiding this comment

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

we would have to standardise if we search based on _id or ted_id

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

_id == ted_id

This method allows all records to be retrieved from the repository.
:return: list of notices
"""
return [Notice(**result_dict) for result_dict in self.collection.find()]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Notice(**result_dict) is partially safe at the moment.
What happens to the _id for example? If we do not care, then it should be fairly okay. But still needs to be tested in e2e tests.

Also, what happens in the case of very very large databases? Shall we provide it as a cursor or a generator instead of a memory-hungry list? I would recommend the generator option. But need to check what is the general practice.

@@ -3,7 +3,7 @@
from ted_sws.notice_fetcher.adapters.ted_api import TedAPIAdapter
from tests.fakes.fake_repository import FakeNoticeRepository
from tests.fakes.fake_ted_api import FakeRequestAPI

from pymongo import MongoClient
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 recommend removing e2e requirements from the tests/conftest.py and moving it closer to the tests where it is used i.e. e2e/conftest.py tests for example.


@pytest.fixture
def mongodb_client():
uri = config.MONGO_DB_AUTH_URL
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why ...AUTH_URL ?

shouldn't we receive from the env the

  • (a) database URL in one variable,
  • (b) the auth parameters in another one or two, depending on the method



@pytest.fixture
@mongomock.patch(servers=(('server.example.com', 27017),))
Copy link
Collaborator

Choose a reason for hiding this comment

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

We are gonna have to decide whether we use Fakes or mocks.
Generally, we do not need both unless I am ignorant or missing something.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

for pymongo we need mock approach

TEST_DB_NAME = 'test_db'


def test_notice_repository_create(mongodb_client):
Copy link
Collaborator

Choose a reason for hiding this comment

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

This test is identical to the other one in e2e.

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.

Looking good!

:return: list of notices
"""
for result_dict in self.collection.find():
yield Notice(**result_dict)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Clever!

I only hope that self.collection.find() is also a generator.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes

@costezki
Copy link
Collaborator

costezki commented Mar 1, 2022

BTW the tests are failing :)

@CaptainOfHacks CaptainOfHacks merged commit 80a30cc into main Mar 1, 2022
@CaptainOfHacks CaptainOfHacks deleted the feature/TED-84 branch March 1, 2022 18:43
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