.
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
import pytest
|
||||
from django.urls import reverse
|
||||
|
||||
@pytest.fixture
|
||||
def logged_in_admin(client, django_user_model):
|
||||
admin = django_user_model.objects.create_superuser(
|
||||
username="admin",
|
||||
email="admin@example.com",
|
||||
password="adminpassword"
|
||||
)
|
||||
client.force_login(admin)
|
||||
return admin
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_physics_stats_only_no_attribute_error(client, logged_in_admin):
|
||||
from physics.models import Exam, Question, UserAnswer
|
||||
exam = Exam.objects.create(name="Physics Test Exam", exam_mode=True)
|
||||
exam.author.add(logged_in_admin)
|
||||
|
||||
question = Question.objects.create(
|
||||
stem="stem",
|
||||
a="a", a_answer=True,
|
||||
b="b", b_answer=False,
|
||||
c="c", c_answer=True,
|
||||
d="d", d_answer=False,
|
||||
e="e", e_answer=True,
|
||||
)
|
||||
question.exams.add(exam)
|
||||
|
||||
UserAnswer.objects.create(
|
||||
question=question,
|
||||
exam=exam,
|
||||
a=True, b=False, c=True, d=False, e=True,
|
||||
cid=1
|
||||
)
|
||||
|
||||
url = reverse("physics:exam_scores_all", kwargs={"pk": exam.pk})
|
||||
response = client.get(f"{url}?stats_only=true")
|
||||
assert response.status_code == 200
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_sbas_stats_only_no_attribute_error(client, logged_in_admin):
|
||||
from sbas.models import Exam, Question, UserAnswer
|
||||
exam = Exam.objects.create(name="SBAs Test Exam", exam_mode=True)
|
||||
exam.author.add(logged_in_admin)
|
||||
|
||||
question = Question.objects.create(
|
||||
stem="stem",
|
||||
best_answer="A",
|
||||
)
|
||||
question.exams.add(exam)
|
||||
|
||||
UserAnswer.objects.create(
|
||||
question=question,
|
||||
exam=exam,
|
||||
answer="A",
|
||||
cid=1
|
||||
)
|
||||
|
||||
url = reverse("sbas:exam_scores_all", kwargs={"pk": exam.pk})
|
||||
response = client.get(f"{url}?stats_only=true")
|
||||
assert response.status_code == 200
|
||||
Reference in New Issue
Block a user