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:
@@ -100,6 +100,54 @@ def test_invalid_all_empty(authenticated_client: Client,
|
||||
assert 'canhazconfirm' in result.context['form'].errors
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_archived(authenticated_client: Client,
|
||||
archived_association_out,
|
||||
):
|
||||
# When
|
||||
result = authenticated_client.post(
|
||||
reverse('ui.associations.archive', args=(archived_association_out.pk,)),
|
||||
data={
|
||||
'canhazconfirm': 'hai',
|
||||
},
|
||||
)
|
||||
|
||||
# Then
|
||||
assert result.status_code == http.HTTPStatus.NOT_FOUND
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_deleted(authenticated_client: Client,
|
||||
deleted_association_out,
|
||||
):
|
||||
# When
|
||||
result = authenticated_client.post(
|
||||
reverse('ui.associations.archive', 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.archive', 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,
|
||||
other_account_association_out,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -47,10 +47,10 @@ def test_ok(authenticated_client: Client,
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_invalid_all_empty(authenticated_client: Client,
|
||||
association_out,
|
||||
payload,
|
||||
):
|
||||
def test_all_empty(authenticated_client: Client,
|
||||
association_out,
|
||||
payload,
|
||||
):
|
||||
# Given
|
||||
effective_payload = {
|
||||
key: ''
|
||||
@@ -79,9 +79,9 @@ def test_invalid_all_empty(authenticated_client: Client,
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_invalid_all_missing(authenticated_client: Client,
|
||||
association_out,
|
||||
):
|
||||
def test_all_missing(authenticated_client: Client,
|
||||
association_out,
|
||||
):
|
||||
# Given
|
||||
effective_payload = {}
|
||||
|
||||
@@ -105,6 +105,45 @@ def test_invalid_all_missing(authenticated_client: Client,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_archived(authenticated_client: Client,
|
||||
archived_association_out,
|
||||
):
|
||||
# When
|
||||
result = authenticated_client.post(
|
||||
reverse('ui.associations.edit', args=(archived_association_out.pk,)),
|
||||
)
|
||||
|
||||
# Then
|
||||
assert result.status_code == http.HTTPStatus.NOT_FOUND
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_deleted(authenticated_client: Client,
|
||||
deleted_association_out,
|
||||
):
|
||||
# When
|
||||
result = authenticated_client.post(
|
||||
reverse('ui.associations.edit', args=(deleted_association_out.pk,)),
|
||||
)
|
||||
|
||||
# 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.edit', args=(null_uuid,)),
|
||||
)
|
||||
|
||||
# Then
|
||||
assert result.status_code == http.HTTPStatus.NOT_FOUND
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_other_account_association(authenticated_client: Client,
|
||||
other_account_association_out,
|
||||
|
||||
@@ -128,6 +128,54 @@ def test_invalid_all_empty(authenticated_client: Client,
|
||||
assert 'canhazconfirm' in result.context['form'].errors
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_archived(authenticated_client: Client,
|
||||
archived_association_out,
|
||||
):
|
||||
# When
|
||||
result = authenticated_client.post(
|
||||
reverse('ui.associations.refresh', args=(archived_association_out.pk,)),
|
||||
data={
|
||||
'canhazconfirm': 'hai',
|
||||
},
|
||||
)
|
||||
|
||||
# Then
|
||||
assert result.status_code == http.HTTPStatus.NOT_FOUND
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_deleted(authenticated_client: Client,
|
||||
deleted_association_out,
|
||||
):
|
||||
# When
|
||||
result = authenticated_client.post(
|
||||
reverse('ui.associations.refresh', 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.refresh', 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,
|
||||
other_account_association_out,
|
||||
|
||||
@@ -54,6 +54,45 @@ def test_ok_htmx(authenticated_client: Client,
|
||||
assert result.context['association'].target.pk == association_out.target.pk
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_archived(authenticated_client: Client,
|
||||
archived_association_out,
|
||||
):
|
||||
# When
|
||||
result = authenticated_client.get(
|
||||
reverse('ui.associations.star', args=(archived_association_out.pk,)),
|
||||
)
|
||||
|
||||
# Then
|
||||
assert result.status_code == http.HTTPStatus.NOT_FOUND
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_deleted(authenticated_client: Client,
|
||||
deleted_association_out,
|
||||
):
|
||||
# When
|
||||
result = authenticated_client.get(
|
||||
reverse('ui.associations.star', args=(deleted_association_out.pk,)),
|
||||
)
|
||||
|
||||
# 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.get(
|
||||
reverse('ui.associations.star', args=(null_uuid,)),
|
||||
)
|
||||
|
||||
# Then
|
||||
assert result.status_code == http.HTTPStatus.NOT_FOUND
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_other_account_association(authenticated_client: Client,
|
||||
other_account_association_out,
|
||||
|
||||
@@ -54,6 +54,45 @@ def test_ok_htmx(authenticated_client: Client,
|
||||
assert result.context['association'].target.pk == starred_association_out.target.pk
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_archived(authenticated_client: Client,
|
||||
archived_association_out,
|
||||
):
|
||||
# When
|
||||
result = authenticated_client.get(
|
||||
reverse('ui.associations.unstar', args=(archived_association_out.pk,)),
|
||||
)
|
||||
|
||||
# Then
|
||||
assert result.status_code == http.HTTPStatus.NOT_FOUND
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_deleted(authenticated_client: Client,
|
||||
deleted_association_out,
|
||||
):
|
||||
# When
|
||||
result = authenticated_client.get(
|
||||
reverse('ui.associations.unstar', args=(deleted_association_out.pk,)),
|
||||
)
|
||||
|
||||
# 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.get(
|
||||
reverse('ui.associations.unstar', args=(null_uuid,)),
|
||||
)
|
||||
|
||||
# Then
|
||||
assert result.status_code == http.HTTPStatus.NOT_FOUND
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_other_account_association(authenticated_client: Client,
|
||||
other_account_starred_association_out,
|
||||
|
||||
@@ -66,6 +66,19 @@ def test_authenticated_deleted(authenticated_client: Client,
|
||||
assert result.status_code == http.HTTPStatus.NOT_FOUND
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_authenticated_deleted_save(authenticated_client: Client,
|
||||
deleted_save_association_out,
|
||||
):
|
||||
# When
|
||||
result = authenticated_client.get(
|
||||
reverse('ui.associations.view', args=(deleted_save_association_out.pk,)),
|
||||
)
|
||||
|
||||
# Then
|
||||
assert result.status_code == http.HTTPStatus.NOT_FOUND
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_authenticated_not_found(authenticated_client: Client,
|
||||
null_uuid,
|
||||
@@ -169,6 +182,23 @@ def test_authenticated_share_deleted(authenticated_client: Client,
|
||||
assert result.status_code == http.HTTPStatus.NOT_FOUND
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_authenticated_share_deleted_save(authenticated_client: Client,
|
||||
other_account_deleted_save_association_out,
|
||||
):
|
||||
# When
|
||||
result = authenticated_client.get(
|
||||
reverse(
|
||||
'ui.associations.view',
|
||||
args=(other_account_deleted_save_association_out.pk,),
|
||||
query=[('share', 'true')],
|
||||
),
|
||||
)
|
||||
|
||||
# Then
|
||||
assert result.status_code == http.HTTPStatus.NOT_FOUND
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_authenticated_share_not_found(authenticated_client: Client,
|
||||
null_uuid,
|
||||
@@ -240,6 +270,23 @@ def test_anonymous_share_deleted(client: Client,
|
||||
assert result.status_code == http.HTTPStatus.NOT_FOUND
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_anonymous_share_deleted_save(client: Client,
|
||||
deleted_save_association_out,
|
||||
):
|
||||
# When
|
||||
result = client.get(
|
||||
reverse(
|
||||
'ui.associations.view',
|
||||
args=(deleted_save_association_out.pk,),
|
||||
query=[('share', 'true')],
|
||||
),
|
||||
)
|
||||
|
||||
# Then
|
||||
assert result.status_code == http.HTTPStatus.NOT_FOUND
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_anonymous_share_not_found(client: Client,
|
||||
null_uuid,
|
||||
|
||||
@@ -76,6 +76,7 @@ def test_ok(override_settings_upload_path,
|
||||
|
||||
mock_ui_import_from_pocket_task_apply_async.assert_called_once_with(
|
||||
kwargs={
|
||||
'job': mock.ANY,
|
||||
'account_uuid': account.pk,
|
||||
'csv_path': str(uploaded_file_path),
|
||||
},
|
||||
|
||||
@@ -77,10 +77,11 @@ def test_auth_key_not_found(null_uuid,
|
||||
|
||||
call_result = result.json()
|
||||
assert 'error' in call_result
|
||||
assert call_result['error']['data'].startswith(
|
||||
assert call_result['error']['code'] == -32001
|
||||
assert call_result['error']['message'].startswith(
|
||||
'Auth Key not found',
|
||||
)
|
||||
assert call_auth_key in call_result['error']['data']
|
||||
assert call_auth_key in call_result['error']['message']
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
@@ -108,10 +109,11 @@ def test_deleted_auth_key(deleted_auth_key_out,
|
||||
|
||||
call_result = result.json()
|
||||
assert 'error' in call_result
|
||||
assert call_result['error']['data'].startswith(
|
||||
assert call_result['error']['code'] == -32001
|
||||
assert call_result['error']['message'].startswith(
|
||||
'Auth Key not found',
|
||||
)
|
||||
assert call_auth_key in call_result['error']['data']
|
||||
assert call_auth_key in call_result['error']['message']
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
@@ -139,10 +141,11 @@ def test_expired_auth_key(expired_auth_key_out,
|
||||
|
||||
call_result = result.json()
|
||||
assert 'error' in call_result
|
||||
assert call_result['error']['data'].startswith(
|
||||
assert call_result['error']['code'] == -32000
|
||||
assert call_result['error']['message'].startswith(
|
||||
'Auth Key expired',
|
||||
)
|
||||
assert call_auth_key in call_result['error']['data']
|
||||
assert call_auth_key in call_result['error']['message']
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
@@ -170,10 +173,11 @@ def test_consumed_auth_key(consumed_auth_key,
|
||||
|
||||
call_result = result.json()
|
||||
assert 'error' in call_result
|
||||
assert call_result['error']['data'].startswith(
|
||||
assert call_result['error']['code'] == -32000
|
||||
assert call_result['error']['message'].startswith(
|
||||
'Auth Key already consumed',
|
||||
)
|
||||
assert call_auth_key in call_result['error']['data']
|
||||
assert call_auth_key in call_result['error']['message']
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
@@ -201,4 +205,5 @@ def test_inactive_account(inactive_account_auth_key,
|
||||
|
||||
call_result = result.json()
|
||||
assert 'error' in call_result
|
||||
assert str(inactive_account.pk) in call_result['error']['data']
|
||||
assert call_result['error']['code'] == -32001
|
||||
assert str(inactive_account.pk) in call_result['error']['message']
|
||||
|
||||
Reference in New Issue
Block a user