82 lines
2.4 KiB
Python
82 lines
2.4 KiB
Python
import datetime
|
|
|
|
from django.test import TestCase, Client
|
|
from django.urls import reverse_lazy
|
|
from django.contrib.auth.models import User
|
|
|
|
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(ViewTestCase):
|
|
view = PlaceCreateView
|
|
|
|
@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()
|
|
|
|
def setUp(self):
|
|
self.client = Client()
|
|
|
|
def test_has_forms(self):
|
|
self.client.login(username='testpeter', password='Develop123')
|
|
response = self.client.get(reverse_lazy('place_create'))
|
|
|
|
self.assertHasForm(response, 'place_image_form', PlaceImageCreateForm)
|
|
self.assertHasForm(response, 'place_form', PlaceForm)
|
|
|
|
class TestPlaceListView(ViewTestCase):
|
|
view = PlaceListView
|
|
|
|
@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()
|
|
|
|
def setUp(self):
|
|
self.client = Client()
|
|
|
|
def test_list_view(self):
|
|
self.client.login(username='testpeter', password='Develop123')
|
|
response = self.client.get(reverse_lazy('place_list'))
|
|
|
|
self.assertContext(response, 'map_config')
|
|
|
|
def test_test(self):
|
|
response = self.client.get(reverse_lazy('place_list'))
|
|
print(response['location'])
|
|
|
|
|