Compare commits
No commits in common. "b3db6643b9dc3e666c4963b97df80967175c6cc6" and "b52d96a55e017bfce18e63a0c0d21c93a8416587" have entirely different histories.
b3db6643b9
...
b52d96a55e
@ -109,11 +109,19 @@ class Voucher(models.Model):
|
|||||||
return "Voucher " + str(self.code)
|
return "Voucher " + str(self.code)
|
||||||
|
|
||||||
|
|
||||||
class Place(Submittable, Taggable, MapablePoint):
|
class Place(Taggable, MapablePoint):
|
||||||
"""
|
"""
|
||||||
Place defines a lost place (location, name, description etc.).
|
Place defines a lost place (location, name, description etc.).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
submitted_when = models.DateTimeField(auto_now_add=True, null=True)
|
||||||
|
submitted_by = models.ForeignKey(
|
||||||
|
Explorer,
|
||||||
|
on_delete=models.SET_NULL,
|
||||||
|
null=True,
|
||||||
|
blank=True,
|
||||||
|
related_name='places'
|
||||||
|
)
|
||||||
location = models.CharField(max_length=50)
|
location = models.CharField(max_length=50)
|
||||||
description = models.TextField()
|
description = models.TextField()
|
||||||
|
|
||||||
@ -149,7 +157,7 @@ def generate_image_upload_path(instance, filename):
|
|||||||
return 'places/' + str(uuid.uuid4())+'.'+filename.split('.')[-1]
|
return 'places/' + str(uuid.uuid4())+'.'+filename.split('.')[-1]
|
||||||
|
|
||||||
|
|
||||||
class PlaceImage (Submittable):
|
class PlaceImage (models.Model):
|
||||||
"""
|
"""
|
||||||
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/.
|
||||||
Intermediate image sizes are generated as defined in SIZES.
|
Intermediate image sizes are generated as defined in SIZES.
|
||||||
@ -163,7 +171,15 @@ class PlaceImage (Submittable):
|
|||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
related_name='placeimages'
|
related_name='placeimages'
|
||||||
)
|
)
|
||||||
|
submitted_when = models.DateTimeField(auto_now_add=True, null=True)
|
||||||
|
submitted_by = models.ForeignKey(
|
||||||
|
Explorer,
|
||||||
|
on_delete=models.SET_NULL,
|
||||||
|
null=True,
|
||||||
|
blank=True,
|
||||||
|
related_name='placeimages'
|
||||||
|
)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
"""
|
"""
|
||||||
Returning the name of the corresponding place + id
|
Returning the name of the corresponding place + id
|
||||||
|
@ -84,7 +84,7 @@ class SubmittableTestCase(ModelTestCase):
|
|||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
submitted_by.remote_field.on_delete,
|
submitted_by.remote_field.on_delete,
|
||||||
models.SET_NULL,
|
models.SET_NULL
|
||||||
msg='Expecting %s to be null when reference is delete (models.SET_NULL)' % (
|
msg='Expecting %s to be null when reference is delete (models.SET_NULL)' % (
|
||||||
str(submitted_by)
|
str(submitted_by)
|
||||||
)
|
)
|
||||||
|
@ -1,14 +1,17 @@
|
|||||||
from django.test import TestCase
|
from django.test import Client
|
||||||
|
|
||||||
class ViewTestCase(TestCase):
|
class ViewTestCaseMixin:
|
||||||
'''
|
'''
|
||||||
This is a mixni for testing views. It provides functionality to
|
This is a mixni for testing views. It provides functionality to
|
||||||
test the context, forms and HTTP Response of responses.
|
test the context, forms and HTTP Response of responses.
|
||||||
All methods take responses, so this base class can be used
|
Also works with django's ReqeustFactory and provides a self.client
|
||||||
with django's RequestFactory and Test-Client
|
|
||||||
'''
|
'''
|
||||||
view = None
|
view = None
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.view_name = self.view.__name__
|
||||||
|
self.client = Client()
|
||||||
|
|
||||||
def assertContext(self, response, key, value=None):
|
def assertContext(self, response, key, value=None):
|
||||||
'''
|
'''
|
||||||
Checks weather the response's context has the given key
|
Checks weather the response's context has the given key
|
||||||
@ -17,7 +20,7 @@ class ViewTestCase(TestCase):
|
|||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
key in response.context,
|
key in response.context,
|
||||||
msg='Expecting the context of %s to have an attribute \'%s\'' % (
|
msg='Expecting the context of %s to have an attribute \'%s\'' % (
|
||||||
self.view.__name__,
|
self.view_name,
|
||||||
key
|
key
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -27,24 +30,24 @@ class ViewTestCase(TestCase):
|
|||||||
value,
|
value,
|
||||||
response.context[key],
|
response.context[key],
|
||||||
msg='Expecting the context of %s to have %s set to \'%s\'' % (
|
msg='Expecting the context of %s to have %s set to \'%s\'' % (
|
||||||
self.view.__name__,
|
self.view_name,
|
||||||
key,
|
key,
|
||||||
str(value)
|
str(value)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def assertHasForm(self, response, key, form_class):
|
def assertHasForm(self, response, context_key, form_class):
|
||||||
'''
|
'''
|
||||||
Checks if response has a form under the given key and if
|
Checks if response has a form under the given key and if
|
||||||
the forms class matches.
|
the forms class matches.
|
||||||
'''
|
'''
|
||||||
self.assertContext(response, key)
|
self.assertContext(response, context_key)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
type(response.context[key]),
|
type(response.context[context_key]),
|
||||||
form_class,
|
form_class,
|
||||||
msg='Expecting %s\'s context.%s to be of the type %s' % (
|
msg='Expecting %s\'s context.%s to be of the type %s' % (
|
||||||
self.view.__name__,
|
self.view_name,
|
||||||
key,
|
context_key,
|
||||||
form_class.__name__
|
form_class.__name__
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -60,31 +63,6 @@ class ViewTestCase(TestCase):
|
|||||||
response.status_code
|
response.status_code
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def assertHttpRedirect(self, response, redirect_to=None):
|
|
||||||
'''
|
|
||||||
Checks weather the response redirected, and if passed,
|
|
||||||
if it redirected to the expected loaction
|
|
||||||
'''
|
|
||||||
|
|
||||||
self.assertTrue(
|
|
||||||
300 <= response.status_code < 400,
|
|
||||||
'Expected an HTTP 3XX (redirect) response, but got HTTP %s' %
|
|
||||||
response.status_code
|
|
||||||
)
|
|
||||||
self.assertTrue(
|
|
||||||
'location' in response,
|
|
||||||
msg='Expecting a redirect to have an location, got none'
|
|
||||||
)
|
|
||||||
if redirect_to:
|
|
||||||
self.assertEqual(
|
|
||||||
response['location'],
|
|
||||||
redirect_to,
|
|
||||||
msg='Expecing the response to redirect to %s, where redirected to %s instea' % (
|
|
||||||
str(redirect_to),
|
|
||||||
str(response['location'])
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
def assertHttpOK(self, response):
|
def assertHttpOK(self, response):
|
||||||
self.assertHttpCode(response, 200)
|
self.assertHttpCode(response, 200)
|
||||||
@ -92,6 +70,28 @@ class ViewTestCase(TestCase):
|
|||||||
def assertHttpCreated(self, response):
|
def assertHttpCreated(self, response):
|
||||||
self.assertHttpCode(response, 201)
|
self.assertHttpCode(response, 201)
|
||||||
|
|
||||||
|
def assertHttpRedirect(self, response, redirect_to=None):
|
||||||
|
'''
|
||||||
|
Checks weather the response redirected, and if passed,
|
||||||
|
if it redirected to the expected loaction
|
||||||
|
'''
|
||||||
|
|
||||||
|
self.assertTrue(
|
||||||
|
300 <= response.status_code < 400,
|
||||||
|
'Expected an HTTP 3XX (redirect) response, but got HTTP %s' %
|
||||||
|
response.status_code
|
||||||
|
)
|
||||||
|
if redirect_to:
|
||||||
|
self.assertEqual(
|
||||||
|
response['Location'],
|
||||||
|
redirect_to,
|
||||||
|
msg='Expecing the response to redirect to %s, where redirected to %s instea' % (
|
||||||
|
str(redirect_to),
|
||||||
|
str(response['Location'])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def assertHttpBadRequest(self, response):
|
def assertHttpBadRequest(self, response):
|
||||||
self.assertHttpCode(response, 400)
|
self.assertHttpCode(response, 400)
|
||||||
|
|
||||||
|
@ -7,9 +7,9 @@ from django.contrib.messages.storage.fallback import FallbackStorage
|
|||||||
|
|
||||||
from lostplaces_app.models import Place
|
from lostplaces_app.models import Place
|
||||||
from lostplaces_app.views import IsAuthenticatedMixin
|
from lostplaces_app.views import IsAuthenticatedMixin
|
||||||
from lostplaces_app.tests.views import ViewTestCase
|
from lostplaces_app.tests.views import ViewTestCaseMixin
|
||||||
|
|
||||||
class TestIsAuthenticated(ViewTestCase):
|
class TestIsAuthenticated(ViewTestCaseMixin, TestCase):
|
||||||
view = IsAuthenticatedMixin
|
view = IsAuthenticatedMixin
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -18,9 +18,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('/')
|
||||||
@ -63,9 +60,6 @@ class TestIsPlaceSubmitterMixin(TestCase):
|
|||||||
)
|
)
|
||||||
place.tags.add('I a tag', 'testlocation')
|
place.tags.add('I a tag', 'testlocation')
|
||||||
place.save()
|
place.save()
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
self.client = Client()
|
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self. client = Client()
|
self. client = Client()
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
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
|
||||||
|
|
||||||
@ -10,9 +10,10 @@ from lostplaces_app.views import (
|
|||||||
PlaceListView
|
PlaceListView
|
||||||
)
|
)
|
||||||
from lostplaces_app.forms import PlaceImageCreateForm, PlaceForm
|
from lostplaces_app.forms import PlaceImageCreateForm, PlaceForm
|
||||||
from lostplaces_app.tests.views import ViewTestCase
|
from lostplaces_app.tests.views import ViewTestCaseMixin
|
||||||
|
|
||||||
class TestPlaceCreateView(ViewTestCase):
|
class TestPlaceCreateView(ViewTestCaseMixin, TestCase):
|
||||||
|
|
||||||
view = PlaceCreateView
|
view = PlaceCreateView
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -34,9 +35,6 @@ class TestPlaceCreateView(ViewTestCase):
|
|||||||
place.tags.add('I a tag', 'testlocation')
|
place.tags.add('I a tag', 'testlocation')
|
||||||
place.save()
|
place.save()
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
self.client = Client()
|
|
||||||
|
|
||||||
def test_has_forms(self):
|
def test_has_forms(self):
|
||||||
self.client.login(username='testpeter', password='Develop123')
|
self.client.login(username='testpeter', password='Develop123')
|
||||||
response = self.client.get(reverse_lazy('place_create'))
|
response = self.client.get(reverse_lazy('place_create'))
|
||||||
@ -44,7 +42,7 @@ class TestPlaceCreateView(ViewTestCase):
|
|||||||
self.assertHasForm(response, 'place_image_form', PlaceImageCreateForm)
|
self.assertHasForm(response, 'place_image_form', PlaceImageCreateForm)
|
||||||
self.assertHasForm(response, 'place_form', PlaceForm)
|
self.assertHasForm(response, 'place_form', PlaceForm)
|
||||||
|
|
||||||
class TestPlaceListView(ViewTestCase):
|
class TestPlaceListView(ViewTestCaseMixin, TestCase):
|
||||||
view = PlaceListView
|
view = PlaceListView
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -66,17 +64,10 @@ class TestPlaceListView(ViewTestCase):
|
|||||||
place.tags.add('I a tag', 'testlocation')
|
place.tags.add('I a tag', 'testlocation')
|
||||||
place.save()
|
place.save()
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
self.client = Client()
|
|
||||||
|
|
||||||
def test_list_view(self):
|
def test_list_view(self):
|
||||||
self.client.login(username='testpeter', password='Develop123')
|
self.client.login(username='testpeter', password='Develop123')
|
||||||
response = self.client.get(reverse_lazy('place_list'))
|
response = self.client.get(reverse_lazy('place_list'))
|
||||||
|
|
||||||
self.assertContext(response, 'map_config')
|
self.assertContext(response, 'map_config')
|
||||||
|
|
||||||
def test_test(self):
|
|
||||||
response = self.client.get(reverse_lazy('place_list'))
|
|
||||||
print(response['location'])
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user