Пример #1
0
    def test_unauthorized_user(self) -> None:
        user = self.UserFactory.create()
        student = self.StudentFactory()
        request = self.request_factory.authenticated_post(user, data={})

        with self.assertRaises(Http404):
            views.remove_school(request, student.id)
Пример #2
0
    def test_requires_post(self) -> None:
        user = self.UserFactory.create()
        request = self.request_factory.authenticated_get(user)

        response = views.remove_school(request, 1)

        self.assertEqual(405, response.status_code)
Пример #3
0
    def test_requires_login(self) -> None:
        request = self.request_factory.get()

        response = views.remove_school(request, 1)

        self.assertEqual(302, response.status_code)
        self.assertIn(reverse("login"), response.get("Location"))
Пример #4
0
    def test_invalid_post(self, messages: mock.MagicMock) -> None:
        user = self.UserFactory.create()
        student = self.StudentFactory(user=user)
        request = self.request_factory.authenticated_post(user, data={})

        response = views.remove_school(request, student.id)

        messages.add_message.assert_called_once_with(request, messages.ERROR,
                                                     mock.ANY)
        self.assertEqual(302, response.status_code)
        self.assertIn(reverse("student-profile", args=[student.id]),
                      response.get("Location"))