smoke test the rest of the apps

This commit is contained in:
Ross
2026-06-10 22:05:12 +01:00
parent e670adf2d0
commit 6bb9441748
55 changed files with 1454 additions and 109 deletions
+4 -1
View File
@@ -6,7 +6,8 @@
<input type="submit" value="Update">
</form>
{% if request.user.is_superuser %}
{% if object %}
{% if request.user.is_superuser and object.id %}
<a href="{% url 'admin:oef_formats_change' object.id %}">Admin</a>
{% endif %}
@@ -22,6 +23,8 @@
{% endif %}
"><a href='{% url "oef:entry_detail" entry.pk %}'>{{ entry.exam_code }}</a> / {{ entry.exam_name }}</li>
{% endfor %}
</ul>
{% endif %}
{% endblock content %}
-3
View File
@@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.
+1
View File
@@ -0,0 +1 @@
# OEF tests package
+95
View File
@@ -0,0 +1,95 @@
import pytest
from django.urls import reverse
from django.contrib.auth.models import User
from django.test import Client
SAFE_STATUS_CODES = {200, 301, 302, 303, 400, 403, 404, 405}
@pytest.fixture
def candidate_client(db):
user = User.objects.create_user(username="candidate", password="password", email="candidate@test.com")
client = Client()
client.force_login(user)
return client
@pytest.fixture
def superuser_client(db):
user = User.objects.create_superuser(username="superuser", password="password", email="superuser@test.com")
client = Client()
client.force_login(user)
return client
@pytest.fixture
def anonymous_client(db):
return Client()
@pytest.fixture
def smoke_data(db):
from oef.models import Entry, Formats
entry = Entry.objects.create(
modality="CT",
exam_code="CT1",
exam_name="CT Entry",
questions="Question Text\nQuestion 2",
questions_original="Question Text\nQuestion 2",
)
fmt = Formats.objects.create(
name="Format 1",
format="Question Text",
)
return {
"entry": entry,
"format": fmt,
}
URL_SPECS = [
("oef:entry_table_view", None),
("oef:formats_view", None),
("oef:formats_dupe_view", None),
("oef:format_create", None),
("oef:format_search", None),
("oef:replace_questions", None),
("oef:questions", None),
("oef:subspecialties", None),
("oef:entries_table", None),
("oef:entries", None),
("oef:questions_diff", None),
("oef:questions_sym", None),
("oef:entries_by_question", None),
("oef:entries_by_question_codes", None),
("oef:entry_update", lambda d: {"pk": d["entry"].pk}),
("oef:entry_detail", lambda d: {"pk": d["entry"].pk}),
("oef:entry_detail_formats", lambda d: {"pk": d["entry"].pk}),
("oef:format_update", lambda d: {"pk": d["format"].pk}),
("oef:formats_apply", lambda d: {"pk": d["format"].pk}),
("oef:formats_delete", lambda d: {"pk": d["format"].pk}),
("oef:formats_save", None),
("oef:output", None),
]
@pytest.mark.django_db
@pytest.mark.parametrize("url_name, kwargs_lambda", URL_SPECS)
def test_url_smoke_anonymous(anonymous_client, smoke_data, url_name, kwargs_lambda):
kwargs = kwargs_lambda(smoke_data) if kwargs_lambda else None
url = reverse(url_name, kwargs=kwargs)
response = anonymous_client.get(url, follow=False)
assert response.status_code != 500, f"500 Server Error on {url_name} ({url}) for Anonymous"
assert response.status_code in {200, 302, 400, 403, 404, 405}, f"Unexpected status code {response.status_code} on {url_name} for Anonymous"
@pytest.mark.django_db
@pytest.mark.parametrize("url_name, kwargs_lambda", URL_SPECS)
def test_url_smoke_candidate(candidate_client, smoke_data, url_name, kwargs_lambda):
kwargs = kwargs_lambda(smoke_data) if kwargs_lambda else None
url = reverse(url_name, kwargs=kwargs)
response = candidate_client.get(url, follow=False)
assert response.status_code != 500, f"500 Server Error on {url_name} ({url}) for Candidate"
assert response.status_code in SAFE_STATUS_CODES, f"Unexpected status code {response.status_code} on {url_name} for Candidate"
@pytest.mark.django_db
@pytest.mark.parametrize("url_name, kwargs_lambda", URL_SPECS)
def test_url_smoke_superuser(superuser_client, smoke_data, url_name, kwargs_lambda):
kwargs = kwargs_lambda(smoke_data) if kwargs_lambda else None
url = reverse(url_name, kwargs=kwargs)
response = superuser_client.get(url, follow=False)
assert response.status_code != 500, f"500 Server Error on {url_name} ({url}) for Superuser"
assert response.status_code in SAFE_STATUS_CODES, f"Unexpected status code {response.status_code} on {url_name} for Superuser"