Commit 74ae54ca by Braden MacDonald

Merge pull request #28 from open-craft/fix-author-changes-ii

Test + fix an additional failure case
parents ee363edf 4be1a4c8
......@@ -281,6 +281,11 @@ class MentoringBlock(XBlock, StepParentMixin, StudioEditableXBlockMixin, StudioC
# 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""
......
......@@ -149,6 +149,19 @@ class MentoringAssessmentBaseTest(ProblemBuilderBaseTest):
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 """
......
......@@ -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 @@ class AuthorChangesTest(ProblemBuilderBaseTest):
# 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)
<vertical_demo>
<problem-builder>
<problem-builder mode="{{mode}}">
<pb-mcq name="q1" type="choices" correct_choices='["yes"]' question="So, do you like this Q1?">
<pb-choice value="yes">Yes</pb-choice>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment