diff --git a/.travis.yml b/.travis.yml index 2e7f6e072..3750cf39d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ install: - "sh install_test_deps.sh" - "pip uninstall -y xblock-drag-and-drop-v2" - "python setup.py sdist" - - "pip install dist/xblock-drag-and-drop-v2-2.0.10.tar.gz" + - "pip install dist/xblock-drag-and-drop-v2-2.0.11.tar.gz" script: - pep8 drag_and_drop_v2 tests --max-line-length=120 - pylint drag_and_drop_v2 diff --git a/Changelog.md b/Changelog.md index 22360256b..4a1284775 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,8 @@ +Version 2.0.11 (2016-10-03) +--------------------------- + +* ([#106](https://github.com/edx-solutions/xblock-drag-and-drop-v2/pull/106)) Don't delete misplaced items on final attempt + Version 2.0.10 (2016-09-22) --------------------------- diff --git a/drag_and_drop_v2/drag_and_drop_v2.py b/drag_and_drop_v2/drag_and_drop_v2.py index ce99aea6a..45cf7676f 100644 --- a/drag_and_drop_v2/drag_and_drop_v2.py +++ b/drag_and_drop_v2/drag_and_drop_v2.py @@ -403,7 +403,9 @@ def do_attempt(self, data, suffix=''): misplaced_items = [] 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))) feedback_msgs = [FeedbackMessage(item['feedback']['incorrect'], None) for item in misplaced_items] diff --git a/setup.py b/setup.py index 16beb824d..4b0b39816 100644 --- a/setup.py +++ b/setup.py @@ -23,7 +23,7 @@ def package_data(pkg, root_list): setup( name='xblock-drag-and-drop-v2', - version='2.0.10', + version='2.0.11', description='XBlock - Drag-and-Drop v2', packages=['drag_and_drop_v2'], install_requires=[ diff --git a/tests/integration/test_interaction_assessment.py b/tests/integration/test_interaction_assessment.py index d8ed2b0bc..0268990b9 100644 --- a/tests/integration/test_interaction_assessment.py +++ b/tests/integration/test_interaction_assessment.py @@ -139,6 +139,36 @@ def test_misplaced_items_returned_to_bank(self): for item_id in misplaced_items: 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): """ Test "Submit" and "Reset" buttons are disabled when no more attempts remaining diff --git a/tests/unit/test_advanced.py b/tests/unit/test_advanced.py index 7d4ad64a7..1710ca0e1 100644 --- a/tests/unit/test_advanced.py +++ b/tests/unit/test_advanced.py @@ -404,6 +404,21 @@ def test_do_attempt_shows_final_feedback_at_last_attempt(self): expected_message = self._make_feedback_message(self.FINAL_FEEDBACK) 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): self._submit_complete_solution() original_item_state = self.block.item_state