def test_ok_views(self): # we only test ta participation from course.auth import make_sign_in_key # make sign in key for a user u = factories.UserFactory( first_name="foo", last_name="bar", status=constants.user_status.unconfirmed) sign_in_key = make_sign_in_key(u) u.sign_in_key = sign_in_key u.save() self.c.force_login(self.ta_participation.user) my_session = factories.FlowSessionFactory( participation=self.ta_participation, flow_id=self.flow_id) with override_settings(RELATE_SIGN_IN_BY_USERNAME_ENABLED=True): for url, args, kwargs, code_or_redirect in [ ("relate-sign_in_choice", [], {}, 200), ("relate-sign_in_by_email", [], {}, 200), ("relate-sign_in_stage2_with_token", [u.pk, sign_in_key], {}, "/"), ("relate-sign_in_by_user_pw", [], {}, 200), ("relate-impersonate", [], {}, 200), # because not we are testing get, while stop_impersonating view # doesn't allow get, if it return 403 instead of 302 # we think it passed test. ("relate-stop_impersonating", [], {}, 403), ("relate-check_in_for_exam", [], {}, 200), ("relate-list_available_exams", [], {}, 200), ("relate-view_start_flow", [], {"course_identifier": self.course.identifier, "flow_id": self.flow_id}, 200), ("relate-view_resume_flow", [], {"course_identifier": self.course.identifier, "flow_session_id": my_session.pk}, self.get_page_url_by_ordinal(0, flow_session_id=my_session.pk)), ("relate-user_profile", [], {}, 200), ("relate-logout", [], {}, "/"), ("relate-set_pretend_facilities", [], {}, 200), ]: with self.subTest(url=url): if "sign_in" in url: switch_to = None else: switch_to = self.ta_participation.user with self.temporarily_switch_to_user(switch_to): resp = self.c.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)
def test_ok_views(self): # we only test student participation user from course.auth import make_sign_in_key # make sign in key for a user u = factories.UserFactory(first_name="foo", last_name="bar", status=constants.user_status.unconfirmed) sign_in_key = make_sign_in_key(u) u.sign_in_key = sign_in_key u.save() with override_settings(RELATE_SIGN_IN_BY_USERNAME_ENABLED=True): for url, args, kwargs, code_or_redirect in [ # 403, because these file do not have "in_exam" access permission ("relate-get_repo_file", [], { "course_identifier": self.course.identifier, "commit_sha": self.course.active_git_commit_sha, "path": "images/cc.png" }, 403), ("relate-get_current_repo_file", [], { "course_identifier": self.course.identifier, "path": "pdfs/sample.pdf" }, 403), ("relate-check_in_for_exam", [], {}, 200), ("relate-list_available_exams", [], {}, 200), ("relate-sign_in_choice", [], {}, 200), ("relate-sign_in_by_email", [], {}, 200), ("relate-sign_in_stage2_with_token", [u.pk, sign_in_key], {}, "/"), ("relate-sign_in_by_user_pw", [], {}, 200), ("relate-user_profile", [], {}, 200), ("relate-logout", [], {}, "/"), ]: with self.subTest(url=url): if "sign_in" in url: switch_to = None else: switch_to = self.student_participation.user with self.temporarily_switch_to_user(switch_to): self.tweak_session_to_lock_down() resp = self.c.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)
def test_ok_views(self): # we only test student participation user from course.auth import make_sign_in_key # make sign in key for a user u = factories.UserFactory( first_name="foo", last_name="bar", status=constants.user_status.unconfirmed) sign_in_key = make_sign_in_key(u) u.sign_in_key = sign_in_key u.save() with override_settings(RELATE_SIGN_IN_BY_USERNAME_ENABLED=True): for url, args, kwargs, code_or_redirect in [ # 403, because these file do not have "in_exam" access permission ("relate-get_repo_file", [], { "course_identifier": self.course.identifier, "commit_sha": self.course.active_git_commit_sha, "path": "images/cc.png"}, 403), ("relate-get_current_repo_file", [], { "course_identifier": self.course.identifier, "path": "pdfs/sample.pdf"}, 403), ("relate-check_in_for_exam", [], {}, 200), ("relate-list_available_exams", [], {}, 200), ("relate-sign_in_choice", [], {}, 200), ("relate-sign_in_by_email", [], {}, 200), ("relate-sign_in_stage2_with_token", [u.pk, sign_in_key], {}, "/"), ("relate-sign_in_by_user_pw", [], {}, 200), ("relate-user_profile", [], {}, 200), ("relate-logout", [], {}, "/"), ]: with self.subTest(url=url): if "sign_in" in url: switch_to = None else: switch_to = self.student_participation.user with self.temporarily_switch_to_user(switch_to): self.tweak_session_to_lock_down() resp = self.c.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)
def test_ok_views(self): # we only test ta participation from course.auth import make_sign_in_key # make sign in key for a user u = factories.UserFactory(first_name="foo", last_name="bar", status=constants.user_status.unconfirmed) sign_in_key = make_sign_in_key(u) u.sign_in_key = sign_in_key u.save() self.c.force_login(self.ta_participation.user) my_session = factories.FlowSessionFactory( participation=self.ta_participation, flow_id=self.flow_id) with override_settings(RELATE_SIGN_IN_BY_USERNAME_ENABLED=True): for url, args, kwargs, code_or_redirect in [ ("relate-sign_in_choice", [], {}, 200), ("relate-sign_in_by_email", [], {}, 200), ("relate-sign_in_stage2_with_token", [u.pk, sign_in_key], {}, "/"), ("relate-sign_in_by_user_pw", [], {}, 200), ("relate-impersonate", [], {}, 200), # because not we are testing get, while stop_impersonating view # doesn't allow get, if it return 403 instead of 302 # we think it passed test. ("relate-stop_impersonating", [], {}, 403), ("relate-check_in_for_exam", [], {}, 200), ("relate-list_available_exams", [], {}, 200), ("relate-view_start_flow", [], { "course_identifier": self.course.identifier, "flow_id": self.flow_id }, 200), ("relate-view_resume_flow", [], { "course_identifier": self.course.identifier, "flow_session_id": my_session.pk }, self.get_page_url_by_ordinal(0, flow_session_id=my_session.pk)), ("relate-user_profile", [], {}, 200), ("relate-logout", [], {}, "/"), ("relate-set_pretend_facilities", [], {}, 200), ]: with self.subTest(url=url): if "sign_in" in url: switch_to = None else: switch_to = self.ta_participation.user with self.temporarily_switch_to_user(switch_to): resp = self.c.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)
def token_hash(self, create, extracted, **kwargs): if not create: return else: token = make_sign_in_key(self.user) self.token_hash = make_password(token)