Testing Abstract classes
This commit is contained in:
parent
3780aa6cf1
commit
e77edf18ac
@ -7,12 +7,13 @@ from django.test import TestCase
|
||||
|
||||
class ModelTestCase:
|
||||
'''
|
||||
Base class for Lostplaces models
|
||||
Base class for ModelTests
|
||||
'''
|
||||
model = None
|
||||
model_name = None
|
||||
|
||||
def setUp(self):
|
||||
if not self.model._meta.abstract:
|
||||
self.object = self.model.objects.get(id=1)
|
||||
self.model_name = self.model.__name__
|
||||
|
||||
@ -26,7 +27,7 @@ class ModelTestCase:
|
||||
something that fullfills value == False (i.e. '' or 0)
|
||||
'''
|
||||
try:
|
||||
field = self.object._meta.get_field(field_name)
|
||||
field = self.model._meta.get_field(field_name)
|
||||
except FieldDoesNotExist:
|
||||
self.fail(
|
||||
'Expecting %s to have a field named \'%s\'' % (
|
||||
|
@ -0,0 +1,44 @@
|
||||
import datetime
|
||||
|
||||
from django.test import TestCase
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
from lostplaces_app.models import Place, Taggable, MapablePoint
|
||||
from lostplaces_app.tests.models import ModelTestCase
|
||||
|
||||
from taggit.managers import TaggableManager
|
||||
|
||||
|
||||
class TaggableTestCase(ModelTestCase, TestCase):
|
||||
|
||||
model = Taggable
|
||||
|
||||
def test_tags(self):
|
||||
self._test_field('tags', TaggableManager)
|
||||
|
||||
|
||||
class MapablePointTestCase(ModelTestCase, TestCase):
|
||||
|
||||
model = MapablePoint
|
||||
|
||||
def test_name(self):
|
||||
self._test_char_field(
|
||||
field_name='name',
|
||||
min_length=10,
|
||||
max_length=100
|
||||
)
|
||||
|
||||
def test_latitude(self):
|
||||
self._test_float_field(
|
||||
field_name='latitude',
|
||||
min_value=-90,
|
||||
max_value=90
|
||||
)
|
||||
|
||||
def test_longitude(self):
|
||||
self._test_float_field(
|
||||
field_name='longitude',
|
||||
min_value=-180,
|
||||
max_value=180
|
||||
)
|
@ -8,9 +8,6 @@ from django.contrib.auth.models import User
|
||||
from lostplaces_app.models import Place
|
||||
from lostplaces_app.tests.models import SubmittableTestCase
|
||||
|
||||
|
||||
from taggit.managers import TaggableManager
|
||||
|
||||
class PlaceTestCase(SubmittableTestCase, TestCase):
|
||||
model = Place
|
||||
related_name = 'places'
|
||||
@ -35,12 +32,6 @@ class PlaceTestCase(SubmittableTestCase, TestCase):
|
||||
place.tags.add('I a tag', 'testlocation')
|
||||
place.save()
|
||||
|
||||
def test_name_field(self):
|
||||
self._test_char_field(
|
||||
field_name='name',
|
||||
min_length=10,
|
||||
max_length=100
|
||||
)
|
||||
|
||||
def test_location(self):
|
||||
self._test_char_field(
|
||||
@ -49,26 +40,9 @@ class PlaceTestCase(SubmittableTestCase, TestCase):
|
||||
max_length=100
|
||||
)
|
||||
|
||||
def test_latitude(self):
|
||||
self._test_float_field(
|
||||
field_name='latitude',
|
||||
min_value=-90,
|
||||
max_value=90
|
||||
)
|
||||
|
||||
def test_longitude(self):
|
||||
self._test_float_field(
|
||||
field_name='longitude',
|
||||
min_value=-180,
|
||||
max_value=180
|
||||
)
|
||||
|
||||
def test_decsription(self):
|
||||
self._test_field('description', models.TextField)
|
||||
|
||||
def test_tags(self):
|
||||
self._test_field('tags', TaggableManager)
|
||||
|
||||
def test_average_latlon(self):
|
||||
'''
|
||||
Tests the average latitude/longitude calculation of a list
|
||||
|
Loading…
Reference in New Issue
Block a user