Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions problem_builder/mentoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -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""

Expand Down
13 changes: 13 additions & 0 deletions problem_builder/tests/integration/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 """
Expand Down
45 changes: 43 additions & 2 deletions problem_builder/tests/integration/test_author_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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):
Expand Down Expand Up @@ -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)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<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>
Expand Down