-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af9234c
commit 4c0a38f
Showing
12 changed files
with
211 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,20 @@ | ||
from hope_dedup_engine.apps.api.const import BULK_IMAGE_LIST, DEDUPLICATION_SET_LIST, DUPLICATE_LIST, IMAGE_LIST | ||
from hope_dedup_engine.apps.api.const import ( | ||
BULK_IMAGE_LIST, | ||
DEDUPLICATION_SET_LIST, | ||
DUPLICATE_LIST, | ||
IGNORED_KEYS_LIST, | ||
IMAGE_LIST, | ||
) | ||
|
||
JSON = "json" | ||
DEDUPLICATION_SET_LIST_VIEW = f"{DEDUPLICATION_SET_LIST}-list" | ||
DEDUPLICATION_SET_DETAIL_VIEW = f"{DEDUPLICATION_SET_LIST}-detail" | ||
LIST = "list" | ||
DETAIL = "detail" | ||
DEDUPLICATION_SET_LIST_VIEW = f"{DEDUPLICATION_SET_LIST}-{LIST}" | ||
DEDUPLICATION_SET_DETAIL_VIEW = f"{DEDUPLICATION_SET_LIST}-{DETAIL}" | ||
DEDUPLICATION_SET_PROCESS_VIEW = f"{DEDUPLICATION_SET_LIST}-process" | ||
IMAGE_LIST_VIEW = f"{IMAGE_LIST}-list" | ||
IMAGE_DETAIL_VIEW = f"{IMAGE_LIST}-detail" | ||
BULK_IMAGE_LIST_VIEW = f"{BULK_IMAGE_LIST}-list" | ||
IMAGE_LIST_VIEW = f"{IMAGE_LIST}-{LIST}" | ||
IMAGE_DETAIL_VIEW = f"{IMAGE_LIST}-{DETAIL}" | ||
BULK_IMAGE_LIST_VIEW = f"{BULK_IMAGE_LIST}-{LIST}" | ||
BULK_IMAGE_CLEAR_VIEW = f"{BULK_IMAGE_LIST}-clear" | ||
DUPLICATE_LIST_VIEW = f"{DUPLICATE_LIST}-list" | ||
DUPLICATE_LIST_VIEW = f"{DUPLICATE_LIST}-{LIST}" | ||
IGNORED_KEYS_LIST_VIEW = f"{IGNORED_KEYS_LIST}-{LIST}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
from api_const import IGNORED_KEYS_LIST_VIEW, JSON | ||
from pytest import mark | ||
from rest_framework import status | ||
from rest_framework.reverse import reverse | ||
from rest_framework.test import APIClient | ||
from testutils.factories.api import IgnoredKeyPairFactory | ||
|
||
from hope_dedup_engine.apps.api.models import DeduplicationSet | ||
from hope_dedup_engine.apps.api.models.deduplication import IgnoredKeyPair | ||
from hope_dedup_engine.apps.api.serializers import IgnoredKeyPairSerializer | ||
from hope_dedup_engine.apps.security.models import User | ||
|
||
|
||
def test_can_create_ignored_key_pair(api_client: APIClient, deduplication_set: DeduplicationSet) -> None: | ||
previous_amount = IgnoredKeyPair.objects.filter(deduplication_set=deduplication_set).count() | ||
data = IgnoredKeyPairSerializer(IgnoredKeyPairFactory.build()).data | ||
|
||
response = api_client.post(reverse(IGNORED_KEYS_LIST_VIEW, (deduplication_set.pk,)), data=data, format=JSON) | ||
assert response.status_code == status.HTTP_201_CREATED | ||
assert IgnoredKeyPair.objects.filter(deduplication_set=deduplication_set).count() == previous_amount + 1 | ||
|
||
|
||
def test_cannot_create_ignored_key_pair_between_systems( | ||
another_system_api_client: APIClient, deduplication_set: DeduplicationSet | ||
) -> None: | ||
previous_amount = IgnoredKeyPair.objects.filter(deduplication_set=deduplication_set).count() | ||
data = IgnoredKeyPairSerializer(IgnoredKeyPairFactory.build()).data | ||
|
||
response = another_system_api_client.post( | ||
reverse(IGNORED_KEYS_LIST_VIEW, (deduplication_set.pk,)), data=data, format=JSON | ||
) | ||
assert response.status_code == status.HTTP_403_FORBIDDEN | ||
assert IgnoredKeyPair.objects.filter(deduplication_set=deduplication_set).count() == previous_amount | ||
|
||
|
||
INVALID_PK_VALUES = "", None | ||
|
||
|
||
@mark.parametrize("first_pk", INVALID_PK_VALUES) | ||
@mark.parametrize("second_pk", INVALID_PK_VALUES) | ||
def test_invalid_values_handling( | ||
api_client: APIClient, deduplication_set: DeduplicationSet, first_pk: str | None, second_pk: str | None | ||
) -> None: | ||
data = IgnoredKeyPairSerializer(IgnoredKeyPairFactory.build()).data | ||
data["first_reference_pk"] = first_pk | ||
data["second_reference_pk"] = second_pk | ||
response = api_client.post(reverse(IGNORED_KEYS_LIST_VIEW, (deduplication_set.pk,)), data=data, format=JSON) | ||
assert response.status_code == status.HTTP_400_BAD_REQUEST | ||
errors = response.json() | ||
assert len(errors) == 2 | ||
assert "first_reference_pk" in errors | ||
assert "second_reference_pk" in errors | ||
|
||
|
||
def test_missing_pk_handling(api_client: APIClient, deduplication_set: DeduplicationSet) -> None: | ||
data = IgnoredKeyPairSerializer(IgnoredKeyPairFactory.build()).data | ||
del data["first_reference_pk"], data["second_reference_pk"] | ||
|
||
response = api_client.post(reverse(IGNORED_KEYS_LIST_VIEW, (deduplication_set.pk,)), data=data, format=JSON) | ||
assert response.status_code == status.HTTP_400_BAD_REQUEST | ||
errors = response.json() | ||
assert "first_reference_pk" in errors | ||
assert "second_reference_pk" in errors | ||
|
||
|
||
def test_deduplication_set_is_updated(api_client: APIClient, user: User, deduplication_set: DeduplicationSet) -> None: | ||
assert deduplication_set.updated_by is None | ||
|
||
data = IgnoredKeyPairSerializer(IgnoredKeyPairFactory.build()).data | ||
response = api_client.post(reverse(IGNORED_KEYS_LIST_VIEW, (deduplication_set.pk,)), data=data, format=JSON) | ||
|
||
assert response.status_code == status.HTTP_201_CREATED | ||
deduplication_set.refresh_from_db() | ||
assert deduplication_set.updated_by == user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from api_const import IGNORED_KEYS_LIST_VIEW | ||
from rest_framework import status | ||
from rest_framework.reverse import reverse | ||
from rest_framework.test import APIClient | ||
|
||
from hope_dedup_engine.apps.api.models import DeduplicationSet | ||
from hope_dedup_engine.apps.api.models.deduplication import IgnoredKeyPair | ||
|
||
|
||
def test_can_list_ignored_key_pairs( | ||
api_client: APIClient, deduplication_set: DeduplicationSet, ignored_key_pair: IgnoredKeyPair | ||
) -> None: | ||
response = api_client.get(reverse(IGNORED_KEYS_LIST_VIEW, (deduplication_set.pk,))) | ||
assert response.status_code == status.HTTP_200_OK | ||
ignored_key_pairs = response.json() | ||
assert len(ignored_key_pairs) | ||
assert len(ignored_key_pairs) == IgnoredKeyPair.objects.filter(deduplication_set=deduplication_set).count() | ||
|
||
|
||
def test_cannot_list_ignored_key_pairs_between_systems( | ||
another_system_api_client: APIClient, deduplication_set: DeduplicationSet | ||
) -> None: | ||
response = another_system_api_client.get(reverse(IGNORED_KEYS_LIST_VIEW, (deduplication_set.pk,))) | ||
assert response.status_code == status.HTTP_403_FORBIDDEN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters