diff --git a/problem_builder/mentoring.py b/problem_builder/mentoring.py index 06e9a616..45184db6 100644 --- a/problem_builder/mentoring.py +++ b/problem_builder/mentoring.py @@ -281,6 +281,11 @@ def student_view(self, context): # Migrate stored data if necessary self.migrate_fields() + # Validate self.step: + num_steps = len(self.steps) + if self.step > num_steps: + self.step = num_steps + fragment = Fragment() child_content = u"" diff --git a/problem_builder/tests/integration/base_test.py b/problem_builder/tests/integration/base_test.py index 059af9c9..29f45f48 100644 --- a/problem_builder/tests/integration/base_test.py +++ b/problem_builder/tests/integration/base_test.py @@ -149,6 +149,19 @@ def expect_question_visible(self, number, mentoring): self.assertIsNotNone(question_div) return question_div + def answer_mcq(self, number, name, value, mentoring, controls, is_last=False): + self.expect_question_visible(number, mentoring) + + mentoring.find_element_by_css_selector('input[name={}][value={}]'.format(name, value)).click() + controls.submit.click() + if is_last: + self.wait_until_clickable(controls.review) + controls.review.click() + self.wait_until_hidden(controls.review) + else: + self.wait_until_clickable(controls.next_question) + controls.next_question.click() + class GetChoices(object): """ Helper class for interacting with MCQ options """ diff --git a/problem_builder/tests/integration/test_author_changes.py b/problem_builder/tests/integration/test_author_changes.py index 85601630..be4e116d 100644 --- a/problem_builder/tests/integration/test_author_changes.py +++ b/problem_builder/tests/integration/test_author_changes.py @@ -2,7 +2,7 @@ If an author makes changes to the block after students have started using it, will bad things happen? """ -from .base_test import ProblemBuilderBaseTest +from .base_test import ProblemBuilderBaseTest, MentoringAssessmentBaseTest import re @@ -12,7 +12,7 @@ class AuthorChangesTest(ProblemBuilderBaseTest): """ def setUp(self): super(AuthorChangesTest, self).setUp() - self.load_scenario("author_changes.xml", load_immediately=False) + self.load_scenario("author_changes.xml", {"mode": "standard"}, load_immediately=False) self.refresh_page() def refresh_page(self): @@ -75,3 +75,44 @@ def test_reweight_question(self): # Now, the student's score should be 1 out of 6 (only q3 is correct): self.assertEqual(self.pb_block.score.percentage, 17) + + +class AuthorChangesAssessmentTest(MentoringAssessmentBaseTest): + """ + Test various scenarios involving author changes made to an assessment block already in use + """ + def test_delete_question(self): + """ Test that the assessment behaves correctly when deleting a question. """ + pb_block_dom, controls = self.load_assessment_scenario("author_changes.xml", {"mode": "assessment"}) + + # Answer each question, getting the first question wrong: + mentoring = pb_block_dom.find_element_by_css_selector(".mentoring") + self.answer_mcq(number=1, name="q1", value="no", mentoring=mentoring, controls=controls, is_last=False) + self.answer_mcq(number=2, name="q2", value="elegance", mentoring=mentoring, controls=controls, is_last=False) + + pb_block_dom.find_element_by_css_selector('textarea').send_keys("Hello world") + controls.submit.click() + self.wait_until_clickable(controls.review) + controls.review.click() + self.wait_until_hidden(controls.review) + + # Delete question 3: + vertical = self.load_root_xblock() + pb_block = vertical.runtime.get_block(vertical.children[0]) + self.assertEqual(pb_block.score.percentage, 67) + pb_block.children = [pb_block.children[0], pb_block.children[1]] + pb_block.save() + pb_block_dom, controls = self.go_to_assessment() + + self.assertIn("You scored 50% on this assessment.", pb_block_dom.text) + self.assertIn("You answered 1 question correctly.", pb_block_dom.text) + self.assertIn("You answered 1 question incorrectly.", pb_block_dom.text) + + controls.try_again.click() + self.wait_until_hidden(controls.try_again) + + # Now answer again, getting a perfect score: + mentoring = pb_block_dom.find_element_by_css_selector(".mentoring") + self.answer_mcq(number=1, name="q1", value="yes", mentoring=mentoring, controls=controls, is_last=False) + self.answer_mcq(number=2, name="q2", value="elegance", mentoring=mentoring, controls=controls, is_last=True) + self.assertIn("You scored 100% on this assessment.", mentoring.text) diff --git a/problem_builder/tests/integration/xml_templates/author_changes.xml b/problem_builder/tests/integration/xml_templates/author_changes.xml index 86b62409..95096049 100644 --- a/problem_builder/tests/integration/xml_templates/author_changes.xml +++ b/problem_builder/tests/integration/xml_templates/author_changes.xml @@ -1,5 +1,5 @@ - + Yes