Commenting tests

This commit is contained in:
reverend 2020-09-03 20:24:20 +02:00
parent 2837999a5b
commit 1dee72cd15

View File

@ -23,9 +23,16 @@ def mock_place():
return place
class ModelTest:
'''
Base class for Lostplaces models
'''
model_name = None
def _test_field(self, field_name, field_class):
'''
Tests if a field exists under the given name and
if the field is of the right type
'''
field = self.place._meta.get_field(field_name)
self.assertTrue(
field,
@ -45,6 +52,10 @@ class ModelTest:
def _test_char_field(self, field_name, min_length, max_length):
'''
Tests if the given field is a char field and if its max_length
is in min_length and max_legth
'''
field = self._test_field(field_name, models.CharField)
self.assertEqual(
type(field), models.CharField,
@ -64,6 +75,14 @@ class ModelTest:
)
def _test_float_field(self, field_name, min_value=None, max_value=None):
'''
Tests if the field is a floatfield. If min_value and/or max_value are passed,
the validators of the field are also checked. The validator list of the field should
look like
[MinValueValidator, MayValueValidator], if both values are passed,
[MinValueValidator] if only min_value is passed,
[MaxValueValidator] if only max_value is passed
'''
field = self._test_field(field_name, models.FloatField)
if min_value:
self.assertTrue(
@ -143,6 +162,10 @@ class PlaceTestCase(ModelTest, TestSubmittable, TestCase):
self._test_field('tags', TaggableManager)
def test_average_latlon(self):
'''
Tests the average latitude/longitude calculation of a list
of 10 places
'''
place_list = []
for i in range(10):
place = mock_place()
@ -163,6 +186,10 @@ class PlaceTestCase(ModelTest, TestSubmittable, TestCase):
)
def test_average_latlon_one_place(self):
'''
Tests the average latitude/longitude calculation of a list
of one place
'''
place = mock_place()
avg_latlon = Place.average_latlon([place])
self.assertEqual(avg_latlon[0], place.latitude,
@ -177,6 +204,10 @@ class PlaceTestCase(ModelTest, TestSubmittable, TestCase):
)
def test_average_latlon_no_places(self):
'''
Tests the average latitude/longitude calculation of
an empty list
'''
avg_latlon = Place.average_latlon([])
self.assertEqual(avg_latlon[0], 0,
msg='%s: (no places) average latitude missmatch' % (