docstring + rename some mixins
This commit is contained in:
parent
fdce944820
commit
814199da71
2 changed files with 40 additions and 14 deletions
|
@ -5,7 +5,7 @@ from rest_framework.test import APITestCase
|
||||||
from event.models import Event, Place, ActivityTag, ActivityTemplate
|
from event.models import Event, Place, ActivityTag, ActivityTemplate
|
||||||
|
|
||||||
from api.event.serializers import ActivityTemplateSerializer, EventSerializer
|
from api.event.serializers import ActivityTemplateSerializer, EventSerializer
|
||||||
from api.test_mixins import EventBasedModelMixin, EventSpecificMixin,\
|
from api.test_mixins import EventBasedModelTestMixin, EventSpecificTestMixin,\
|
||||||
ModelTestMixin
|
ModelTestMixin
|
||||||
|
|
||||||
User = get_user_model()
|
User = get_user_model()
|
||||||
|
@ -22,7 +22,7 @@ class EventTest(ModelTestMixin, APITestCase):
|
||||||
serializer = EventSerializer
|
serializer = EventSerializer
|
||||||
|
|
||||||
|
|
||||||
class ActivityTemplateTest(EventBasedModelMixin, APITestCase):
|
class ActivityTemplateTest(EventBasedModelTestMixin, APITestCase):
|
||||||
model = ActivityTemplate
|
model = ActivityTemplate
|
||||||
base_name = 'event-activitytemplate'
|
base_name = 'event-activitytemplate'
|
||||||
initial_count = 1
|
initial_count = 1
|
||||||
|
@ -44,13 +44,13 @@ class ActivityTemplateTest(EventBasedModelMixin, APITestCase):
|
||||||
self.assertEqual(instance.tags.count(), 2)
|
self.assertEqual(instance.tags.count(), 2)
|
||||||
|
|
||||||
|
|
||||||
class EventSpecficTagTest(EventSpecificMixin, APITestCase):
|
class EventSpecficTagTest(EventSpecificTestMixin, APITestCase):
|
||||||
model = ActivityTag
|
model = ActivityTag
|
||||||
root_base_name = 'activitytag'
|
root_base_name = 'activitytag'
|
||||||
event_base_name = 'event-activitytag'
|
event_base_name = 'event-activitytag'
|
||||||
|
|
||||||
|
|
||||||
class EventSpecficPlaceTest(EventSpecificMixin, APITestCase):
|
class EventSpecficPlaceTest(EventSpecificTestMixin, APITestCase):
|
||||||
model = Place
|
model = Place
|
||||||
root_base_name = 'place'
|
root_base_name = 'place'
|
||||||
event_base_name = 'event-place'
|
event_base_name = 'event-place'
|
||||||
|
|
|
@ -14,6 +14,9 @@ User = get_user_model()
|
||||||
|
|
||||||
|
|
||||||
class DataBaseMixin(object):
|
class DataBaseMixin(object):
|
||||||
|
"""
|
||||||
|
provides a datatabse for API tests
|
||||||
|
"""
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpTestData(cls):
|
def setUpTestData(cls):
|
||||||
# Users
|
# Users
|
||||||
|
@ -49,23 +52,35 @@ class DataBaseMixin(object):
|
||||||
self.act_temp1.tags.add(self.tag1)
|
self.act_temp1.tags.add(self.tag1)
|
||||||
|
|
||||||
|
|
||||||
class EventBasedModelMixin(DataBaseMixin):
|
class EventBasedModelTestMixin(DataBaseMixin):
|
||||||
"""
|
"""
|
||||||
Note : need to define : `model`, `base_name`, `initial_count`,
|
Note : need to define : `model`, `base_name`, `initial_count`,
|
||||||
`data_creation`, `instance_name`, `field_tested`, `serializer`
|
`data_creation`, `instance_name`, `field_tested`, `serializer`
|
||||||
|
|
||||||
|
tests for models served by the API that are related to an event
|
||||||
|
and whose API urls are nested under ../event/<event_id>/%model
|
||||||
"""
|
"""
|
||||||
def test_user_create_extra(self):
|
def user_create_extra(self):
|
||||||
|
"""
|
||||||
|
extra test in creation by a permited user
|
||||||
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def pre_update_extra(self, data):
|
def pre_update_extra(self, data):
|
||||||
|
"""
|
||||||
|
extra modification for the data sent for update
|
||||||
|
"""
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def post_update_extra(self):
|
def post_update_extra(self):
|
||||||
|
"""
|
||||||
|
extra test for updated model
|
||||||
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_user_create(self):
|
def test_user_create(self):
|
||||||
"""
|
"""
|
||||||
ensure we can create a new %model object using API
|
ensure a permited user can create a new %model object using API
|
||||||
"""
|
"""
|
||||||
data = getattr(self, self.data_creation)
|
data = getattr(self, self.data_creation)
|
||||||
|
|
||||||
|
@ -80,11 +95,11 @@ class EventBasedModelMixin(DataBaseMixin):
|
||||||
self.assertEqual(self.model.objects.get(id=self.initial_count+1).event,
|
self.assertEqual(self.model.objects.get(id=self.initial_count+1).event,
|
||||||
self.event1)
|
self.event1)
|
||||||
|
|
||||||
self.test_create_extra()
|
self.user_create_extra()
|
||||||
|
|
||||||
def test_user_update(self):
|
def test_user_update(self):
|
||||||
"""
|
"""
|
||||||
ensure we can update an %model object using API
|
ensure a permited user can update a new %model object using API
|
||||||
"""
|
"""
|
||||||
instance = getattr(self, self.instance_name)
|
instance = getattr(self, self.instance_name)
|
||||||
factory = APIRequestFactory()
|
factory = APIRequestFactory()
|
||||||
|
@ -114,7 +129,7 @@ class EventBasedModelMixin(DataBaseMixin):
|
||||||
|
|
||||||
def test_user_delete(self):
|
def test_user_delete(self):
|
||||||
"""
|
"""
|
||||||
ensure we can update an %model object using API
|
ensure a permited user can delete a new %model object using API
|
||||||
"""
|
"""
|
||||||
instance = getattr(self, self.instance_name)
|
instance = getattr(self, self.instance_name)
|
||||||
|
|
||||||
|
@ -133,11 +148,13 @@ class EventBasedModelMixin(DataBaseMixin):
|
||||||
# TODO rajouter la gestion des permissions dans le Mixin
|
# TODO rajouter la gestion des permissions dans le Mixin
|
||||||
# TODO rajouter un test pour s'assurer que les personnes non
|
# TODO rajouter un test pour s'assurer que les personnes non
|
||||||
# connectées ne peuvent pas create/update/delete
|
# connectées ne peuvent pas create/update/delete
|
||||||
class EventSpecificMixin(object):
|
class EventSpecificTestMixin(object):
|
||||||
"""
|
"""
|
||||||
Tests is the EventSpecifics querysets are rendered correctly
|
Tests is the EventSpecifics querysets are rendered correctly
|
||||||
using the API
|
using the API
|
||||||
Note : need to define : `model`, `root_base_name` and `event_base_name`
|
Note : need to define : `model`, `root_base_name` and `event_base_name`
|
||||||
|
|
||||||
|
tests for models served by the API that inherit EventSpecificMixin
|
||||||
"""
|
"""
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpTestData(cls):
|
def setUpTestData(cls):
|
||||||
|
@ -168,6 +185,12 @@ class EventSpecificMixin(object):
|
||||||
self.place_event = Place.objects.create(**self.place_event_data)
|
self.place_event = Place.objects.create(**self.place_event_data)
|
||||||
|
|
||||||
def test_lists(self):
|
def test_lists(self):
|
||||||
|
"""
|
||||||
|
ensure that only root-level models are served under
|
||||||
|
api/%root_base_name/
|
||||||
|
and that root-level and event-level models are served under
|
||||||
|
api/event/<event_id>/%event_base_name/
|
||||||
|
"""
|
||||||
event_id = self.event1.id
|
event_id = self.event1.id
|
||||||
root_count = self.model.objects.filter(event=None).count()
|
root_count = self.model.objects.filter(event=None).count()
|
||||||
event_count = (self.model.objects
|
event_count = (self.model.objects
|
||||||
|
@ -196,10 +219,13 @@ class ModelTestMixin(DataBaseMixin):
|
||||||
"""
|
"""
|
||||||
Note : need to define : `model`, `base_name`,
|
Note : need to define : `model`, `base_name`,
|
||||||
`instance_name`, `field_tested`, `serializer`
|
`instance_name`, `field_tested`, `serializer`
|
||||||
|
|
||||||
|
generic mixin for testing creation/update/delete
|
||||||
|
of models served by the API
|
||||||
"""
|
"""
|
||||||
def test_user_create(self):
|
def test_user_create(self):
|
||||||
"""
|
"""
|
||||||
ensure we can create a new %model object using API
|
ensure a permited user can create a new %model object using API
|
||||||
"""
|
"""
|
||||||
data = getattr(self, self.data_creation)
|
data = getattr(self, self.data_creation)
|
||||||
initial_count = self.model.objects.count()
|
initial_count = self.model.objects.count()
|
||||||
|
@ -217,7 +243,7 @@ class ModelTestMixin(DataBaseMixin):
|
||||||
|
|
||||||
def test_user_update(self):
|
def test_user_update(self):
|
||||||
"""
|
"""
|
||||||
ensure we can update an %model object using API
|
ensure a permited user can update a new %model object using API
|
||||||
"""
|
"""
|
||||||
instance = getattr(self, self.instance_name)
|
instance = getattr(self, self.instance_name)
|
||||||
factory = APIRequestFactory()
|
factory = APIRequestFactory()
|
||||||
|
@ -241,7 +267,7 @@ class ModelTestMixin(DataBaseMixin):
|
||||||
|
|
||||||
def test_user_delete(self):
|
def test_user_delete(self):
|
||||||
"""
|
"""
|
||||||
ensure we can update an %model object using API
|
ensure a permited user can delete a new %model object using API
|
||||||
"""
|
"""
|
||||||
instance = getattr(self, self.instance_name)
|
instance = getattr(self, self.instance_name)
|
||||||
initial_count = self.model.objects.count()
|
initial_count = self.model.objects.count()
|
||||||
|
|
Loading…
Reference in a new issue