refactor: rework scores pages for improved usability and performance
This commit is contained in:
+50
-21
@@ -188,6 +188,7 @@ class ExamTester:
|
||||
|
||||
cid_take_soup = BeautifulSoup(cid_take_res.content, "html.parser")
|
||||
|
||||
|
||||
# Check correct user is displayed
|
||||
if self.testing_cid_user:
|
||||
display_user = str(self.current_user.cid)
|
||||
@@ -198,58 +199,86 @@ class ExamTester:
|
||||
# Check review mode alert not visible
|
||||
assert cid_take_soup.find("div", {"class": "review-mode-alert"}) is None
|
||||
|
||||
# Check that relevant buttons are being displayed
|
||||
assert cid_take_soup.find("button", {"name": "finish"}) is not None
|
||||
# The main take page loads the question controls via HTMX/JS into
|
||||
# the fragment URL. Request that fragment and run button/answer
|
||||
# checks against it (server-rendered), not the main page which is
|
||||
# just a container.
|
||||
if self.testing_cid_user:
|
||||
frag_url = reverse(
|
||||
f"{self.app_name}:exam_take_fragment",
|
||||
kwargs={
|
||||
"pk": self.exam.pk,
|
||||
"sk": n,
|
||||
"cid": self.current_user.cid,
|
||||
"passcode": self.current_user.passcode,
|
||||
},
|
||||
)
|
||||
else:
|
||||
frag_url = reverse(
|
||||
f"{self.app_name}:exam_take_fragment_user",
|
||||
kwargs={
|
||||
"pk": self.exam.pk,
|
||||
"sk": n,
|
||||
},
|
||||
)
|
||||
|
||||
frag_res = self.client.get(frag_url)
|
||||
|
||||
# If the user is invalid they may not be able to load the fragment
|
||||
if self.current_user in self.invalid_users:
|
||||
assert frag_res.status_code == HTTPStatus.NOT_FOUND
|
||||
continue
|
||||
else:
|
||||
assert frag_res.status_code == HTTPStatus.OK
|
||||
|
||||
frag_soup = BeautifulSoup(frag_res.content, "html.parser")
|
||||
|
||||
# Check that relevant buttons are being displayed in the fragment
|
||||
assert frag_soup.find("button", {"name": "finish"}) is not None
|
||||
|
||||
if n < len(self.generated_questions) - 1:
|
||||
assert cid_take_soup.find("button", {"name": "next"}) is not None
|
||||
assert frag_soup.find("button", {"name": "next"}) is not None
|
||||
|
||||
if n > 0:
|
||||
assert cid_take_soup.find("button", {"name": "previous"}) is not None
|
||||
assert frag_soup.find("button", {"name": "previous"}) is not None
|
||||
|
||||
assert cid_take_soup.find("span", {"id": "question-number"}).string == str(
|
||||
n + 1
|
||||
) # + 1 for 0 offset
|
||||
assert cid_take_soup.find("span", {"id": "exam-length"}).string == str(
|
||||
len(self.generated_questions)
|
||||
)
|
||||
|
||||
# Check that stem text is displayed
|
||||
# Check that stem text is displayed (main page header is also kept in
|
||||
# sync by fragment JS, but verify here that fragment contains stem)
|
||||
assert (
|
||||
cid_take_soup.find("span", {"id": "question-stem"}).string
|
||||
frag_soup.find("div", {"class": "question-stem-fragment"}).string.strip()
|
||||
== question.stem
|
||||
)
|
||||
|
||||
match self.app_name:
|
||||
case "physics":
|
||||
assert (
|
||||
cid_take_soup.find("label", {"for": "id_a"}).string
|
||||
frag_soup.find("label", {"for": "id_a"}).string
|
||||
== question.a
|
||||
)
|
||||
assert (
|
||||
cid_take_soup.find("label", {"for": "id_b"}).string
|
||||
frag_soup.find("label", {"for": "id_b"}).string
|
||||
== question.b
|
||||
)
|
||||
assert (
|
||||
cid_take_soup.find("label", {"for": "id_c"}).string
|
||||
frag_soup.find("label", {"for": "id_c"}).string
|
||||
== question.c
|
||||
)
|
||||
assert (
|
||||
cid_take_soup.find("label", {"for": "id_d"}).string
|
||||
frag_soup.find("label", {"for": "id_d"}).string
|
||||
== question.d
|
||||
)
|
||||
assert (
|
||||
cid_take_soup.find("label", {"for": "id_e"}).string
|
||||
frag_soup.find("label", {"for": "id_e"}).string
|
||||
== question.e
|
||||
)
|
||||
case "sbas":
|
||||
assert (
|
||||
cid_take_soup.find("ul", {"class": "sba-answer-list"})
|
||||
frag_soup.find("ul", {"class": "sba-answer-list"})
|
||||
is not None
|
||||
)
|
||||
assert (
|
||||
len(
|
||||
cid_take_soup.find(
|
||||
frag_soup.find(
|
||||
"ul", {"class": "sba-answer-list"}
|
||||
).find_all("li")
|
||||
)
|
||||
@@ -258,7 +287,7 @@ class ExamTester:
|
||||
|
||||
# As we haven't submitted any answers they should all be blank
|
||||
assert (
|
||||
cid_take_soup.find("input", {"type": "checkbox", "checked": True})
|
||||
frag_soup.find("input", {"type": "checkbox", "checked": True})
|
||||
is None
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user