112 lines
2.2 KiB
Python
112 lines
2.2 KiB
Python
# -*- 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
|
|
|
|
|
|
@pytest.fixture
|
|
def payload(save_out):
|
|
return {
|
|
'pk': str(save_out.pk),
|
|
}
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_ok(client: Client, payload, save_out):
|
|
# When
|
|
result = client.post(
|
|
reverse('ui.saves.embed'),
|
|
headers={
|
|
'HX-Request': 'true',
|
|
},
|
|
data=payload,
|
|
)
|
|
|
|
# Then
|
|
assert result.status_code == http.HTTPStatus.OK
|
|
|
|
asserts.assertTemplateUsed(result, 'ui/saves/partials/embed.html')
|
|
assert result.context['save'] == save_out
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_bad_request_get(client: Client, payload):
|
|
# When
|
|
result = client.get(
|
|
reverse('ui.saves.embed'),
|
|
headers={
|
|
'HX-Request': 'true',
|
|
},
|
|
data=payload,
|
|
)
|
|
|
|
# Then
|
|
assert result.status_code == http.HTTPStatus.BAD_REQUEST
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_bad_request_missing_pk(client: Client):
|
|
# When
|
|
result = client.post(
|
|
reverse('ui.saves.embed'),
|
|
headers={
|
|
'HX-Request': 'true',
|
|
},
|
|
data={},
|
|
)
|
|
|
|
# Then
|
|
assert result.status_code == http.HTTPStatus.BAD_REQUEST
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_bad_request_not_htmx(client: Client, payload):
|
|
# When
|
|
result = client.post(
|
|
reverse('ui.saves.embed'),
|
|
data=payload,
|
|
)
|
|
|
|
# Then
|
|
assert result.status_code == http.HTTPStatus.BAD_REQUEST
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_not_found(client: Client, null_uuid):
|
|
# When
|
|
result = client.post(
|
|
reverse('ui.saves.embed'),
|
|
headers={
|
|
'HX-Request': 'true',
|
|
},
|
|
data={
|
|
'pk': str(null_uuid),
|
|
},
|
|
)
|
|
|
|
# Then
|
|
assert result.status_code == http.HTTPStatus.NOT_FOUND
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_deleted(client: Client, deleted_save_out):
|
|
# When
|
|
result = client.post(
|
|
reverse('ui.saves.embed'),
|
|
headers={
|
|
'HX-Request': 'true',
|
|
},
|
|
data={
|
|
'pk': str(deleted_save_out.pk),
|
|
},
|
|
)
|
|
|
|
# Then
|
|
assert result.status_code == http.HTTPStatus.NOT_FOUND
|