update sba testing (and fix others)
This commit is contained in:
+128
-54
@@ -11,6 +11,7 @@ from django.contrib.auth.models import User
|
||||
from django.urls import reverse
|
||||
from rich.pretty import pprint
|
||||
|
||||
|
||||
def AssertNotFound(client, url):
|
||||
"""Helper to quickly test for urls that should return a 404 (NOT FOUND) error"""
|
||||
response = client.get(url)
|
||||
@@ -74,9 +75,11 @@ class ExamTester:
|
||||
|
||||
cidgroup1: CidUserGroup = CidUserGroup.objects.get(name="Group1")
|
||||
|
||||
self.answers_per_question = 1
|
||||
match app_name:
|
||||
case "physics":
|
||||
assert exam in cidgroup1.physics_cid_user_groups.all()
|
||||
self.answers_per_question = 5
|
||||
case "sbas":
|
||||
assert exam in cidgroup1.sba_cid_user_groups.all()
|
||||
|
||||
@@ -123,7 +126,9 @@ class ExamTester:
|
||||
def check_active_exams(self, n):
|
||||
active_exams = self.client.get(reverse(f"{self.app_name}:active_exams"))
|
||||
assert active_exams.status_code == 200
|
||||
assert len(json.loads(active_exams.content)["exams"]) == n, f"Current user: {self.current_user}"
|
||||
assert (
|
||||
len(json.loads(active_exams.content)["exams"]) == n
|
||||
), f"Current user: {self.current_user}"
|
||||
|
||||
def check_onsite_start_page(self):
|
||||
start_page_res = self.client.get(
|
||||
@@ -169,7 +174,9 @@ class ExamTester:
|
||||
assert cid_take_res.status_code == HTTPStatus.NOT_FOUND
|
||||
continue
|
||||
else:
|
||||
assert cid_take_res.status_code == HTTPStatus.OK, f"Current user: {self.current_user}"
|
||||
assert (
|
||||
cid_take_res.status_code == HTTPStatus.OK
|
||||
), f"Current user: {self.current_user}"
|
||||
|
||||
cid_take_soup = BeautifulSoup(cid_take_res.content, "html.parser")
|
||||
|
||||
@@ -207,14 +214,39 @@ class ExamTester:
|
||||
|
||||
match self.app_name:
|
||||
case "physics":
|
||||
assert cid_take_soup.find("label", {"for": "id_a"}).string == question.a
|
||||
assert cid_take_soup.find("label", {"for": "id_b"}).string == question.b
|
||||
assert cid_take_soup.find("label", {"for": "id_c"}).string == question.c
|
||||
assert cid_take_soup.find("label", {"for": "id_d"}).string == question.d
|
||||
assert cid_take_soup.find("label", {"for": "id_e"}).string == question.e
|
||||
assert (
|
||||
cid_take_soup.find("label", {"for": "id_a"}).string
|
||||
== question.a
|
||||
)
|
||||
assert (
|
||||
cid_take_soup.find("label", {"for": "id_b"}).string
|
||||
== question.b
|
||||
)
|
||||
assert (
|
||||
cid_take_soup.find("label", {"for": "id_c"}).string
|
||||
== question.c
|
||||
)
|
||||
assert (
|
||||
cid_take_soup.find("label", {"for": "id_d"}).string
|
||||
== question.d
|
||||
)
|
||||
assert (
|
||||
cid_take_soup.find("label", {"for": "id_e"}).string
|
||||
== question.e
|
||||
)
|
||||
case "sbas":
|
||||
assert cid_take_soup.find("ul", {"class": "sba-answer-list"}) is not None
|
||||
assert len(cid_take_soup.find("ul", {"class": "sba-answer-list"}).find_all("li")) == 5
|
||||
assert (
|
||||
cid_take_soup.find("ul", {"class": "sba-answer-list"})
|
||||
is not None
|
||||
)
|
||||
assert (
|
||||
len(
|
||||
cid_take_soup.find(
|
||||
"ul", {"class": "sba-answer-list"}
|
||||
).find_all("li")
|
||||
)
|
||||
== 5
|
||||
)
|
||||
|
||||
# As we haven't submitted any answers they should all be blank
|
||||
assert (
|
||||
@@ -396,18 +428,21 @@ class ExamTester:
|
||||
# Check that we are showing enough questions / answers
|
||||
match self.app_name:
|
||||
case "physics":
|
||||
answer_lis = cid_exam_scores_soup.find_all("li", {"class": "question-part"})
|
||||
answer_lis = cid_exam_scores_soup.find_all(
|
||||
"li", {"class": "question-part"}
|
||||
)
|
||||
assert len(answer_lis) == 5 * len(self.generated_questions)
|
||||
assert len(submitted_answers) == 5 * len(self.generated_questions)
|
||||
for ans in submitted_answers:
|
||||
assert ans.text.strip() == "True"
|
||||
|
||||
case "sbas":
|
||||
answer_lis = cid_exam_scores_soup.find_all("li", {"class": "user-answer-li"})
|
||||
answer_lis = cid_exam_scores_soup.find_all(
|
||||
"li", {"class": "user-answer-li"}
|
||||
)
|
||||
assert len(answer_lis) == len(self.generated_questions)
|
||||
assert len(submitted_answers) == len(self.generated_questions)
|
||||
|
||||
|
||||
for ans in submitted_answers:
|
||||
assert ans.text.strip() == "a"
|
||||
|
||||
@@ -426,7 +461,9 @@ class ExamTester:
|
||||
)
|
||||
match self.app_name:
|
||||
case "physics":
|
||||
answer_lis = cid_exam_scores_soup.find_all("li", {"class": "question-part"})
|
||||
answer_lis = cid_exam_scores_soup.find_all(
|
||||
"li", {"class": "question-part"}
|
||||
)
|
||||
assert len(answer_lis) == 5 * len(self.generated_questions)
|
||||
assert len(submitted_answers) == 5 * len(self.generated_questions)
|
||||
|
||||
@@ -435,10 +472,12 @@ class ExamTester:
|
||||
|
||||
# The new question will not have any answers
|
||||
for ans in submitted_answers[-5:]:
|
||||
assert ans.text.strip() == ""
|
||||
assert ans.text.strip() == "Not answered"
|
||||
|
||||
case "sbas":
|
||||
answer_lis = cid_exam_scores_soup.find_all("li", {"class": "user-answer-li"})
|
||||
answer_lis = cid_exam_scores_soup.find_all(
|
||||
"li", {"class": "user-answer-li"}
|
||||
)
|
||||
assert len(answer_lis) == len(self.generated_questions)
|
||||
assert len(submitted_answers) == len(self.generated_questions)
|
||||
|
||||
@@ -451,9 +490,7 @@ class ExamTester:
|
||||
# The new question will not have any answers
|
||||
for ans in submitted_answers[3:]:
|
||||
print("test2", ans)
|
||||
assert ans.text.strip() == ""
|
||||
|
||||
|
||||
assert ans.text.strip() == "Not answered"
|
||||
|
||||
# Publish the results!
|
||||
self.exam.publish_results = True
|
||||
@@ -471,56 +508,92 @@ class ExamTester:
|
||||
correct_answers = cid_exam_scores_soup.find_all(
|
||||
"span", {"class": "correct-answer"}
|
||||
)
|
||||
assert len(correct_answers) == 5 * len(self.generated_questions)
|
||||
|
||||
assert len(correct_answers) == self.answers_per_question * len(
|
||||
self.generated_questions
|
||||
)
|
||||
|
||||
n = 0
|
||||
for question in self.generated_questions:
|
||||
for ans in question.get_answers():
|
||||
assert correct_answers[n].text.strip() == f"Correct answer: {ans}"
|
||||
n = n + 1
|
||||
for i, question in enumerate(self.generated_questions):
|
||||
match self.app_name:
|
||||
case "physics":
|
||||
for ans in question.get_answers():
|
||||
assert correct_answers[n].text.strip() == f"Correct answer: {ans}"
|
||||
n = n + 1
|
||||
case "sbas":
|
||||
ans = question.get_correct_answer()
|
||||
assert correct_answers[i].text.strip() == f"Correct answer: {ans}"
|
||||
|
||||
submitted_answers = cid_exam_scores_soup.find_all(
|
||||
"span", {"class": "submitted-user-answer"}
|
||||
)
|
||||
assert len(submitted_answers) == 5 * len(self.generated_questions)
|
||||
assert len(submitted_answers) == self.answers_per_question * len(
|
||||
self.generated_questions
|
||||
)
|
||||
|
||||
for ans in submitted_answers[:-5]:
|
||||
assert ans.text.strip() == "True"
|
||||
print(submitted_answers)
|
||||
|
||||
for ans in submitted_answers[:-self.answers_per_question]:
|
||||
print("------", ans.text.strip())
|
||||
match self.app_name:
|
||||
case "physics":
|
||||
assert ans.text.strip() == "True"
|
||||
case "sbas":
|
||||
assert ans.text.strip() == "a"
|
||||
|
||||
# The new question will not have any answers
|
||||
for ans in submitted_answers[-5:]:
|
||||
assert ans.text.strip() == ""
|
||||
|
||||
assert (
|
||||
cid_exam_scores_soup.find("div", {"class": "score-overview"})
|
||||
.find("span", {"id": "total-score"})
|
||||
.string
|
||||
== "9"
|
||||
)
|
||||
assert (
|
||||
cid_exam_scores_soup.find("div", {"class": "score-overview"})
|
||||
.find("span", {"id": "max-score"})
|
||||
.string
|
||||
== "20"
|
||||
)
|
||||
|
||||
for ans in submitted_answers[-self.answers_per_question:]:
|
||||
assert ans.text.strip() == "Not answered"
|
||||
|
||||
match self.app_name:
|
||||
case "physics":
|
||||
assert (
|
||||
cid_exam_scores_soup.find("div", {"class": "score-overview"})
|
||||
.find("span", {"id": "total-score"})
|
||||
.string
|
||||
== "9"
|
||||
)
|
||||
assert (
|
||||
cid_exam_scores_soup.find("div", {"class": "score-overview"})
|
||||
.find("span", {"id": "max-score"})
|
||||
.string
|
||||
== "20"
|
||||
)
|
||||
case "sbas":
|
||||
assert (
|
||||
cid_exam_scores_soup.find("div", {"class": "score-overview"})
|
||||
.find("span", {"id": "total-score"})
|
||||
.string
|
||||
== "3"
|
||||
)
|
||||
assert (
|
||||
cid_exam_scores_soup.find("div", {"class": "score-overview"})
|
||||
.find("span", {"id": "max-score"})
|
||||
.string
|
||||
== "4"
|
||||
)
|
||||
|
||||
def check_cid_scores_user_page2(self):
|
||||
|
||||
cid_exam_scores_res = self.client.get(self.exam_scores_url)
|
||||
|
||||
cid_exam_scores_soup = BeautifulSoup(cid_exam_scores_res.content, "html.parser")
|
||||
|
||||
|
||||
|
||||
# As we have answered correctly the new score should be increased by 5
|
||||
assert (
|
||||
cid_exam_scores_soup.find("div", {"class": "score-overview"})
|
||||
.find("span", {"id": "total-score"})
|
||||
.string
|
||||
== "14"
|
||||
), f"Current user: {self.current_user}"
|
||||
# As we have answered correctly the new score should be increased by 1 * answer_count
|
||||
match self.app_name:
|
||||
case "physics":
|
||||
assert (
|
||||
cid_exam_scores_soup.find("div", {"class": "score-overview"})
|
||||
.find("span", {"id": "total-score"})
|
||||
.string
|
||||
== "14"
|
||||
), f"Invalid answer count, Current user: {self.current_user}"
|
||||
case "sbas":
|
||||
assert (
|
||||
cid_exam_scores_soup.find("div", {"class": "score-overview"})
|
||||
.find("span", {"id": "total-score"})
|
||||
.string
|
||||
== "4"
|
||||
), f"Invalid answer count, Current user: {self.current_user}"
|
||||
|
||||
# Check what happens when exam is not active
|
||||
self.exam.active = False
|
||||
@@ -553,9 +626,10 @@ class ExamTester:
|
||||
)
|
||||
cid_take_res = self.client.get(cid_take_url)
|
||||
cid_take_soup = BeautifulSoup(cid_take_res.content, "html.parser")
|
||||
print(cid_take_soup.text)
|
||||
assert "Exam is currently inactive" in cid_take_soup.text
|
||||
|
||||
# Delete the last question, from both the list
|
||||
q= self.generated_questions.pop()
|
||||
q = self.generated_questions.pop()
|
||||
# and the database
|
||||
q.delete()
|
||||
q.delete()
|
||||
|
||||
Reference in New Issue
Block a user