Commit 8c2b62de by Adolfo R. Brandes

Don't delete misplaced items on final attempt

In assessment mode, don't delete misplaced items from the user's state
when handling the final attempt.

This is a server-side change to match what Javascript already does: upon
submitting the final attempt, misplaced items are left on the board.
However, since the corresponding state was deleted server-side, upon
refreshing the page items were returned to the bank.
parent 45b0e1a6
...@@ -403,7 +403,9 @@ class DragAndDropBlock(XBlock, XBlockWithSettingsMixin, ThemableXBlockMixin): ...@@ -403,7 +403,9 @@ class DragAndDropBlock(XBlock, XBlockWithSettingsMixin, ThemableXBlockMixin):
misplaced_items = [] misplaced_items = []
for item_id in misplaced_ids: for item_id in misplaced_ids:
del self.item_state[item_id] # Don't delete misplaced item states on the final attempt.
if self.attempts_remain:
del self.item_state[item_id]
misplaced_items.append(self._get_item_definition(int(item_id))) misplaced_items.append(self._get_item_definition(int(item_id)))
feedback_msgs = [FeedbackMessage(item['feedback']['incorrect'], None) for item in misplaced_items] feedback_msgs = [FeedbackMessage(item['feedback']['incorrect'], None) for item in misplaced_items]
......
...@@ -139,6 +139,36 @@ class AssessmentInteractionTest( ...@@ -139,6 +139,36 @@ class AssessmentInteractionTest(
for item_id in misplaced_items: for item_id in misplaced_items:
self.assert_reverted_item(item_id) self.assert_reverted_item(item_id)
def test_misplaced_items_not_returned_to_bank_on_final_attempt(self):
"""
Test items placed on incorrect zones are not returned to item bank
after submitting solution on the final attempt, and remain placed after
subsequently refreshing the page.
"""
self.place_item(0, TOP_ZONE_ID, action_key=Keys.RETURN)
# Reach final attempt
for _ in xrange(self.MAX_ATTEMPTS-1):
self.click_submit()
# Place incorrect item on final attempt
self.place_item(1, TOP_ZONE_ID, action_key=Keys.RETURN)
self.click_submit()
# Incorrect item remains placed
def _assert_placed(item_id, zone_title):
item = self._get_placed_item_by_value(item_id)
item_description = item.find_element_by_css_selector('.sr')
self.assertEqual(item_description.text, 'Placed in: {}'.format(zone_title))
_assert_placed(1, TOP_ZONE_TITLE)
# Refresh the page
self._page = self.go_to_page(self.PAGE_TITLE)
# Incorrect item remains placed after refresh
_assert_placed(1, TOP_ZONE_TITLE)
def test_max_attempts_reached_submit_and_reset_disabled(self): def test_max_attempts_reached_submit_and_reset_disabled(self):
""" """
Test "Submit" and "Reset" buttons are disabled when no more attempts remaining Test "Submit" and "Reset" buttons are disabled when no more attempts remaining
......
...@@ -404,6 +404,21 @@ class AssessmentModeFixture(BaseDragAndDropAjaxFixture): ...@@ -404,6 +404,21 @@ class AssessmentModeFixture(BaseDragAndDropAjaxFixture):
expected_message = self._make_feedback_message(self.FINAL_FEEDBACK) expected_message = self._make_feedback_message(self.FINAL_FEEDBACK)
self.assertIn(expected_message, res[self.OVERALL_FEEDBACK_KEY]) self.assertIn(expected_message, res[self.OVERALL_FEEDBACK_KEY])
def test_do_attempt_does_not_delete_misplaced_items_at_last_attempt(self):
"""
Upon submitting the final attempt, test that misplaced items are not
deleted from the item state.
"""
self._set_final_attempt()
misplaced_ids = self._submit_incorrect_solution()
self.call_handler(self.DO_ATTEMPT_HANDLER, data={})
self.assertFalse(self.block.attempts_remain) # precondition check
for i in misplaced_ids:
self.assertIn(str(i), self.block.item_state.keys())
def test_get_user_state_does_not_include_correctness(self): def test_get_user_state_does_not_include_correctness(self):
self._submit_complete_solution() self._submit_complete_solution()
original_item_state = self.block.item_state original_item_state = self.block.item_state
......
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