Testing messages
This commit is contained in:
parent
b77c5d1d7f
commit
f1c51ab8a7
@ -7,8 +7,10 @@ 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 TestIsAuthenticatedMixin(RedirectTestCase):
|
||||
class TestIsAuthenticated(ViewTestCaseMixin, TestCase):
|
||||
view = IsAuthenticatedMixin
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
@ -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.assertHttpRedirect(response, '?'.join([str(reverse_lazy('login')), 'next=/someurl1234']))
|
||||
|
||||
self.assertTrue(response.context['messages'])
|
||||
self.assertTrue(len(response.context['messages']) > 0)
|
||||
response = self.client.get(response['Location'])
|
||||
self.assertTrue(len(messages) > 0)
|
||||
|
||||
class TestIsPlaceSubmitterMixin(TestCase):
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user