Testing PlaceListView
This commit is contained in:
parent
26286984c2
commit
317437fedc
@ -1,12 +1,20 @@
|
|||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from django.test import TestCase, Client
|
from django.test import TestCase
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
from lostplaces_app.models import Place
|
from lostplaces_app.models import Place
|
||||||
|
from lostplaces_app.views import (
|
||||||
|
PlaceCreateView,
|
||||||
|
PlaceListView
|
||||||
|
)
|
||||||
|
from lostplaces_app.forms import PlaceImageCreateForm, PlaceForm
|
||||||
|
from lostplaces_app.tests.views import ViewTestCase
|
||||||
|
|
||||||
class TestPlaceCreateView(TestCase):
|
class TestPlaceCreateView(ViewTestCase, TestCase):
|
||||||
|
|
||||||
|
view = PlaceCreateView
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpTestData(cls):
|
def setUpTestData(cls):
|
||||||
@ -27,26 +35,39 @@ class TestPlaceCreateView(TestCase):
|
|||||||
place.tags.add('I a tag', 'testlocation')
|
place.tags.add('I a tag', 'testlocation')
|
||||||
place.save()
|
place.save()
|
||||||
|
|
||||||
def setUp(self):
|
def test_has_forms(self):
|
||||||
self. client = Client()
|
|
||||||
|
|
||||||
def test_url_logged_in(self):
|
|
||||||
self.client.login(username='testpeter', password='Develop123')
|
self.client.login(username='testpeter', password='Develop123')
|
||||||
response = self.client.get(reverse_lazy('place_detail', kwargs={'pk': 1}))
|
response = self.client.get(reverse_lazy('place_create'))
|
||||||
self.assertEqual(response.status_code, 200)
|
|
||||||
|
self._test_form(response, 'place_image_form', PlaceImageCreateForm)
|
||||||
def test_url_not_logged_in(self):
|
self._test_form(response, 'place_form', PlaceForm)
|
||||||
url = reverse_lazy('place_detail', kwargs={'pk': 1})
|
|
||||||
response = self.client.get(url)
|
class TestPlaceListView(ViewTestCase, TestCase):
|
||||||
self.assertRedirects(
|
view = PlaceListView
|
||||||
response=response,
|
|
||||||
expected_url='?'.join([str(reverse_lazy('login')), 'next=/place/1/']),
|
@classmethod
|
||||||
status_code=302,
|
def setUpTestData(cls):
|
||||||
target_status_code=200,
|
user = User.objects.create_user(
|
||||||
msg_prefix='''Accesing PlaceDetailView while not logged should
|
username='testpeter',
|
||||||
redirect to login page with redirect params
|
password='Develop123'
|
||||||
''',
|
|
||||||
fetch_redirect_response=True
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
place = Place.objects.create(
|
||||||
|
name='Im a place',
|
||||||
|
submitted_when=datetime.datetime.now(),
|
||||||
|
submitted_by=user.explorer,
|
||||||
|
location='Testtown',
|
||||||
|
latitude=50.5,
|
||||||
|
longitude=7.0,
|
||||||
|
description='This is just a test, do not worry'
|
||||||
|
)
|
||||||
|
place.tags.add('I a tag', 'testlocation')
|
||||||
|
place.save()
|
||||||
|
|
||||||
|
def test_list_view(self):
|
||||||
|
self.client.login(username='testpeter', password='Develop123')
|
||||||
|
response = self.client.get(reverse_lazy('place_list'))
|
||||||
|
|
||||||
|
self._test_has_context_key(response, 'place_map_center')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user