You've already forked hotpocket
This commit is contained in:
166
services/backend/tests/ui/views/associations/test_archive.py
Normal file
166
services/backend/tests/ui/views/associations/test_archive.py
Normal file
@@ -0,0 +1,166 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# type: ignore
|
||||
from __future__ import annotations
|
||||
|
||||
import http
|
||||
|
||||
from django.test import Client
|
||||
from django.urls import reverse
|
||||
import pytest
|
||||
from pytest_django import asserts
|
||||
|
||||
from hotpocket_backend_testing.services.saves import AssociationsTestingService
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_ok(authenticated_client: Client,
|
||||
association_out,
|
||||
):
|
||||
# When
|
||||
result = authenticated_client.post(
|
||||
reverse('ui.associations.archive', args=(association_out.pk,)),
|
||||
data={
|
||||
'canhazconfirm': 'hai',
|
||||
},
|
||||
)
|
||||
|
||||
# Then
|
||||
asserts.assertRedirects(
|
||||
result,
|
||||
reverse('ui.associations.browse'),
|
||||
fetch_redirect_response=False,
|
||||
)
|
||||
|
||||
AssociationsTestingService().assert_archived(
|
||||
pk=association_out.pk, reference=association_out,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_ok_htmx(authenticated_client: Client,
|
||||
association_out,
|
||||
):
|
||||
# When
|
||||
result = authenticated_client.post(
|
||||
reverse('ui.associations.archive', args=(association_out.pk,)),
|
||||
headers={
|
||||
'HX-Request': 'true',
|
||||
},
|
||||
data={
|
||||
'canhazconfirm': 'hai',
|
||||
},
|
||||
)
|
||||
|
||||
# Then
|
||||
assert result.status_code == http.HTTPStatus.OK
|
||||
|
||||
expected_payload = {
|
||||
'status': 'ok',
|
||||
'result': True,
|
||||
}
|
||||
assert result.json() == expected_payload
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_invalid_all_missing(authenticated_client: Client,
|
||||
association_out,
|
||||
):
|
||||
# When
|
||||
result = authenticated_client.post(
|
||||
reverse('ui.associations.archive', args=(association_out.pk,)),
|
||||
data={
|
||||
},
|
||||
)
|
||||
|
||||
# Then
|
||||
assert result.status_code == http.HTTPStatus.OK
|
||||
|
||||
AssociationsTestingService().assert_not_archived(pk=association_out.pk)
|
||||
|
||||
assert 'canhazconfirm' in result.context['form'].errors
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_invalid_all_empty(authenticated_client: Client,
|
||||
association_out,
|
||||
):
|
||||
# When
|
||||
result = authenticated_client.post(
|
||||
reverse('ui.associations.archive', args=(association_out.pk,)),
|
||||
data={
|
||||
'canhazconfirm': '',
|
||||
},
|
||||
)
|
||||
|
||||
# Then
|
||||
assert result.status_code == http.HTTPStatus.OK
|
||||
|
||||
AssociationsTestingService().assert_not_archived(pk=association_out.pk)
|
||||
|
||||
assert 'canhazconfirm' in result.context['form'].errors
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_other_account_association(authenticated_client: Client,
|
||||
other_account_association_out,
|
||||
):
|
||||
# When
|
||||
result = authenticated_client.post(
|
||||
reverse('ui.associations.archive', args=(other_account_association_out.pk,)),
|
||||
data={
|
||||
'canhazconfirm': 'hai',
|
||||
},
|
||||
)
|
||||
|
||||
# Then
|
||||
assert result.status_code == http.HTTPStatus.FORBIDDEN
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_inactive_account(inactive_account_client: Client,
|
||||
association_out,
|
||||
):
|
||||
# When
|
||||
result = inactive_account_client.post(
|
||||
reverse('ui.associations.archive', args=(association_out.pk,)),
|
||||
data={
|
||||
'canhazconfirm': 'hai',
|
||||
},
|
||||
)
|
||||
|
||||
# Then
|
||||
asserts.assertRedirects(
|
||||
result,
|
||||
reverse(
|
||||
'ui.accounts.login',
|
||||
query=[
|
||||
('next', reverse('ui.associations.archive', args=(association_out.pk,))),
|
||||
],
|
||||
),
|
||||
fetch_redirect_response=False,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_anonymous(client: Client,
|
||||
association_out,
|
||||
):
|
||||
# When
|
||||
result = client.post(
|
||||
reverse('ui.associations.archive', args=(association_out.pk,)),
|
||||
data={
|
||||
'canhazconfirm': 'hai',
|
||||
},
|
||||
)
|
||||
|
||||
# Then
|
||||
asserts.assertRedirects(
|
||||
result,
|
||||
reverse(
|
||||
'ui.accounts.login',
|
||||
query=[
|
||||
('next', reverse('ui.associations.archive', args=(association_out.pk,))),
|
||||
],
|
||||
),
|
||||
fetch_redirect_response=False,
|
||||
)
|
||||
Reference in New Issue
Block a user