def test_unauthorized_user(self) -> None: user = self.UserFactory.create() student = self.StudentFactory() request = self.request_factory.authenticated_get(user) with self.assertRaises(Http404): views.student_profile(request, student.id)
def test_context(self, render: mock.MagicMock) -> None: user = self.UserFactory.create() student = self.StudentFactory(user=user) target_school = self.TargetSchoolFactory.create(student=student) milestone = self.MilestoneFactory.create(school=target_school.school) target_school.milestones.add(milestone) request = self.request_factory.authenticated_get(user) views.student_profile(request, student.id) context = render.call_args[0][2] self.assertEqual(Milestone, context["Milestone"]) self.assertEqual(student, context["student"]) self.assertEqual([target_school.school], list(context["schools"])) self.assertEqual([milestone], list(context["target_milestones"]))
def test_requires_login(self) -> None: request = self.request_factory.get() response = views.student_profile(request, 1) self.assertEqual(302, response.status_code) self.assertIn(reverse("login"), response.get("Location"))
def test_valid(self) -> None: user = self.UserFactory.create() student = self.StudentFactory(user=user) request = self.request_factory.authenticated_get(user) response = views.student_profile(request, student.id) self.assertEqual(200, response.status_code)
def test_schools_by_application_type(self, render: mock.MagicMock) -> None: """Order the schools by what application types are available. * The application type with the most schools will be ordered first. * The school will only be selected for one app type. * The student may also have no selected app type yet. """ user = self.UserFactory.create() student = self.StudentFactory(user=user) school_1 = self.SchoolFactory.create(name="A University") school_application_1 = self.SchoolApplicationFactory.create( school=school_1, application_type=SchoolApplication.SCHOOL_BASED_APPLICATION) self.TargetSchoolFactory.create( student=student, school_application=school_application_1, school=school_1) school_application_1b = self.SchoolApplicationFactory.create( school=school_1, application_type=SchoolApplication.COMMON_APPLICATION) school_2 = self.SchoolFactory.create(name="B University") school_application_2 = self.SchoolApplicationFactory.create( school=school_2, application_type=SchoolApplication.SCHOOL_BASED_APPLICATION) self.TargetSchoolFactory.create( student=student, school_application=school_application_2, school=school_2) school_3 = self.SchoolFactory.create(name="B University") school_application_3 = self.SchoolApplicationFactory.create( school=school_3, application_type=SchoolApplication.COALITION_APPLICATION) self.TargetSchoolFactory.create(student=student, school=school_3) request = self.request_factory.authenticated_get(user) views.student_profile(request, student.id) context = render.call_args[0][2] expected_data: Dict[str, List[Dict]] = OrderedDict() expected_data["School-Based Application"] = [ { "school": school_1, "school_application": school_application_1, "no_app_selected": False, "selected": True, }, { "school": school_2, "school_application": school_application_2, "no_app_selected": False, "selected": True, }, ] expected_data["Common Application"] = [{ "school": school_1, "school_application": school_application_1b, "no_app_selected": False, "selected": False, }] expected_data["Coalition Application"] = [{ "school": school_3, "school_application": school_application_3, "no_app_selected": True, "selected": False, }] expected_data["Universal College Application"] = [] self.assertEqual(expected_data, context["schools_by_application_type"])