Skip to content
test_exam.py 43.9 KiB
Newer Older
                 {"course_identifier": self.course.identifier,
                  "flow_session_id": another_fs.pk},
                 self.get_view_start_flow_url(self.flow_id)),
            ("relate-update_page_bookmark_state", [],
                 {"course_identifier": self.course.identifier,
                  "flow_session_id": another_fs.pk, "page_ordinal": 0},
                 self.get_view_start_flow_url(self.flow_id)),
            ("relate-finish_flow_session_view", [],
                 {"course_identifier": self.course.identifier,
                  "flow_session_id": another_fs.pk},
                 self.get_view_start_flow_url(self.flow_id)),
        ]:
            with self.subTest(url=url):
                self.tweak_session_to_lock_down()
                resp = self.client.get(reverse(url, args=args, kwargs=kwargs))
                try:
                    code = int(code_or_redirect)
                    self.assertEqual(resp.status_code, code)
                except ValueError:
                    self.assertRedirects(
                        resp, code_or_redirect,
                        fetch_redirect_response=False)
                self.assertAddMessageCallCount(1)
                self.assertAddMessageCalledWith(
                    "Your RELATE session is currently locked down "
                    "to this exam flow. Navigating to other parts of "
                    "RELATE is not currently allowed. "
                    "To exit this exam, log out.")

    def test_start_flow_ok(self):
        for url, args, kwargs, code_or_redirect in [
            ("relate-view_start_flow", [],
                 {"course_identifier": self.course.identifier,
                  "flow_id": self.flow_id}, 200),
        ]:
            with self.subTest(url=url):
                self.tweak_session_to_lock_down()
                resp = self.client.get(reverse(url, args=args, kwargs=kwargs))
                try:
                    code = int(code_or_redirect)
                    self.assertEqual(resp.status_code, code)
                except ValueError:
                    self.assertRedirects(
                        resp, code_or_redirect,
                        fetch_redirect_response=False)

                self.assertAddMessageCallCount(0, reset=True)

    def test_start_flow_not_ok(self):
        another_flow_id = "jinja-yaml"

        for url, args, kwargs, code_or_redirect in [
            ("relate-view_start_flow", [],
                 {"course_identifier": self.course.identifier,
                  "flow_id": another_flow_id},
                 self.get_view_start_flow_url(self.flow_id)),
        ]:
            with self.subTest(url=url):
                self.tweak_session_to_lock_down()
                resp = self.client.get(reverse(url, args=args, kwargs=kwargs))
                try:
                    code = int(code_or_redirect)
                    self.assertEqual(resp.status_code, code)
                except ValueError:
                    self.assertRedirects(
                        resp, code_or_redirect,
                        fetch_redirect_response=False)
                self.assertAddMessageCallCount(1)
                self.assertAddMessageCalledWith(
                    "Your RELATE session is currently locked down "
                    "to this exam flow. Navigating to other parts of "
                    "RELATE is not currently allowed. "
                    "To exit this exam, log out.")

Dong Zhuang's avatar
Dong Zhuang committed
# vim: fdm=marker