Testing messages
This commit is contained in:
parent
b77c5d1d7f
commit
f1c51ab8a7
@ -7,9 +7,11 @@ from django.contrib.messages.storage.fallback import FallbackStorage
|
|||||||
|
|
||||||
from lostplaces_app.models import Place
|
from lostplaces_app.models import Place
|
||||||
from lostplaces_app.views import IsAuthenticatedMixin
|
from lostplaces_app.views import IsAuthenticatedMixin
|
||||||
|
from lostplaces_app.tests.views import ViewTestCaseMixin
|
||||||
|
|
||||||
|
class TestIsAuthenticated(ViewTestCaseMixin, TestCase):
|
||||||
|
view = IsAuthenticatedMixin
|
||||||
|
|
||||||
class TestIsAuthenticatedMixin(RedirectTestCase):
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpTestData(cls):
|
def setUpTestData(cls):
|
||||||
user = User.objects.create_user(
|
user = User.objects.create_user(
|
||||||
@ -22,7 +24,8 @@ class TestIsAuthenticatedMixin(RedirectTestCase):
|
|||||||
request.user = User.objects.get(id=1)
|
request.user = User.objects.get(id=1)
|
||||||
|
|
||||||
response = IsAuthenticatedMixin.as_view()(request)
|
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):
|
def test_not_logged_in(self):
|
||||||
request = RequestFactory().get('/someurl1234')
|
request = RequestFactory().get('/someurl1234')
|
||||||
@ -32,10 +35,10 @@ class TestIsAuthenticatedMixin(RedirectTestCase):
|
|||||||
request._messages = messages
|
request._messages = messages
|
||||||
|
|
||||||
response = IsAuthenticatedMixin.as_view()(request)
|
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'])
|
response = self.client.get(response['Location'])
|
||||||
self.assertTrue(len(response.context['messages']) > 0)
|
self.assertTrue(len(messages) > 0)
|
||||||
|
|
||||||
class TestIsPlaceSubmitterMixin(TestCase):
|
class TestIsPlaceSubmitterMixin(TestCase):
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user