Mixin Test does not rely on actual place view
This commit is contained in:
parent
f5f5980f9b
commit
29d067002e
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
23238#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from django.test import TestCase, RequestFactory, Client
|
||||
@ -6,6 +6,7 @@ from django.urls import reverse_lazy
|
||||
from django.contrib.auth.models import User, AnonymousUser
|
||||
from django.contrib.messages.storage.fallback import FallbackStorage
|
||||
from django.utils import timezone
|
||||
from django.shortcuts import render
|
||||
|
||||
from lostplaces.models import Place
|
||||
from lostplaces.views import IsAuthenticatedMixin
|
||||
@ -33,14 +34,14 @@ class TestIsAuthenticated(ViewTestCase):
|
||||
self.assertHttpMethodNotAllowed(response)
|
||||
|
||||
def test_not_logged_in(self):
|
||||
request = RequestFactory().get('/someurl1234')
|
||||
request = RequestFactory().get('/')
|
||||
request.user = AnonymousUser()
|
||||
request.session = 'session'
|
||||
messages = FallbackStorage(request)
|
||||
request._messages = messages
|
||||
|
||||
response = IsAuthenticatedMixin.as_view()(request)
|
||||
self.assertHttpRedirect(response, '?'.join([str(reverse_lazy('login')), 'next=/someurl1234']))
|
||||
self.assertHttpRedirect(response, '?'.join([str(reverse_lazy('login')), 'next=/']))
|
||||
|
||||
response = self.client.get(response['Location'])
|
||||
self.assertTrue(len(messages) > 0)
|
||||
@ -86,4 +87,5 @@ class TestIsPlaceSubmitterMixin(TestCase):
|
||||
response = self.client.get(reverse_lazy('place_edit', kwargs={'pk': 1}))
|
||||
self.assertEqual(response.status_code, 403)
|
||||
self.assertTrue(response.context['messages'])
|
||||
self.assertTrue(len(response.context['messages']) > 0)
|
||||
self.assertTrue(len(response.context['messages']) > 0)
|
||||
|
Loading…
Reference in New Issue
Block a user