Compare commits
2 Commits
0a5d22d4d9
...
822a536ebe
Author | SHA1 | Date | |
---|---|---|---|
822a536ebe | |||
5b9672e21e |
@ -98,6 +98,9 @@ class PlaceAsset(Submittable):
|
|||||||
null=True
|
null=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
class DummyAsset(PlaceAsset):
|
||||||
|
name = models.CharField(max_length=50)
|
||||||
|
|
||||||
class PlaceImage(PlaceAsset):
|
class PlaceImage(PlaceAsset):
|
||||||
"""
|
"""
|
||||||
PlaceImage defines an image file object that points to a file in uploads/.
|
PlaceImage defines an image file object that points to a file in uploads/.
|
||||||
|
4
django_lostplaces/lostplaces/templates/flat_form.html
Normal file
4
django_lostplaces/lostplaces/templates/flat_form.html
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<form method={{form.method}}>
|
||||||
|
{{form}}
|
||||||
|
<input type="submit"/>
|
||||||
|
</form>
|
@ -3,14 +3,19 @@
|
|||||||
|
|
||||||
from django.test import TestCase, RequestFactory, Client
|
from django.test import TestCase, RequestFactory, Client
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
|
from django.db import models
|
||||||
from django.contrib.auth.models import User, AnonymousUser
|
from django.contrib.auth.models import User, AnonymousUser
|
||||||
from django.contrib.messages.storage.fallback import FallbackStorage
|
from django.contrib.messages.storage.fallback import FallbackStorage
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
|
|
||||||
from lostplaces.models import Place
|
from lostplaces.models import Place
|
||||||
from lostplaces.views import IsAuthenticatedMixin
|
from lostplaces.views import (
|
||||||
|
IsAuthenticatedMixin,
|
||||||
|
PlaceAssetCreateView
|
||||||
|
)
|
||||||
from lostplaces.tests.views import ViewTestCase
|
from lostplaces.tests.views import ViewTestCase
|
||||||
|
from lostplaces.models import DummyAsset
|
||||||
|
|
||||||
class TestIsAuthenticated(ViewTestCase):
|
class TestIsAuthenticated(ViewTestCase):
|
||||||
view = IsAuthenticatedMixin
|
view = IsAuthenticatedMixin
|
||||||
@ -21,9 +26,6 @@ class TestIsAuthenticated(ViewTestCase):
|
|||||||
username='testpeter',
|
username='testpeter',
|
||||||
password='Develop123'
|
password='Develop123'
|
||||||
)
|
)
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
self.client = Client()
|
|
||||||
|
|
||||||
def test_logged_in(self):
|
def test_logged_in(self):
|
||||||
request = RequestFactory().get('/')
|
request = RequestFactory().get('/')
|
||||||
@ -43,7 +45,6 @@ class TestIsAuthenticated(ViewTestCase):
|
|||||||
response = IsAuthenticatedMixin.as_view()(request)
|
response = IsAuthenticatedMixin.as_view()(request)
|
||||||
self.assertHttpRedirect(response, '?'.join([str(reverse_lazy('login')), 'next=/']))
|
self.assertHttpRedirect(response, '?'.join([str(reverse_lazy('login')), 'next=/']))
|
||||||
|
|
||||||
response = self.client.get(response['Location'])
|
|
||||||
self.assertTrue(len(messages) > 0)
|
self.assertTrue(len(messages) > 0)
|
||||||
|
|
||||||
class TestIsPlaceSubmitterMixin(TestCase):
|
class TestIsPlaceSubmitterMixin(TestCase):
|
||||||
@ -88,4 +89,51 @@ class TestIsPlaceSubmitterMixin(TestCase):
|
|||||||
self.assertEqual(response.status_code, 403)
|
self.assertEqual(response.status_code, 403)
|
||||||
self.assertTrue(response.context['messages'])
|
self.assertTrue(response.context['messages'])
|
||||||
self.assertTrue(len(response.context['messages']) > 0)
|
self.assertTrue(len(response.context['messages']) > 0)
|
||||||
|
|
||||||
|
class TestPlaceAssetCreateView(ViewTestCase):
|
||||||
|
view = PlaceAssetCreateView
|
||||||
|
|
||||||
|
class DummyAssetCreateView(PlaceAssetCreateView):
|
||||||
|
model = DummyAsset
|
||||||
|
fields = ['name']
|
||||||
|
template_name = 'flat_form.html'
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUpTestData(cls):
|
||||||
|
user = User.objects.create_user(
|
||||||
|
username='testpeter',
|
||||||
|
password='Develop123'
|
||||||
|
)
|
||||||
|
|
||||||
|
place = Place.objects.create(
|
||||||
|
name='Im a place',
|
||||||
|
submitted_when=timezone.now(),
|
||||||
|
submitted_by=user.explorer,
|
||||||
|
location='Testtown',
|
||||||
|
latitude=50.5,
|
||||||
|
longitude=7.0,
|
||||||
|
description='This is just a test, do not worry'
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_create_asset(self):
|
||||||
|
request = RequestFactory().post(
|
||||||
|
'/',
|
||||||
|
{
|
||||||
|
'name': 'im a place'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
request.user = User.objects.get(id=1)
|
||||||
|
|
||||||
|
response = TestPlaceAssetCreateView.DummyAssetCreateView.as_view()(request, place_id=1)
|
||||||
|
|
||||||
|
self.assertTrue(
|
||||||
|
DummyAsset.objects.all().count() >= 1,
|
||||||
|
msg='Expecting a dummy place asset to be created by the view'
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
DummyAsset.objects.get(id=1).name,
|
||||||
|
'im a place',
|
||||||
|
msg='Expecting the dummy place asset to have the correct data'
|
||||||
|
)
|
||||||
|
|
@ -42,7 +42,7 @@ class TestHomeView(GlobalTemplateTestCaseMixin, ViewTestCase):
|
|||||||
self.assertGlobal(response)
|
self.assertGlobal(response)
|
||||||
|
|
||||||
def test_place_list_authenticated(self):
|
def test_place_list_authenticated(self):
|
||||||
"""
|
"""
|
||||||
Testing there is the place list containing the name,
|
Testing there is the place list containing the name,
|
||||||
location and description of the latest place for
|
location and description of the latest place for
|
||||||
authenticated users.
|
authenticated users.
|
||||||
@ -59,7 +59,7 @@ class TestHomeView(GlobalTemplateTestCaseMixin, ViewTestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_place_list_unauthenticated(self):
|
def test_place_list_unauthenticated(self):
|
||||||
"""
|
"""
|
||||||
Testing there is a place list of the lates places
|
Testing there is a place list of the lates places
|
||||||
containing the place names only for unauthenticated users.
|
containing the place names only for unauthenticated users.
|
||||||
"""
|
"""
|
||||||
@ -82,7 +82,7 @@ class TestHomeView(GlobalTemplateTestCaseMixin, ViewTestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_map_authenticated(self):
|
def test_map_authenticated(self):
|
||||||
"""
|
"""
|
||||||
Testing there is a map showing all the lates places
|
Testing there is a map showing all the lates places
|
||||||
on a map for authenticated users.
|
on a map for authenticated users.
|
||||||
"""
|
"""
|
||||||
@ -98,7 +98,7 @@ class TestHomeView(GlobalTemplateTestCaseMixin, ViewTestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_map_unauthenticated(self):
|
def test_map_unauthenticated(self):
|
||||||
"""
|
"""
|
||||||
Testing there is no map for unauthenticated users.
|
Testing there is no map for unauthenticated users.
|
||||||
"""
|
"""
|
||||||
response = self.client.get(reverse('lostplaces_home'))
|
response = self.client.get(reverse('lostplaces_home'))
|
||||||
|
Loading…
Reference in New Issue
Block a user