2020-09-12 08:39:06 +02:00
|
|
|
import datetime
|
|
|
|
|
2020-09-13 19:43:47 +02:00
|
|
|
from django.test import TestCase, Client
|
2020-09-13 20:27:05 +02:00
|
|
|
from django.urls import reverse
|
2020-09-12 08:39:06 +02:00
|
|
|
from django.contrib.auth.models import User
|
2020-09-18 22:04:19 +02:00
|
|
|
from django.utils import timezone
|
|
|
|
|
2020-09-04 21:48:05 +02:00
|
|
|
|
2020-09-14 17:26:17 +02:00
|
|
|
from lostplaces.models import Place
|
|
|
|
from lostplaces.views import (
|
2020-09-12 11:02:39 +02:00
|
|
|
PlaceCreateView,
|
2020-09-13 20:27:05 +02:00
|
|
|
PlaceListView,
|
|
|
|
PlaceDetailView
|
2020-09-12 11:02:39 +02:00
|
|
|
)
|
2020-09-14 17:26:17 +02:00
|
|
|
from lostplaces.forms import PlaceImageCreateForm, PlaceForm
|
|
|
|
from lostplaces.tests.views import (
|
2020-09-13 20:27:05 +02:00
|
|
|
ViewTestCase,
|
|
|
|
TaggableViewTestCaseMixin,
|
2020-09-14 15:18:21 +02:00
|
|
|
MapableViewTestCaseMixin
|
2020-09-13 20:27:05 +02:00
|
|
|
)
|
|
|
|
|
2020-09-04 21:48:05 +02:00
|
|
|
|
2020-09-13 19:43:47 +02:00
|
|
|
class TestPlaceCreateView(ViewTestCase):
|
2020-09-12 11:02:39 +02:00
|
|
|
view = PlaceCreateView
|
2020-09-13 20:27:05 +02:00
|
|
|
|
2020-09-12 08:39:06 +02:00
|
|
|
@classmethod
|
|
|
|
def setUpTestData(cls):
|
|
|
|
user = User.objects.create_user(
|
|
|
|
username='testpeter',
|
|
|
|
password='Develop123'
|
|
|
|
)
|
2020-09-13 20:27:05 +02:00
|
|
|
|
2020-09-12 08:39:06 +02:00
|
|
|
place = Place.objects.create(
|
|
|
|
name='Im a place',
|
2020-09-18 22:04:19 +02:00
|
|
|
submitted_when=timezone.now(),
|
2020-09-12 08:39:06 +02:00
|
|
|
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()
|
2020-09-13 20:27:05 +02:00
|
|
|
|
2020-09-13 19:43:47 +02:00
|
|
|
def setUp(self):
|
|
|
|
self.client = Client()
|
2020-09-13 20:27:05 +02:00
|
|
|
|
2020-09-12 11:02:39 +02:00
|
|
|
def test_has_forms(self):
|
2020-09-04 21:48:05 +02:00
|
|
|
self.client.login(username='testpeter', password='Develop123')
|
2020-09-13 20:27:05 +02:00
|
|
|
response = self.client.get(reverse('place_create'))
|
|
|
|
|
2020-09-13 12:39:02 +02:00
|
|
|
self.assertHasForm(response, 'place_image_form', PlaceImageCreateForm)
|
|
|
|
self.assertHasForm(response, 'place_form', PlaceForm)
|
2020-09-13 20:27:05 +02:00
|
|
|
|
|
|
|
|
2020-09-13 19:43:47 +02:00
|
|
|
class TestPlaceListView(ViewTestCase):
|
2020-09-12 11:02:39 +02:00
|
|
|
view = PlaceListView
|
2020-09-13 20:27:05 +02:00
|
|
|
|
2020-09-12 11:02:39 +02:00
|
|
|
@classmethod
|
|
|
|
def setUpTestData(cls):
|
|
|
|
user = User.objects.create_user(
|
|
|
|
username='testpeter',
|
|
|
|
password='Develop123'
|
2020-09-04 21:48:05 +02:00
|
|
|
)
|
2020-09-13 20:27:05 +02:00
|
|
|
|
2020-09-12 11:02:39 +02:00
|
|
|
place = Place.objects.create(
|
|
|
|
name='Im a place',
|
2020-09-18 22:04:19 +02:00
|
|
|
submitted_when=timezone.now(),
|
2020-09-12 11:02:39 +02:00
|
|
|
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()
|
2020-09-13 20:27:05 +02:00
|
|
|
|
2020-09-13 19:43:47 +02:00
|
|
|
def setUp(self):
|
2020-09-13 20:27:05 +02:00
|
|
|
self.client = Client()
|
|
|
|
|
2020-09-12 11:02:39 +02:00
|
|
|
def test_list_view(self):
|
|
|
|
self.client.login(username='testpeter', password='Develop123')
|
2020-09-13 20:27:05 +02:00
|
|
|
response = self.client.get(reverse('place_list'))
|
|
|
|
|
|
|
|
self.assertContext(response, 'mapping_config')
|
|
|
|
|
|
|
|
|
2020-09-14 15:18:21 +02:00
|
|
|
class PlaceDetailViewTestCase(TaggableViewTestCaseMixin, MapableViewTestCaseMixin, ViewTestCase):
|
2020-09-13 20:27:05 +02:00
|
|
|
view = PlaceDetailView
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def setUpTestData(cls):
|
|
|
|
user = User.objects.create_user(
|
|
|
|
username='testpeter',
|
|
|
|
password='Develop123'
|
|
|
|
)
|
|
|
|
|
|
|
|
place = Place.objects.create(
|
|
|
|
name='Im a place',
|
2020-09-18 22:04:19 +02:00
|
|
|
submitted_when=timezone.now(),
|
2020-09-13 20:27:05 +02:00
|
|
|
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_context(self):
|
|
|
|
self.client.login(username='testpeter', password='Develop123')
|
|
|
|
response = self.client.get(reverse('place_detail', kwargs={'pk': 1}))
|
|
|
|
|
|
|
|
self.assertTrue(
|
|
|
|
'tagging_config' in response.context,
|
|
|
|
msg='Expecting the context of %s to have an \'tagging_config\'' % (
|
|
|
|
str(self.view)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.assertTaggableContext(response.context['tagging_config'])
|
|
|
|
|
|
|
|
self.assertTrue(
|
|
|
|
'mapping_config' in response.context,
|
|
|
|
msg='Expecting the context of %s to have an \'mapping_config\'' % (
|
|
|
|
str(self.view)
|
|
|
|
)
|
|
|
|
)
|
2020-09-14 15:18:21 +02:00
|
|
|
self.assertMapableContext(response.context['mapping_config'])
|