Compare commits
No commits in common. "b52d96a55e017bfce18e63a0c0d21c93a8416587" and "27520c7ca482e67892ce1ef3d2251e4458be5126" have entirely different histories.
b52d96a55e
...
27520c7ca4
@ -33,46 +33,47 @@ class ModelTestCase(TestCase):
|
|||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
type(field), field_class,
|
type(field), field_class,
|
||||||
msg='Expecting type of %s to be %s' % (
|
msg='Expecting type of %s.%s to be %s' % (
|
||||||
str(field),
|
self.model.__name__,
|
||||||
|
field_name,
|
||||||
field_class.__name__
|
field_class.__name__
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
for key, value in must_have.items():
|
for key, value in must_have.items():
|
||||||
if value:
|
if value:
|
||||||
self.assertEqual(
|
self.assertEqual(getattr(field, key), value,
|
||||||
getattr(field, key), value,
|
msg='Expeting %s.%s.%s to be \'%s\'' % (
|
||||||
msg='Expeting the value of %s %s to be \'%s\'' % (
|
self.model.__name__,
|
||||||
str(field),
|
field_name,
|
||||||
key,
|
key,
|
||||||
value
|
value
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self.assertTrue(
|
self.assertTrue(hasattr(field, key),
|
||||||
hasattr(field, key),
|
msg='Expeting %s.%s to have \'%s\'' % (
|
||||||
msg='Expeting %s to have \'%s\'' % (
|
self.model.__name__,
|
||||||
str(field),
|
field_name,
|
||||||
key
|
key
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
for key, value in must_not_have.items():
|
for key, value in must_not_have.items():
|
||||||
if value:
|
if value:
|
||||||
self.assertTrue(
|
self.assertTrue(getattr(field, key) != value,
|
||||||
getattr(field, key) != value,
|
msg='Expeting %s.%s.%s to not be \'%s\'' % (
|
||||||
msg='Expeting the value of %s %s to not be \'%s\'' % (
|
self.model.__name__,
|
||||||
str(field),
|
field_name,
|
||||||
key,
|
key,
|
||||||
value
|
value
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self.assertFalse(
|
self.assertFalse(hasattr(field, value),
|
||||||
hasattr(field, value),
|
msg='Expeting %s.%s to not have \'%s\'' % (
|
||||||
msg='Expeting %s to not have \'%s\'' % (
|
self.model.__name__,
|
||||||
str(field),
|
field_name,
|
||||||
key
|
key
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -88,8 +89,9 @@ class ModelTestCase(TestCase):
|
|||||||
field_name, models.CharField, must_have, must_hot_have)
|
field_name, models.CharField, must_have, must_hot_have)
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
field.max_length in range(min_length, max_length),
|
field.max_length in range(min_length, max_length),
|
||||||
msg='Expeting %s max_length to be in the range of %d and %d' % (
|
msg='Expeting %s.%s field max_length to be in the range of %d and %d' % (
|
||||||
str(field),
|
self.model.__name__,
|
||||||
|
field_name,
|
||||||
min_length,
|
min_length,
|
||||||
max_length
|
max_length
|
||||||
)
|
)
|
||||||
@ -109,15 +111,17 @@ class ModelTestCase(TestCase):
|
|||||||
if min_value:
|
if min_value:
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
len(field.validators) >= 1,
|
len(field.validators) >= 1,
|
||||||
msg='Expecting the first valiator of %s to check the minimum' % (
|
msg='Expecting the first valiator of %s.%s to check the minimum' % (
|
||||||
str(field)
|
self.model.__name__,
|
||||||
|
field_name
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
field.validators[0].limit_value,
|
field.validators[0].limit_value,
|
||||||
min_value,
|
min_value,
|
||||||
msg='Expecting the min value of %s min to be at least %d' % (
|
msg='Expecting the min value of %s.%s min to be at least %d' % (
|
||||||
str(field),
|
self.model.__name__,
|
||||||
|
field_name,
|
||||||
min_value
|
min_value
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -127,15 +131,40 @@ class ModelTestCase(TestCase):
|
|||||||
index += 1
|
index += 1
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
len(field.validators) >= index+1,
|
len(field.validators) >= index+1,
|
||||||
msg='Expecting the second valiator of %s to check the maximum' % (
|
msg='Expecting the second valiator of %s.%s to check the maximum' % (
|
||||||
str(field)
|
self.model.__name__,
|
||||||
|
field_name
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
field.validators[1].limit_value,
|
field.validators[1].limit_value,
|
||||||
max_value,
|
max_value,
|
||||||
msg='Expecting the max value of %s min to be at most %d' % (
|
msg='Expecting the max value of %s.%s min to be at most %d' % (
|
||||||
str(field),
|
self.model.__name__,
|
||||||
|
field_name,
|
||||||
max_value
|
max_value
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class SubmittableTestCase(ModelTestCase):
|
||||||
|
related_name = None
|
||||||
|
nullable = False
|
||||||
|
|
||||||
|
def test_submitted_when(self):
|
||||||
|
submitted_when = self.assertField(
|
||||||
|
'submitted_when',
|
||||||
|
models.DateTimeField,
|
||||||
|
must_have={'auto_now_add': True}
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_submitted_by(self):
|
||||||
|
submitted_by = self.assertField('submitted_by', models.ForeignKey)
|
||||||
|
if self.related_name:
|
||||||
|
self.assertEqual(
|
||||||
|
submitted_by.remote_field.related_name, self.related_name)
|
||||||
|
if self.nullable:
|
||||||
|
self.assertTrue(submitted_by.null,)
|
||||||
|
self.assertTrue(submitted_by.blank)
|
||||||
|
self.assertEqual(
|
||||||
|
submitted_by.remote_field.on_delete, models.SET_NULL)
|
||||||
|
@ -4,11 +4,7 @@ from django.test import TestCase
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
from lostplaces_app.models import (
|
from lostplaces_app.models import Place, Taggable, MapablePoint
|
||||||
Taggable,
|
|
||||||
MapablePoint,
|
|
||||||
Submittable
|
|
||||||
)
|
|
||||||
from lostplaces_app.tests.models import ModelTestCase
|
from lostplaces_app.tests.models import ModelTestCase
|
||||||
|
|
||||||
from taggit.managers import TaggableManager
|
from taggit.managers import TaggableManager
|
||||||
@ -46,47 +42,3 @@ class MapablePointTestCase(ModelTestCase):
|
|||||||
min_value=-180,
|
min_value=-180,
|
||||||
max_value=180
|
max_value=180
|
||||||
)
|
)
|
||||||
|
|
||||||
class SubmittableTestCase(ModelTestCase):
|
|
||||||
model = Submittable
|
|
||||||
|
|
||||||
def test_submitted_when(self):
|
|
||||||
self.assertField(
|
|
||||||
field_name='submitted_when',
|
|
||||||
field_class=models.DateTimeField,
|
|
||||||
must_have={'auto_now_add': True}
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_submitted_by(self):
|
|
||||||
submitted_by = self.assertField(
|
|
||||||
field_name='submitted_by',
|
|
||||||
field_class=models.ForeignKey
|
|
||||||
)
|
|
||||||
self.assertEqual(
|
|
||||||
submitted_by.remote_field.related_name,
|
|
||||||
'%(class)s',
|
|
||||||
msg='Expecting the related_name of %s to be \'%%(class)s\', got %s' % (
|
|
||||||
str(submitted_by),
|
|
||||||
submitted_by.remote_field.related_name
|
|
||||||
)
|
|
||||||
)
|
|
||||||
self.assertTrue(
|
|
||||||
submitted_by.null,
|
|
||||||
msg='Expecting %s to has null=True' % (
|
|
||||||
str(submitted_by)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
self.assertTrue(
|
|
||||||
submitted_by.blank,
|
|
||||||
msg='Expecting %s to has blank=True' % (
|
|
||||||
str(submitted_by)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
self.assertEqual(
|
|
||||||
submitted_by.remote_field.on_delete,
|
|
||||||
models.SET_NULL
|
|
||||||
msg='Expecting %s to be null when reference is delete (models.SET_NULL)' % (
|
|
||||||
str(submitted_by)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
@ -10,11 +10,11 @@ from django.conf import settings
|
|||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
from lostplaces_app.models import PlaceImage, Place
|
from lostplaces_app.models import PlaceImage, Place
|
||||||
from lostplaces_app.tests.models import ModelTestCase
|
from lostplaces_app.tests.models import SubmittableTestCase
|
||||||
|
|
||||||
from easy_thumbnails.fields import ThumbnailerImageField
|
from easy_thumbnails.fields import ThumbnailerImageField
|
||||||
|
|
||||||
class PlaceImageTestCase(ModelTestCase):
|
class TestPlaceImage(SubmittableTestCase, TestCase):
|
||||||
model = PlaceImage
|
model = PlaceImage
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -59,9 +59,6 @@ class PlaceImageTestCase(ModelTestCase):
|
|||||||
submitted_by=user.explorer
|
submitted_by=user.explorer
|
||||||
)
|
)
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
self.place_image = PlaceImage.objects.get(id=1)
|
|
||||||
|
|
||||||
def test_description(self):
|
def test_description(self):
|
||||||
self.assertField('description', models.TextField)
|
self.assertField('description', models.TextField)
|
||||||
|
|
||||||
@ -71,37 +68,39 @@ class PlaceImageTestCase(ModelTestCase):
|
|||||||
def test_place(self):
|
def test_place(self):
|
||||||
field = self.assertField('place', models.ForeignKey)
|
field = self.assertField('place', models.ForeignKey)
|
||||||
self.assertEqual(field.remote_field.on_delete, models.CASCADE,
|
self.assertEqual(field.remote_field.on_delete, models.CASCADE,
|
||||||
msg='Expecting the deletion of %s to be cascading' % (
|
msg='%s.%s deleting of %s should be cascadinf' % (
|
||||||
str(field)
|
self.model_name,
|
||||||
|
'place',
|
||||||
|
self.model_name
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
expected_related_name = 'placeimages'
|
self.assertEqual(field.remote_field.related_name, 'images',
|
||||||
self.assertEqual(field.remote_field.related_name, expected_related_name,
|
msg='%s.%s related name should be images' % (
|
||||||
msg='Expecting the related name of %s to be %s' % (
|
self.model_name,
|
||||||
str(field),
|
'place'
|
||||||
expected_related_name
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_str(self):
|
def test_str(self):
|
||||||
self.assertTrue(self.place_image.place.name.lower() in str(self.place_image).lower(),
|
place_image = self.object
|
||||||
|
self.assertTrue(place_image.place.name.lower() in str(place_image).lower(),
|
||||||
msg='Expecting %s.__str__ to contain the name of the place' % (
|
msg='Expecting %s.__str__ to contain the name of the place' % (
|
||||||
self.model.__name__
|
self.model_name
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_change_filename(self):
|
def test_change_filename(self):
|
||||||
path = self.place_image.filename.path
|
path = self.object.filename.path
|
||||||
self.place_image.filename = os.path.join(settings.MEDIA_ROOT, 'im_a_image_changed.jpeg')
|
self.object.filename = os.path.join(settings.MEDIA_ROOT, 'im_a_image_changed.jpeg')
|
||||||
self.place_image.save()
|
self.object.save()
|
||||||
self.assertFalse(
|
self.assertFalse(
|
||||||
os.path.isfile(path),
|
os.path.isfile(path),
|
||||||
msg='Expecting the old file of an place_image to be deleteed when an place_image file is changed'
|
msg='Expecting the old file of an place_image to be deleteed when an place_image file is changed'
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_deletion(self):
|
def test_deletion(self):
|
||||||
path = self.place_image.filename.path
|
path = self.object.filename.path
|
||||||
self.place_image.delete()
|
self.object.delete()
|
||||||
self.assertFalse(
|
self.assertFalse(
|
||||||
os.path.isfile(path),
|
os.path.isfile(path),
|
||||||
msg='Expecting the file of an place_image to be deleteed when an place_image is deleted'
|
msg='Expecting the file of an place_image to be deleteed when an place_image is deleted'
|
||||||
|
@ -6,9 +6,9 @@ from django.db import models
|
|||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
from lostplaces_app.models import Place
|
from lostplaces_app.models import Place
|
||||||
from lostplaces_app.tests.models import ModelTestCase
|
from lostplaces_app.tests.models import SubmittableTestCase
|
||||||
|
|
||||||
class PlaceTestCase(ModelTestCase):
|
class PlaceTestCase(SubmittableTestCase, TestCase):
|
||||||
model = Place
|
model = Place
|
||||||
related_name = 'places'
|
related_name = 'places'
|
||||||
nullable = True
|
nullable = True
|
||||||
@ -33,9 +33,6 @@ class PlaceTestCase(ModelTestCase):
|
|||||||
place.save()
|
place.save()
|
||||||
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
self.place = Place.objects.get(id=1)
|
|
||||||
|
|
||||||
def test_location(self):
|
def test_location(self):
|
||||||
self.assertCharField(
|
self.assertCharField(
|
||||||
field_name='location',
|
field_name='location',
|
||||||
@ -71,12 +68,12 @@ class PlaceTestCase(ModelTestCase):
|
|||||||
|
|
||||||
self.assertEqual(avg_latlon['latitude'], 5.5,
|
self.assertEqual(avg_latlon['latitude'], 5.5,
|
||||||
msg='%s: average latitude missmatch' % (
|
msg='%s: average latitude missmatch' % (
|
||||||
self.model.__name__
|
self.model_name
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.assertEqual(avg_latlon['longitude'], 14.5,
|
self.assertEqual(avg_latlon['longitude'], 14.5,
|
||||||
msg='%s: average longitude missmatch' % (
|
msg='%s: average longitude missmatch' % (
|
||||||
self.model.__name__
|
self.model_name
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -89,12 +86,12 @@ class PlaceTestCase(ModelTestCase):
|
|||||||
avg_latlon = Place.average_latlon([place])
|
avg_latlon = Place.average_latlon([place])
|
||||||
self.assertEqual(avg_latlon['latitude'], place.latitude,
|
self.assertEqual(avg_latlon['latitude'], place.latitude,
|
||||||
msg='%s:(one place) average latitude missmatch' % (
|
msg='%s:(one place) average latitude missmatch' % (
|
||||||
self.model.__name__
|
self.model_name
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.assertEqual(avg_latlon['longitude'], place.longitude,
|
self.assertEqual(avg_latlon['longitude'], place.longitude,
|
||||||
msg='%s: (one place) average longitude missmatch' % (
|
msg='%s: (one place) average longitude missmatch' % (
|
||||||
self.model.__name__
|
self.model_name
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -106,19 +103,19 @@ class PlaceTestCase(ModelTestCase):
|
|||||||
avg_latlon = Place.average_latlon([])
|
avg_latlon = Place.average_latlon([])
|
||||||
self.assertEqual(avg_latlon['latitude'], 0,
|
self.assertEqual(avg_latlon['latitude'], 0,
|
||||||
msg='%s: (no places) average latitude missmatch' % (
|
msg='%s: (no places) average latitude missmatch' % (
|
||||||
self.model.__name__
|
self.model_name
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.assertEqual(avg_latlon['longitude'], 0,
|
self.assertEqual(avg_latlon['longitude'], 0,
|
||||||
msg='%s: a(no places) verage longitude missmatch' % (
|
msg='%s: a(no places) verage longitude missmatch' % (
|
||||||
self.model.__name__
|
self.model_name
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_str(self):
|
def test_str(self):
|
||||||
place = self.place
|
place = self.object
|
||||||
self.assertTrue(place.name.lower() in str(place).lower(),
|
self.assertTrue(place.name.lower() in str(place).lower(),
|
||||||
msg='Expecting %s.__str__ to contain the name' % (
|
msg='Expecting %s.__str__ to contain the name' % (
|
||||||
self.model.__name__
|
self.model_name
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -14,39 +14,36 @@ class VoucheTestCase(ModelTestCase):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def setUpTestData(cls):
|
def setUpTestData(cls):
|
||||||
Voucher.objects.create(
|
Voucher.objects.create(
|
||||||
code='ayDraJCCwfhcFiYmSR5GrcjcchDfcahv',
|
code='ayDraJCCwfhcFiYmSR5GrcjcchDfcahv',
|
||||||
expires_when=timezone.now() + datetime.timedelta(days=1)
|
expires_when=timezone.now() + datetime.timedelta(days=1)
|
||||||
)
|
)
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
self.voucher = Voucher.objects.get(id=1)
|
|
||||||
|
|
||||||
def test_voucher_code(self):
|
def test_voucher_code(self):
|
||||||
self.assertCharField(
|
self.assertCharField(
|
||||||
field_name='code',
|
'code',
|
||||||
min_length=10,
|
10,
|
||||||
max_length=100,
|
100,
|
||||||
must_have={'unique': True}
|
must_have={'unique': True}
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_voucher_created(self):
|
def test_voucher_created(self):
|
||||||
self.assertField(
|
self.assertField(
|
||||||
field_name='created_when',
|
'created_when',
|
||||||
field_class=models.DateTimeField,
|
models.DateTimeField,
|
||||||
must_have={'auto_now_add': True}
|
must_have={'auto_now_add': True}
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_voucher_expires(self):
|
def test_voucher_expires(self):
|
||||||
self.assertField(
|
self.assertField(
|
||||||
field_name='expires_when',
|
'expires_when',
|
||||||
field_class=models.DateTimeField,
|
models.DateTimeField,
|
||||||
must_not_have={'auto_now_add': True}
|
must_not_have={'auto_now_add': True}
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_str(self):
|
def test_str(self):
|
||||||
self.assertTrue(
|
voucher = self.object
|
||||||
self.voucher.code.lower() in str(self.voucher).lower(),
|
self.assertTrue(voucher.code.lower() in str(voucher).lower(),
|
||||||
msg='Expecting %s.__str__ to contain the voucher code' % (
|
msg='Expecting %s.__str__ to contain the voucher code' % (
|
||||||
self.model.__name__
|
self.model_name
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user