-
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.
78: Allow per deduplication set face distance threshold configuration (…
…#85) * Add possibility to configure face distance threshold per deduplication set * Check face_distance_threshold value passed to DuplicationDetector * Resolve merge issues
- Loading branch information
1 parent
5a16805
commit e15ffc5
Showing
14 changed files
with
175 additions
and
28 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
36 changes: 36 additions & 0 deletions
36
src/hope_dedup_engine/apps/api/migrations/0005_config_deduplicationset_config.py
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,36 @@ | ||
# Generated by Django 5.0.7 on 2024-09-24 09:05 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("api", "0004_remove_deduplicationset_error_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Config", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("face_distance_threshold", models.FloatField(null=True)), | ||
], | ||
), | ||
migrations.AddField( | ||
model_name="deduplicationset", | ||
name="config", | ||
field=models.OneToOneField( | ||
null=True, on_delete=django.db.models.deletion.SET_NULL, to="api.config" | ||
), | ||
), | ||
] |
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,46 +1,63 @@ | ||
from api_const import DEDUPLICATION_SET_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 DeduplicationSetFactory | ||
|
||
from hope_dedup_engine.apps.api.models import DeduplicationSet | ||
from hope_dedup_engine.apps.api.serializers import DeduplicationSetSerializer | ||
from hope_dedup_engine.apps.api.serializers import CreateDeduplicationSetSerializer | ||
|
||
|
||
def test_can_create_deduplication_set(api_client: APIClient) -> None: | ||
previous_amount = DeduplicationSet.objects.count() | ||
data = DeduplicationSetSerializer(DeduplicationSetFactory.build()).data | ||
data = CreateDeduplicationSetSerializer(DeduplicationSetFactory.build()).data | ||
|
||
response = api_client.post( | ||
reverse(DEDUPLICATION_SET_LIST_VIEW), data=data, format=JSON | ||
) | ||
|
||
assert response.status_code == status.HTTP_201_CREATED | ||
assert DeduplicationSet.objects.count() == previous_amount + 1 | ||
data = response.json() | ||
assert data["state"] == DeduplicationSet.State.CLEAN.label | ||
|
||
|
||
def test_missing_fields_handling(api_client: APIClient) -> None: | ||
data = DeduplicationSetSerializer(DeduplicationSetFactory.build()).data | ||
data = CreateDeduplicationSetSerializer(DeduplicationSetFactory.build()).data | ||
del data["reference_pk"] | ||
|
||
response = api_client.post( | ||
reverse(DEDUPLICATION_SET_LIST_VIEW), data=data, format=JSON | ||
) | ||
|
||
assert response.status_code == status.HTTP_400_BAD_REQUEST | ||
errors = response.json() | ||
assert len(errors) == 1 | ||
assert "reference_pk" in errors | ||
|
||
|
||
def test_invalid_values_handling(api_client: APIClient) -> None: | ||
data = DeduplicationSetSerializer(DeduplicationSetFactory.build()).data | ||
data["reference_pk"] = None | ||
@mark.parametrize("field", ("reference_pk", "config")) | ||
def test_invalid_values_handling(field: str, api_client: APIClient) -> None: | ||
data = CreateDeduplicationSetSerializer(DeduplicationSetFactory.build()).data | ||
data[field] = None | ||
|
||
response = api_client.post( | ||
reverse(DEDUPLICATION_SET_LIST_VIEW), data=data, format=JSON | ||
) | ||
|
||
assert response.status_code == status.HTTP_400_BAD_REQUEST | ||
errors = response.json() | ||
assert len(errors) == 1 | ||
assert "reference_pk" in errors | ||
assert field in errors | ||
|
||
|
||
def test_can_set_deduplication_set_without_config(api_client: APIClient) -> None: | ||
data = CreateDeduplicationSetSerializer(DeduplicationSetFactory.build()).data | ||
del data["config"] | ||
|
||
response = api_client.post( | ||
reverse(DEDUPLICATION_SET_LIST_VIEW), data=data, format=JSON | ||
) | ||
|
||
assert response.status_code == status.HTTP_201_CREATED |
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
Oops, something went wrong.