Skip to content

Commit

Permalink
add test for fetch_preview_items
Browse files Browse the repository at this point in the history
  • Loading branch information
cutoffthetop committed Dec 9, 2024
1 parent c15a4a7 commit 37baf24
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
33 changes: 32 additions & 1 deletion tests/backend_api/test_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
from requests.exceptions import HTTPError

from mex.common.backend_api.connector import BackendApiConnector
from mex.common.backend_api.models import ExtractedItemsRequest
from mex.common.backend_api.models import ExtractedItemsRequest, PreviewItemsResponse
from mex.common.models import (
ExtractedPerson,
MergedPerson,
PersonRuleSetRequest,
PersonRuleSetResponse,
PreviewPerson,
)
from mex.common.testing import Joker

Expand Down Expand Up @@ -197,6 +198,36 @@ def test_preview_merged_item_mocked(
)


def test_fetch_preview_items_mocked(
mocked_backend: MagicMock,
preview_person: PreviewPerson,
) -> None:
preview_response = PreviewItemsResponse(items=[preview_person], total=92)
mocked_return = preview_response.model_dump()
mocked_backend.return_value.json.return_value = mocked_return

connector = BackendApiConnector.get()
response = connector.fetch_preview_items("foobar", None, 1, 0)

assert response == preview_response

assert mocked_backend.call_args == call(
"GET",
"http://localhost:8080/v0/preview-item",
{
"q": "foobar",
"entityType": None,
"skip": "1",
"limit": "0",
},
timeout=10,
headers={
"Accept": "application/json",
"User-Agent": "rki/mex",
},
)


def test_get_rule_set_mocked(
mocked_backend: MagicMock, rule_set_response: PersonRuleSetResponse
) -> None:
Expand Down
11 changes: 11 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
PersonRuleSetRequest,
PersonRuleSetResponse,
PreventivePerson,
PreviewPerson,
SubtractivePerson,
)
from mex.common.types import (
Expand Down Expand Up @@ -64,6 +65,16 @@ def merged_person() -> MergedPerson:
)


@pytest.fixture
def preview_person() -> PreviewPerson:
"""Return a dummy preview person for testing purposes."""
return PreviewPerson(
identifier=MergedPersonIdentifier.generate(seed=876),
affiliation=[MergedOrganizationIdentifier.generate(seed=300)],
email=[Email("TintzmannM@rki.de")],
)


@pytest.fixture
def rule_set_request() -> PersonRuleSetRequest:
"""Return a dummy person rule set request for testing purposes."""
Expand Down

0 comments on commit 37baf24

Please sign in to comment.