Skip to content

Commit

Permalink
Add dirty state tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-misuk-valor committed May 20, 2024
1 parent 543679e commit 4876d5f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/hope_dedup_engine/apps/public_api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def perform_create(self, serializer: Serializer) -> None:
def perform_destroy(self, instance: Image) -> None:
deduplication_set = instance.deduplication_set
super().perform_destroy(instance)
deduplication_set.state = DeduplicationSet.State.DIRTY
deduplication_set.updated_by = self.request.user
deduplication_set.save()

Expand Down
13 changes: 12 additions & 1 deletion tests/api/test_business_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
DEDUPLICATION_SET_DETAIL_VIEW,
DEDUPLICATION_SET_LIST_VIEW,
DEDUPLICATION_SET_PROCESS_VIEW,
IMAGE_DETAIL_VIEW,
IMAGE_LIST_VIEW,
JSON,
)
Expand All @@ -14,6 +15,7 @@
from testutils.factories.api import DeduplicationSetFactory, ImageFactory

from hope_dedup_engine.apps.public_api.models import DeduplicationSet
from hope_dedup_engine.apps.public_api.models.deduplication import Image
from hope_dedup_engine.apps.public_api.serializers import DeduplicationSetSerializer, ImageSerializer


Expand Down Expand Up @@ -50,7 +52,16 @@ def test_new_image_makes_deduplication_set_state_dirty(
assert deduplication_set.state == DeduplicationSet.State.DIRTY


def test_can_deletion_triggers_model_data_deletion(
def test_image_deletion_makes_deduplication_state_dirty(
api_client: APIClient, deduplication_set: DeduplicationSet, image: Image
) -> None:
response = api_client.delete(reverse(IMAGE_DETAIL_VIEW, (deduplication_set.pk, image.pk)))
assert response.status_code == status.HTTP_204_NO_CONTENT
deduplication_set.refresh_from_db()
assert deduplication_set.state == DeduplicationSet.State.DIRTY


def test_deletion_triggers_model_data_deletion(
api_client: APIClient, deduplication_set: DeduplicationSet, delete_model_data: MagicMock
) -> None:
response = api_client.delete(reverse(DEDUPLICATION_SET_DETAIL_VIEW, (deduplication_set.pk,)))
Expand Down

0 comments on commit 4876d5f

Please sign in to comment.