Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
def test_answers_naming_error(self):
markdown = INLINE_MULTI_MARKDOWN_ANSWERS_NAMING_ERROR
resp = self.get_page_sandbox_preview_response(markdown)
self.assertEqual(resp.status_code, 200)
self.assertSandboxNotHasValidPage(resp)
self.assertResponseContextContains(
resp, PAGE_ERRORS,
"invalid answers name '2choice'. A valid name should start "
"with letters. Alphanumeric with underscores. Do not use "
"spaces.")
def test_embedded_naming_duplicated(self):
markdown = INLINE_MULTI_MARKDOWN_EMBEDDED_NAMING_DUPLICATED
resp = self.get_page_sandbox_preview_response(markdown)
self.assertEqual(resp.status_code, 200)
self.assertSandboxNotHasValidPage(resp)
self.assertResponseContextContains(
resp, PAGE_ERRORS,
"embedded question name 'blank1', 'choice1' not unique.")
def test_has_unpaired_wrapper(self):
markdown = INLINE_MULTI_MARKDOWN_HAS_UNPAIRED_WRAPPER
resp = self.get_page_sandbox_preview_response(markdown)
self.assertEqual(resp.status_code, 200)
self.assertSandboxNotHasValidPage(resp)
self.assertResponseContextContains(
resp, PAGE_ERRORS,
"question has unpaired '[['.")
def test_redundant(self):
markdown = INLINE_MULTI_MARKDOWN_REDUNDANT
resp = self.get_page_sandbox_preview_response(markdown)
self.assertEqual(resp.status_code, 200)
self.assertSandboxHasValidPage(resp)
self.assertSandboxWarningTextContain(
resp,
"redundant answers 'blank_2' provided for non-existing "
"question(s).")
resp = self.get_page_sandbox_submit_answer_response(
markdown,
self.assertEqual(resp.status_code, 200)
self.assertContains(resp, "This is an explanation.")
self.assertResponseContextAnswerFeedbackCorrectnessEquals(resp, 1)
def test_embedded_question_with_markdown(self):
commit_sha = "b3cca1b997b24f526196a11c7e34098313a8950b"
commit_sha=commit_sha.encode())
markdown = INLINE_MULTI_EMBEDDED_WITH_MARKDOWN
resp = self.get_page_sandbox_preview_response(markdown)
self.assertEqual(resp.status_code, 200)
self.assertSandboxHasValidPage(resp)
self.assertContains(
resp, f'<img src="/course/test-course/media/{commit_sha}'
'/images/classroom.jpeg">', html=True)
class InlineMultiPageUpdateTest(SingleCourseQuizPageTestMixin, TestCase):
page_id = "inlinemulti"
def test_quiz_inline_not_show_correctness(self):
self.start_flow(self.flow_id)
with mock.patch("course.flow.get_page_behavior") as mock_get_bhv:
mock_get_bhv.side_effect = (
get_page_behavior_not_show_correctness_side_effect)
submit_answer_response, _ = (
self.submit_page_answer_by_page_id_and_test(
self.page_id, do_grading=False))
self.assertEqual(submit_answer_response.status_code, 200)
self.assertContains(submit_answer_response, 'correctness="1"', count=0)
self.assertContains(submit_answer_response, 'correctness="0"', count=0)
self.end_flow()
self.assertSessionScoreEqual(10)
# {{{ Test bug fix in https://github.com/inducer/relate/pull/262
def test_add_new_question(self):
"""Test bug fix in https://github.com/inducer/relate/pull/262
"""
with mock.patch("course.content.get_repo_blob") as mock_get_repo_blob:
mock_get_repo_blob.side_effect = get_repo_blob_side_effect
self.post_update_course_content(
commit_sha=b"ec41a2de73a99e6022060518cb5c5c162b88cdf5")
self.start_flow(self.flow_id)
resp = self.client.get(
self.assertEqual(resp.status_code, 200)
self.assertContains(resp, "(old version)")
answer_data = {
"blank1": "Bar", "blank_2": "0.2", "blank3": "1",
"blank4": "5", "choice2": "0", "choice_a": "0"}
submit_answer_response, _ = (
self.submit_page_answer_by_page_id_and_test(
self.page_id, answer_data=answer_data, expected_grades=10))
self.assertContains(submit_answer_response,
'correctness="1"', count=6)
self.post_update_course_content(
commit_sha=b"4124e0c23e369d6709a670398167cb9c2fe52d35")
resp = self.client.get(
self.assertEqual(resp.status_code, 200)
# 7 answer
self.assertContains(resp, 'correctness="1"', count=7)