Basic anatomy user integration testing
This commit is contained in:
@@ -19,7 +19,7 @@ from physics.views import GenericExamViews as PhysicsExamViews
|
||||
from physics.models import Category, CidUserAnswer, Exam, Question
|
||||
|
||||
from generic.models import CidUser, CidUserGroup, UserUserGroup
|
||||
from rad.test_helpers import AssertNotFound
|
||||
from rad.test_helpers import AssertNotFound, create_cid_user_and_groups
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
@@ -29,23 +29,6 @@ APP_NAME = "physics"
|
||||
|
||||
|
||||
|
||||
def create_cid_user_and_groups(db):
|
||||
group1 = CidUserGroup.objects.create(name="Group1")
|
||||
group2 = CidUserGroup.objects.create(name="Group2")
|
||||
|
||||
cid_user_1000 = CidUser.objects.create(cid=1000, passcode="ABCD", group=group1)
|
||||
cid_user_1001 = CidUser.objects.create(cid=1001, passcode="EFGH", group=group1)
|
||||
cid_user_2001 = CidUser.objects.create(cid=2001, passcode="EFGH", group=group2)
|
||||
|
||||
assert cid_user_1000.cid == 1000
|
||||
assert cid_user_1001.cid == 1001
|
||||
|
||||
# Create UserUsers
|
||||
user1 = User.objects.create_user(username="user1", email="test@email.com", password="test1234")
|
||||
|
||||
usergroup1 = UserUserGroup.objects.create(name="Group1")
|
||||
usergroup1.users.add(user1)
|
||||
usergroup2 = UserUserGroup.objects.create(name="Group2")
|
||||
|
||||
|
||||
def create_exam(db):
|
||||
@@ -122,7 +105,7 @@ def test_exams(db, client):
|
||||
|
||||
create_category(db)
|
||||
|
||||
questions = [create_question(exam), create_question(exam), create_question(exam)]
|
||||
generated_questions = [create_question(exam), create_question(exam), create_question(exam)]
|
||||
|
||||
active_exams = client.get(reverse(f"{APP_NAME}:active_exams"))
|
||||
assert active_exams.status_code == 200
|
||||
@@ -150,7 +133,6 @@ def test_exams(db, client):
|
||||
exam.active = True
|
||||
exam.publish_results = False
|
||||
exam.save()
|
||||
# Test active exams sections works as intended
|
||||
start_page_res = client.get(
|
||||
reverse(f"physics:exam_start", kwargs={"pk": exam.pk})
|
||||
)
|
||||
@@ -161,7 +143,7 @@ def test_exams(db, client):
|
||||
else:
|
||||
assert "Start Exam" in str(start_page_soup)
|
||||
|
||||
for n, question in enumerate(questions):
|
||||
for n, question in enumerate(generated_questions):
|
||||
if testing_cid_user:
|
||||
take_url = reverse(
|
||||
f"physics:exam_take",
|
||||
@@ -203,7 +185,7 @@ def test_exams(db, client):
|
||||
# Check that relevant buttons are being displayed
|
||||
assert cid_take_soup.find("button", {"name": "finish"}) is not None
|
||||
|
||||
if n < len(questions) - 1:
|
||||
if n < len(generated_questions) - 1:
|
||||
assert cid_take_soup.find("button", {"name": "next"}) is not None
|
||||
|
||||
if n > 0:
|
||||
@@ -213,7 +195,7 @@ def test_exams(db, client):
|
||||
n + 1
|
||||
) # + 1 for 0 offset
|
||||
assert cid_take_soup.find("span", {"id": "exam-length"}).string == str(
|
||||
len(questions)
|
||||
len(generated_questions)
|
||||
)
|
||||
|
||||
# Check that stem text is displayed
|
||||
@@ -276,8 +258,8 @@ def test_exams(db, client):
|
||||
|
||||
# Loop through questions again to test submissions
|
||||
# All physics questions have 5 parts (and require a csrf token)
|
||||
questions_len = len(questions) - 1
|
||||
for n, question in enumerate(questions):
|
||||
questions_len = len(generated_questions) - 1
|
||||
for n, question in enumerate(generated_questions):
|
||||
if testing_cid_user:
|
||||
question_url = reverse(
|
||||
f"physics:exam_take",
|
||||
@@ -388,8 +370,8 @@ def test_exams(db, client):
|
||||
== 0
|
||||
)
|
||||
|
||||
# Get overview scores page (invalid passcode)
|
||||
if testing_cid_user:
|
||||
# Get overview scores page (invalid passcode)
|
||||
AssertNotFound(client,
|
||||
reverse(f"cid_scores", kwargs={"cid": cid_user.cid, "passcode": "AAAA"})
|
||||
)
|
||||
@@ -468,12 +450,12 @@ def test_exams(db, client):
|
||||
|
||||
# Check that we are showing enough questions / answers
|
||||
answer_lis = cid_exam_scores_soup.find_all("li", {"class": "question-part"})
|
||||
assert len(answer_lis) == 5 * len(questions)
|
||||
assert len(answer_lis) == 5 * len(generated_questions)
|
||||
|
||||
submitted_answers = cid_exam_scores_soup.find_all(
|
||||
"span", {"class": "submitted-user-answer"}
|
||||
)
|
||||
assert len(submitted_answers) == 5 * len(questions)
|
||||
assert len(submitted_answers) == 5 * len(generated_questions)
|
||||
|
||||
for ans in submitted_answers:
|
||||
assert ans.text.strip() == "True"
|
||||
@@ -483,7 +465,7 @@ def test_exams(db, client):
|
||||
|
||||
# Add another question to the exam
|
||||
extra_question = create_question(exam)
|
||||
questions.append(extra_question)
|
||||
generated_questions.append(extra_question)
|
||||
|
||||
# Load the exam results page (again)
|
||||
cid_exam_scores_res = client.get(
|
||||
@@ -492,12 +474,12 @@ def test_exams(db, client):
|
||||
cid_exam_scores_soup = BeautifulSoup(cid_exam_scores_res.content, "html.parser")
|
||||
|
||||
answer_lis = cid_exam_scores_soup.find_all("li", {"class": "question-part"})
|
||||
assert len(answer_lis) == 5 * len(questions)
|
||||
assert len(answer_lis) == 5 * len(generated_questions)
|
||||
|
||||
submitted_answers = cid_exam_scores_soup.find_all(
|
||||
"span", {"class": "submitted-user-answer"}
|
||||
)
|
||||
assert len(submitted_answers) == 5 * len(questions)
|
||||
assert len(submitted_answers) == 5 * len(generated_questions)
|
||||
|
||||
for ans in submitted_answers[:-5]:
|
||||
assert ans.text.strip() == "True"
|
||||
@@ -524,10 +506,10 @@ def test_exams(db, client):
|
||||
correct_answers = cid_exam_scores_soup.find_all(
|
||||
"span", {"class": "correct-answer"}
|
||||
)
|
||||
assert len(correct_answers) == 5 * len(questions)
|
||||
assert len(correct_answers) == 5 * len(generated_questions)
|
||||
|
||||
n = 0
|
||||
for question in questions:
|
||||
for question in generated_questions:
|
||||
for ans in question.get_answers():
|
||||
assert correct_answers[n].text.strip() == f"Correct answer: {ans}"
|
||||
n = n + 1
|
||||
@@ -535,7 +517,7 @@ def test_exams(db, client):
|
||||
submitted_answers = cid_exam_scores_soup.find_all(
|
||||
"span", {"class": "submitted-user-answer"}
|
||||
)
|
||||
assert len(submitted_answers) == 5 * len(questions)
|
||||
assert len(submitted_answers) == 5 * len(generated_questions)
|
||||
|
||||
for ans in submitted_answers[:-5]:
|
||||
assert ans.text.strip() == "True"
|
||||
@@ -613,5 +595,5 @@ def test_exams(db, client):
|
||||
cid_take_soup = BeautifulSoup(cid_take_res.content, "html.parser")
|
||||
assert "Exam is currently inactive" in cid_take_soup.text
|
||||
|
||||
questions.pop(-1).delete()
|
||||
generated_questions.pop(-1).delete()
|
||||
users_tested = users_tested + 1
|
||||
@@ -102,6 +102,9 @@ def active_exams(request):
|
||||
def exam_scores_cid_user(request, pk, cid=None, passcode=None):
|
||||
exam = get_object_or_404(Exam, pk=pk)
|
||||
|
||||
if not exam.exam_mode:
|
||||
raise Http404("Packet not in exam mode")
|
||||
|
||||
if cid is not None and not exam.check_cid_user(cid, passcode, request):
|
||||
raise Http404("Error accessing exam")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user