2020-09-12 08:39:06 +02:00
|
|
|
import datetime
|
|
|
|
|
2020-09-12 11:02:39 +02:00
|
|
|
from django.test import TestCase
|
2020-09-04 21:48:05 +02:00
|
|
|
from django.urls import reverse_lazy
|
2020-09-12 08:39:06 +02:00
|
|
|
from django.contrib.auth.models import User
|
2020-09-04 21:48:05 +02:00
|
|
|
|
|
|
|
from lostplaces_app.models import Place
|
2020-09-12 11:02:39 +02:00
|
|
|
from lostplaces_app.views import (
|
|
|
|
PlaceCreateView,
|
|
|
|
PlaceListView
|
|
|
|
)
|
|
|
|
from lostplaces_app.forms import PlaceImageCreateForm, PlaceForm
|
|
|
|
from lostplaces_app.tests.views import ViewTestCase
|
2020-09-04 21:48:05 +02:00
|
|
|
|
2020-09-12 11:02:39 +02:00
|
|
|
class TestPlaceCreateView(ViewTestCase, TestCase):
|
|
|
|
|
|
|
|
view = PlaceCreateView
|
2020-09-12 08:39:06 +02:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def setUpTestData(cls):
|
|
|
|
user = User.objects.create_user(
|
|
|
|
username='testpeter',
|
|
|
|
password='Develop123'
|
|
|
|
)
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
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-12 11:02:39 +02:00
|
|
|
response = self.client.get(reverse_lazy('place_create'))
|
|
|
|
|
|
|
|
self._test_form(response, 'place_image_form', PlaceImageCreateForm)
|
|
|
|
self._test_form(response, 'place_form', PlaceForm)
|
|
|
|
|
|
|
|
class TestPlaceListView(ViewTestCase, TestCase):
|
|
|
|
view = PlaceListView
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def setUpTestData(cls):
|
|
|
|
user = User.objects.create_user(
|
|
|
|
username='testpeter',
|
|
|
|
password='Develop123'
|
2020-09-04 21:48:05 +02:00
|
|
|
)
|
2020-09-12 11:02:39 +02:00
|
|
|
|
|
|
|
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')
|
|
|
|
|
2020-09-04 21:48:05 +02:00
|
|
|
|