2020-09-04 21:48:05 +02:00
|
|
|
from django.test import TestCase, Client
|
|
|
|
from django.urls import reverse_lazy
|
|
|
|
|
|
|
|
from lostplaces_app.models import Place
|
|
|
|
|
|
|
|
class TestPlaceCreateView(TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self. client = Client()
|
|
|
|
|
|
|
|
def test_url_logged_in(self):
|
|
|
|
self.client.login(username='testpeter', password='Develop123')
|
|
|
|
response = self.client.get(reverse_lazy('place_detail', kwargs={'pk': 1}))
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
|
|
def test_url_not_logged_in(self):
|
|
|
|
url = reverse_lazy('place_detail', kwargs={'pk': 1})
|
|
|
|
response = self.client.get(url)
|
|
|
|
self.assertRedirects(
|
|
|
|
response=response,
|
2020-09-10 22:30:29 +02:00
|
|
|
expected_url='?'.join([str(reverse_lazy('login')), 'next=/place/1/']),
|
2020-09-04 21:48:05 +02:00
|
|
|
status_code=302,
|
|
|
|
target_status_code=200,
|
|
|
|
msg_prefix='''Accesing PlaceDetailView while not logged should
|
|
|
|
redirect to login page with redirect params
|
|
|
|
''',
|
|
|
|
fetch_redirect_response=True
|
|
|
|
)
|
|
|
|
|
|
|
|
|