aboutsummaryrefslogtreecommitdiff
path: root/tests/views/test_admin.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/views/test_admin.py41
1 files changed, 22 insertions, 19 deletions
diff --git a/tests/views/test_admin.py b/tests/views/test_admin.py
index f166318..a88fbfa 100644
--- a/tests/views/test_admin.py
+++ b/tests/views/test_admin.py
@@ -4,6 +4,7 @@
import uuid
from datetime import UTC, datetime, timedelta
+from http import HTTPStatus
from types import ModuleType
from unittest.mock import Mock
@@ -38,7 +39,7 @@ def views_module(app: Flask) -> ModuleType:
def test_sent_views_require_login(client: FlaskClient, path: str) -> None:
response = client.get(path)
- assert response.status_code == 302
+ assert response.status_code == HTTPStatus.FOUND
assert "/login" in response.headers["Location"]
@@ -48,7 +49,7 @@ def test_sent_lists_sources(app: Flask, client: FlaskClient) -> None:
response = client.get("/sent")
- assert response.status_code == 200
+ assert response.status_code == HTTPStatus.OK
html = response.get_data(as_text=True)
@@ -63,7 +64,7 @@ def test_sent_source_lists_webmentions(app: Flask, client: FlaskClient) -> None:
response = client.get(f"/sent/{identifier}")
- assert response.status_code == 200
+ assert response.status_code == HTTPStatus.OK
html = response.get_data(as_text=True)
@@ -86,13 +87,13 @@ def test_sent_source_returns_404_for_unknown_source(
) -> None:
log_in(app, client)
response = client.get(f"/sent/{uuid.uuid7()}")
- assert response.status_code == 404
+ assert response.status_code == HTTPStatus.NOT_FOUND
def test_received_requires_login(client: FlaskClient) -> None:
response = client.get("/received")
- assert response.status_code == 302
+ assert response.status_code == HTTPStatus.FOUND
assert "/login" in response.headers["Location"]
@@ -102,7 +103,7 @@ def test_received_lists_webmentions(app: Flask, client: FlaskClient) -> None:
response = client.get("/received")
- assert response.status_code == 200
+ assert response.status_code == HTTPStatus.OK
html = response.get_data(as_text=True)
assert SOURCE_URL in html
assert TARGET_URL in html
@@ -112,7 +113,7 @@ def test_received_lists_webmentions(app: Flask, client: FlaskClient) -> None:
def test_received_admin_actions_require_login(client: FlaskClient, action: str) -> None:
response = client.post(f"/received/{uuid.uuid7()}/{action}")
- assert response.status_code == 302
+ assert response.status_code == HTTPStatus.FOUND
assert "/login" in response.headers["Location"]
@@ -130,7 +131,7 @@ def test_received_admin_actions_reject_invalid_form(
response = client.post(f"/received/{identifier}/{action}")
- assert response.status_code == 400
+ assert response.status_code == HTTPStatus.BAD_REQUEST
form.validate_on_submit.assert_called_once_with()
@@ -147,7 +148,7 @@ def test_received_admin_actions_return_404_for_unknown_webmention(
response = client.post(f"/received/{uuid.uuid7()}/{action}")
- assert response.status_code == 404
+ assert response.status_code == HTTPStatus.NOT_FOUND
def test_delete_received_webmention(
@@ -162,7 +163,7 @@ def test_delete_received_webmention(
response = client.post(f"/received/{identifier}/delete?page=3")
- assert response.status_code == 302
+ assert response.status_code == HTTPStatus.FOUND
assert response.headers["Location"].endswith("/received?page=3")
with app.app_context():
@@ -190,7 +191,7 @@ def test_reverify_received_webmention(
response = client.post(f"/received/{identifier}/reverify?page=2")
- assert response.status_code == 302
+ assert response.status_code == HTTPStatus.FOUND
assert response.headers["Location"].endswith("/received?page=2")
with app.app_context():
@@ -206,7 +207,7 @@ def test_reverify_received_webmention(
def test_rescan_sent_sources_requires_login(client: FlaskClient) -> None:
response = client.post("/sent/rescan")
- assert response.status_code == 302
+ assert response.status_code == HTTPStatus.FOUND
assert "/login" in response.headers["Location"]
@@ -225,7 +226,9 @@ def test_rescan_sent_sources(
response = client.post("/sent/rescan")
- assert response.status_code == (302 if valid else 400)
+ assert response.status_code == (
+ HTTPStatus.FOUND if valid else HTTPStatus.BAD_REQUEST
+ )
form.validate_on_submit.assert_called_once_with()
if valid:
@@ -238,7 +241,7 @@ def test_rescan_sent_sources(
def test_resend_sent_webmention_requires_login(client: FlaskClient) -> None:
response = client.post(f"/sent/{uuid.uuid7()}/{uuid.uuid7()}/resend")
- assert response.status_code == 302
+ assert response.status_code == HTTPStatus.FOUND
assert "/login" in response.headers["Location"]
@@ -254,7 +257,7 @@ def test_resend_sent_webmention_rejects_invalid_form(
response = client.post(f"/sent/{source_identifier}/{webmention_identifier}/resend")
- assert response.status_code == 400
+ assert response.status_code == HTTPStatus.BAD_REQUEST
def test_resend_sent_webmention_returns_404_for_unknown_webmention(
@@ -269,7 +272,7 @@ def test_resend_sent_webmention_returns_404_for_unknown_webmention(
response = client.post(f"/sent/{source_identifier}/{uuid.uuid7()}/resend")
- assert response.status_code == 404
+ assert response.status_code == HTTPStatus.NOT_FOUND
def test_resend_sent_webmention_rejects_wrong_source(
@@ -287,7 +290,7 @@ def test_resend_sent_webmention_rejects_wrong_source(
f"/sent/{wrong_source_identifier}/{webmention_identifier}/resend"
)
- assert response.status_code == 404
+ assert response.status_code == HTTPStatus.NOT_FOUND
def test_resend_sent_webmention_reopens_current_revision(
@@ -311,7 +314,7 @@ def test_resend_sent_webmention_reopens_current_revision(
response = client.post(f"/sent/{source_identifier}/{webmention_identifier}/resend")
- assert response.status_code == 302
+ assert response.status_code == HTTPStatus.FOUND
assert response.headers["Location"].endswith(f"/sent/{source_identifier}")
with app.app_context():
@@ -356,7 +359,7 @@ def test_admin_only_links_safe_existing_status_urls(
session["_fresh"] = True
response = client.get(f"/sent/{source_identifier}")
- assert response.status_code == 200
+ assert response.status_code == HTTPStatus.OK
html = response.get_data(as_text=True)
assert (f'href="{status_url}"' in html) is safe
assert status_url in html