diff --git a/common/test/acceptance/pages/lms/staff_view.py b/common/test/acceptance/pages/lms/staff_view.py index d16b5e3248..d5a9a88709 100644 --- a/common/test/acceptance/pages/lms/staff_view.py +++ b/common/test/acceptance/pages/lms/staff_view.py @@ -31,6 +31,13 @@ class StaffPage(PageObject): staff_debug_page.wait_for_page() return staff_debug_page + def answer_problem(self): + """ + Answers the problem to give state that we can clean + """ + self.q(css='input.check').first.click() + self.wait_for_ajax() + class StaffDebugPage(PageObject): """ @@ -43,6 +50,9 @@ class StaffDebugPage(PageObject): return self.q(css='section.staff-modal').present def _click_link(self, link_text): + """ + Clicks on an action link based on text + """ for link in self.q(css='section.staff-modal a').execute(): if link.text == link_text: return link.click() @@ -50,8 +60,22 @@ class StaffDebugPage(PageObject): raise Exception('Could not find the {} link to click on.'.format( link_text)) - def reset_attempts(self): - self._click_link('Reset Attempts') + def reset_attempts(self, user=None): + """ + This clicks on the reset attempts link with an optionally + specified user. + """ + if user: + self.q(css='input[id^=sd_fu_]').first.fill(user) + self._click_link('Reset Student Attempts') + + def delete_state(self, user=None): + """ + This delete's a student's state for the problem + """ + if user: + self.q(css='input[id^=sd_fu_]').fill(user) + self._click_link('Delete Student State') @property def idash_msg(self): diff --git a/common/test/acceptance/tests/test_staff_view.py b/common/test/acceptance/tests/test_staff_view.py index 64dd052b94..a202441710 100644 --- a/common/test/acceptance/tests/test_staff_view.py +++ b/common/test/acceptance/tests/test_staff_view.py @@ -15,6 +15,7 @@ class StaffDebugTest(UniqueCourseTest): """ Tests that verify the staff debug info. """ + USERNAME = "STAFF_TESTER" def setUp(self): super(StaffDebugTest, self).setUp() @@ -48,14 +49,62 @@ class StaffDebugTest(UniqueCourseTest): # Auto-auth register for the course. # Do this as global staff so that you will see the Staff View - AutoAuthPage(self.browser, course_id=self.course_id, staff=True).visit() + AutoAuthPage(self.browser, username=self.USERNAME, + course_id=self.course_id, staff=True).visit() - def test_staff_debug(self): + def _goto_staff_page(self): + """ + Open staff page with assertion + """ self.courseware_page.visit() staff_page = StaffPage(self.browser) self.assertEqual(staff_page.staff_status, 'Staff view') + return staff_page + + def test_reset_attempts_empty(self): + """ + Test that we fail properly when there is no student state + """ + + staff_debug_page = self._goto_staff_page().open_staff_debug_info() + staff_debug_page.reset_attempts() + msg = staff_debug_page.idash_msg[0] + self.assertIn((u"Found a single student. Found module. Couldn't " + "reset module state for {0}/").format(self.USERNAME), + msg) + + def test_delete_state_empty(self): + """ + Test that we delete properly even when there isn't state to delete. + """ + staff_debug_page = self._goto_staff_page().open_staff_debug_info() + staff_debug_page.delete_state() + msg = staff_debug_page.idash_msg[0] + self.assertIn((u"Found a single student. Found module. " + "Deleted student module state for"), msg) + + def test_reset_attempts_state(self): + """ + Successfully reset the student attempts + """ + staff_page = self._goto_staff_page() + staff_page.answer_problem() + staff_debug_page = staff_page.open_staff_debug_info() staff_debug_page.reset_attempts() + msg = staff_debug_page.idash_msg[0] + self.assertIn((u"Found a single student. Found module. Module " + "state successfully reset!"), msg) - msg = staff_debug_page.idash_msg - self.assertEqual('foo', msg) # Not sure what is supposed to happen + def test_student_state_state(self): + """ + Successfully delete the student state with an answer + """ + staff_page = self._goto_staff_page() + staff_page.answer_problem() + + staff_debug_page = staff_page.open_staff_debug_info() + staff_debug_page.delete_state() + msg = staff_debug_page.idash_msg[0] + self.assertIn((u"Found a single student. Found module. " + "Deleted student module state for"), msg) diff --git a/lms/templates/staff_problem_info.html b/lms/templates/staff_problem_info.html index 0f7bad3664..d855359ac3 100644 --- a/lms/templates/staff_problem_info.html +++ b/lms/templates/staff_problem_info.html @@ -82,7 +82,10 @@ var StaffDebug = (function(){ data: pdata, success: function(data){ var msg = $("#idash_msg", data); - $( "#result_"+locname ).html( msg ); + $("#result_" + locname).html( msg ); + }, + error: function(request, status, error) { + $("#result_" + locname).html('
${_('Something has gone wrong with this request. The server replied with a status of: ')}' + error + '
') }, dataType: 'html' }); @@ -96,25 +99,24 @@ var StaffDebug = (function(){ do_idash_action(locname, "Delete student state for module"); } - reload = function(locname){ - var url = geturl('jump_to_id/' + locname); - window.location.replace(url); - } - return {reset: reset, - reload: reload, sdelete: sdelete, do_idash_action: do_idash_action } })(); - - [ ${_('Reset Attempts')} | - ${_('Reload Page')} | - ${_('Delete State')} +