diff options
| author | Dennis Fink | 2026-11-14 19:43:28 +0100 |
|---|---|---|
| committer | Dennis Fink | 2026-11-14 19:43:28 +0100 |
| commit | c74feda222745ab7cca8993df83d9ea5f9d07e5b (patch) | |
| tree | acc7bf9bd7223f9d685d6c2954c5c90d7a9e36f0 /tests/views/test_admin.py | |
| parent | e52e554e2d033dd5ef8397617644e90e354f9560 (diff) | |
| download | webmentions-ssg-c74feda222745ab7cca8993df83d9ea5f9d07e5b.tar.gz webmentions-ssg-c74feda222745ab7cca8993df83d9ea5f9d07e5b.zip | |
refactor(core): use HTTPStatus consistently
Replace numeric HTTP response and assertion codes in views and tests
with `HTTPStatus` members so status handling is more descriptive and
consistent.
Diffstat (limited to 'tests/views/test_admin.py')
| -rw-r--r-- | tests/views/test_admin.py | 41 |
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 |
