You've already forked hotpocket
BTHLABS-61: Service layer refactoring
A journey to fix `ValidationError` in Pocket imports turned service layer refactoring :D
This commit is contained in:
@@ -9,7 +9,7 @@ from django.urls import reverse
|
||||
import pytest
|
||||
from pytest_django import asserts
|
||||
|
||||
from hotpocket_backend.apps.saves.models import Association
|
||||
from hotpocket_backend_testing.services.saves import AssociationsTestingService
|
||||
from hotpocket_common.constants import AssociationsSearchMode
|
||||
|
||||
|
||||
@@ -35,9 +35,10 @@ def test_ok(authenticated_client: Client,
|
||||
fetch_redirect_response=False,
|
||||
)
|
||||
|
||||
association_object = Association.objects.get(pk=association_out.pk)
|
||||
assert association_object.updated_at > association_out.updated_at
|
||||
assert association_object.deleted_at is not None
|
||||
AssociationsTestingService().assert_deleted(
|
||||
pk=association_out.pk,
|
||||
reference=association_out,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
@@ -65,6 +66,34 @@ def test_ok_htmx(authenticated_client: Client,
|
||||
assert result.json() == expected_payload
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_ok_archived(authenticated_client: Client,
|
||||
archived_association_out,
|
||||
):
|
||||
# When
|
||||
result = authenticated_client.post(
|
||||
reverse('ui.associations.delete', args=(archived_association_out.pk,)),
|
||||
data={
|
||||
'canhazconfirm': 'hai',
|
||||
},
|
||||
)
|
||||
|
||||
# Then
|
||||
asserts.assertRedirects(
|
||||
result,
|
||||
reverse(
|
||||
'ui.associations.browse',
|
||||
query=[('mode', AssociationsSearchMode.ARCHIVED.value)],
|
||||
),
|
||||
fetch_redirect_response=False,
|
||||
)
|
||||
|
||||
AssociationsTestingService().assert_deleted(
|
||||
pk=archived_association_out.pk,
|
||||
reference=archived_association_out,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_invalid_all_missing(authenticated_client: Client,
|
||||
association_out,
|
||||
@@ -78,13 +107,13 @@ def test_invalid_all_missing(authenticated_client: Client,
|
||||
|
||||
# Then
|
||||
assert result.status_code == http.HTTPStatus.OK
|
||||
|
||||
association_object = Association.objects.get(pk=association_out.pk)
|
||||
assert association_object.updated_at == association_out.updated_at
|
||||
assert association_object.deleted_at is None
|
||||
|
||||
assert 'canhazconfirm' in result.context['form'].errors
|
||||
|
||||
AssociationsTestingService().assert_not_deleted(
|
||||
pk=association_out.pk,
|
||||
reference=association_out,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_invalid_all_empty(authenticated_client: Client,
|
||||
@@ -100,13 +129,45 @@ def test_invalid_all_empty(authenticated_client: Client,
|
||||
|
||||
# Then
|
||||
assert result.status_code == http.HTTPStatus.OK
|
||||
|
||||
association_object = Association.objects.get(pk=association_out.pk)
|
||||
assert association_object.updated_at == association_out.updated_at
|
||||
assert association_object.deleted_at is None
|
||||
|
||||
assert 'canhazconfirm' in result.context['form'].errors
|
||||
|
||||
AssociationsTestingService().assert_not_deleted(
|
||||
pk=association_out.pk,
|
||||
reference=association_out,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_deleted(authenticated_client: Client,
|
||||
deleted_association_out,
|
||||
):
|
||||
# When
|
||||
result = authenticated_client.post(
|
||||
reverse('ui.associations.delete', args=(deleted_association_out.pk,)),
|
||||
data={
|
||||
'canhazconfirm': 'hai',
|
||||
},
|
||||
)
|
||||
|
||||
# Then
|
||||
assert result.status_code == http.HTTPStatus.NOT_FOUND
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_not_found(authenticated_client: Client,
|
||||
null_uuid,
|
||||
):
|
||||
# When
|
||||
result = authenticated_client.post(
|
||||
reverse('ui.associations.delete', args=(null_uuid,)),
|
||||
data={
|
||||
'canhazconfirm': 'hai',
|
||||
},
|
||||
)
|
||||
|
||||
# Then
|
||||
assert result.status_code == http.HTTPStatus.NOT_FOUND
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_other_account_association(authenticated_client: Client,
|
||||
|
||||
Reference in New Issue
Block a user