Newer
Older
resp = self.client.post(
self.get_regrade_flows_view_url(),
data={
"regraded_session_in_progress": "yes",
"flow_id": QUIZ_FLOW_ID,
"access_rules_tag": "",
}
)
self.assertEqual(resp.status_code, 200)
self.assertEqual(self.mock_regrade_task.call_count, 0)
self.assertEqual(self.mock_redirect.call_count, 0)
def test_success(self):
# get success
resp = self.client.get(self.get_regrade_flows_view_url())
self.assertEqual(resp.status_code, 200)
# post success
access_rules_tag = "some_tag"
flow_id = self.flow_id
inprog_value_map = {
"any": None,
"yes": True,
"no": False,
}
for regraded_session_in_progress, inprog_value in (
with self.subTest(
regraded_session_in_progress=regraded_session_in_progress):
self.mock_regrade_task.return_value = mock.MagicMock()
self.mock_redirect.return_value = http.HttpResponse()
resp = self.client.post(
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
self.get_regrade_flows_view_url(),
data={
"regraded_session_in_progress":
regraded_session_in_progress,
"flow_id": flow_id,
"access_rules_tag": access_rules_tag,
}
)
self.assertFormErrorLoose(resp, None)
self.assertEqual(self.mock_regrade_task.call_count, 1)
self.mock_regrade_task.assert_called_once_with(
self.course.id,
flow_id,
access_rules_tag,
inprog_value,
)
self.mock_regrade_task.reset_mock()
self.assertEqual(self.mock_redirect.call_count, 1)
self.assertIn(
"relate-monitor_task", self.mock_redirect.call_args[0])
self.mock_redirect.reset_mock()
class ViewUnsubmitFlowPageTest(SingleCourseQuizPageTestMixin, TestCase):
# test flow.view_unsubmit_flow_page
page_id = "half"
@classmethod
client = Client()
client.force_login(cls.student_participation.user)
cls.start_flow(client, cls.flow_id)
cls.submit_page_answer_by_page_id_and_test(client, page_id=cls.page_id)
self.client.force_login(self.instructor_participation.user)
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
fake_unsubmit_page = mock.patch(
"course.flow.unsubmit_page")
self.mock_unsubmit_page = fake_unsubmit_page.start()
self.addCleanup(fake_unsubmit_page.stop)
fake_add_message = mock.patch("course.flow.messages.add_message")
self.mock_add_message = fake_add_message.start()
self.addCleanup(fake_add_message.stop)
fake_adjust_flow_session_page_data = mock.patch(
"course.flow.adjust_flow_session_page_data")
self.mock_adjust_flow_session_page_data = (
fake_adjust_flow_session_page_data.start())
self.mock_adjust_flow_session_page_data.return_value = None
self.addCleanup(fake_adjust_flow_session_page_data.stop)
def get_view_unsubmit_flow_page_url(
self, page_ordinal, course_identifier=None, flow_session_id=None):
course_identifier = course_identifier or self.get_default_course_identifier()
flow_session_id = (flow_session_id
or self.get_default_flow_session_id(course_identifier))
return reverse(
"relate-unsubmit_flow_page",
kwargs={"course_identifier": course_identifier,
"flow_session_id": flow_session_id,
"page_ordinal": page_ordinal})
def get_view_unsubmit_flow_page_url_by_page_id(
self, page_id, course_identifier=None, flow_session_id=None):
course_identifier = course_identifier or self.get_default_course_identifier()
flow_session_id = (flow_session_id
or self.get_default_flow_session_id(course_identifier))
page_ordinal = self.get_page_ordinal_via_page_id(page_id)
return self.get_view_unsubmit_flow_page_url(
page_ordinal, course_identifier, flow_session_id)
def test_anonymous(self):
with self.temporarily_switch_to_user(None):
resp = self.client.get(
self.get_view_unsubmit_flow_page_url_by_page_id(self.page_id))
self.assertEqual(resp.status_code, 403)
resp = self.client.post(
self.get_view_unsubmit_flow_page_url_by_page_id(self.page_id),
data={"submit": ""})
self.assertEqual(resp.status_code, 403)
self.assertEqual(self.mock_unsubmit_page.call_count, 0)
def test_no_pperm(self):
with self.temporarily_switch_to_user(self.student_participation.user):
resp = self.client.get(
self.get_view_unsubmit_flow_page_url_by_page_id(self.page_id))
self.assertEqual(resp.status_code, 403)
resp = self.client.post(
self.get_view_unsubmit_flow_page_url_by_page_id(self.page_id),
data={"submit": ""})
self.assertEqual(resp.status_code, 403)
self.assertEqual(self.mock_unsubmit_page.call_count, 0)
def test_session_does_not_exist(self):
resp = self.client.get(
self.get_view_unsubmit_flow_page_url_by_page_id(
self.page_id, flow_session_id=100))
self.assertEqual(resp.status_code, 404)
resp = self.client.post(
self.get_view_unsubmit_flow_page_url_by_page_id(
self.page_id, flow_session_id=100),
data={"submit": ""})
self.assertEqual(resp.status_code, 404)
self.assertEqual(self.mock_unsubmit_page.call_count, 0)
def test_success(self):
# get_success
resp = self.client.get(
self.get_view_unsubmit_flow_page_url_by_page_id(self.page_id))
self.assertEqual(resp.status_code, 200)
# post_success
resp = self.client.post(
self.get_view_unsubmit_flow_page_url_by_page_id(self.page_id),
data={"submit": ""})
self.assertEqual(resp.status_code, 302)
self.assertEqual(self.mock_unsubmit_page.call_count, 1)
self.assertEqual(self.mock_add_message.call_count, 1)
self.assertIn(
"Flow page changes reallowed. ",
self.mock_add_message.call_args[0]
)
def test_postdata_without_submit(self):
resp = self.client.post(
self.get_view_unsubmit_flow_page_url_by_page_id(self.page_id),
data={})
self.assertEqual(resp.status_code, 302)
self.assertEqual(self.mock_unsubmit_page.call_count, 0)
self.assertEqual(self.mock_add_message.call_count, 0)
def test_post_form_not_valid(self):
with mock.patch(
"course.flow.UnsubmitFlowPageForm.is_valid") as mock_form_valid:
mock_form_valid.return_value = False
resp = self.client.post(
self.get_view_unsubmit_flow_page_url_by_page_id(self.page_id),
data={"submit": ""})
self.assertEqual(resp.status_code, 200)
self.assertEqual(self.mock_unsubmit_page.call_count, 0)
def test_unsubmit_page_has_no_answer_visit(self):
# this page has not been answered yet
page_id = "ice_cream_toppings"
expected_error_msg = "No prior answers found that could be un-submitted."
resp = self.client.get(
self.get_view_unsubmit_flow_page_url_by_page_id(page_id))
self.assertEqual(resp.status_code, 302)
self.assertEqual(self.mock_unsubmit_page.call_count, 0)
self.assertEqual(self.mock_add_message.call_count, 1)
self.assertIn(expected_error_msg, self.mock_add_message.call_args[0])
self.mock_add_message.reset_mock()
resp = self.client.post(
self.get_view_unsubmit_flow_page_url_by_page_id(page_id),
data={"submit": ""})
self.assertEqual(resp.status_code, 302)
self.assertEqual(self.mock_unsubmit_page.call_count, 0)
self.assertEqual(self.mock_add_message.call_count, 1)
self.assertIn(expected_error_msg, self.mock_add_message.call_args[0])