diff --git a/lostplaces/lostplaces_app/tests/views/test_base_views.py b/lostplaces/lostplaces_app/tests/views/test_base_views.py index b3d8ae2..9a0ad0d 100644 --- a/lostplaces/lostplaces_app/tests/views/test_base_views.py +++ b/lostplaces/lostplaces_app/tests/views/test_base_views.py @@ -7,9 +7,11 @@ from django.contrib.messages.storage.fallback import FallbackStorage from lostplaces_app.models import Place from lostplaces_app.views import IsAuthenticatedMixin +from lostplaces_app.tests.views import ViewTestCaseMixin + +class TestIsAuthenticated(ViewTestCaseMixin, TestCase): + view = IsAuthenticatedMixin -class TestIsAuthenticatedMixin(RedirectTestCase): - @classmethod def setUpTestData(cls): user = User.objects.create_user( @@ -22,7 +24,8 @@ class TestIsAuthenticatedMixin(RedirectTestCase): request.user = User.objects.get(id=1) response = IsAuthenticatedMixin.as_view()(request) - self.assertEqual(response.status_code, 200) + # Expecting a 405 because IsAuthenticatedMixin has no 'get' method + self.assertHttpMethodNotAllowed(response) def test_not_logged_in(self): request = RequestFactory().get('/someurl1234') @@ -32,10 +35,10 @@ class TestIsAuthenticatedMixin(RedirectTestCase): request._messages = messages response = IsAuthenticatedMixin.as_view()(request) - self.assertRedirectsTo(response, '?'.join([str(reverse_lazy('login')), 'next=/someurl1234'])) - - self.assertTrue(response.context['messages']) - self.assertTrue(len(response.context['messages']) > 0) + self.assertHttpRedirect(response, '?'.join([str(reverse_lazy('login')), 'next=/someurl1234'])) + + response = self.client.get(response['Location']) + self.assertTrue(len(messages) > 0) class TestIsPlaceSubmitterMixin(TestCase):