diff --git a/api/test_event.py b/api/test_event.py index 6c2b118..62d77d5 100644 --- a/api/test_event.py +++ b/api/test_event.py @@ -5,7 +5,7 @@ from rest_framework.test import APITestCase from event.models import Event, Place, ActivityTag, ActivityTemplate from api.event.serializers import ActivityTemplateSerializer, EventSerializer -from api.test_mixins import EventBasedModelMixin, EventSpecificMixin,\ +from api.test_mixins import EventBasedModelTestMixin, EventSpecificTestMixin,\ ModelTestMixin User = get_user_model() @@ -22,7 +22,7 @@ class EventTest(ModelTestMixin, APITestCase): serializer = EventSerializer -class ActivityTemplateTest(EventBasedModelMixin, APITestCase): +class ActivityTemplateTest(EventBasedModelTestMixin, APITestCase): model = ActivityTemplate base_name = 'event-activitytemplate' initial_count = 1 @@ -44,13 +44,13 @@ class ActivityTemplateTest(EventBasedModelMixin, APITestCase): self.assertEqual(instance.tags.count(), 2) -class EventSpecficTagTest(EventSpecificMixin, APITestCase): +class EventSpecficTagTest(EventSpecificTestMixin, APITestCase): model = ActivityTag root_base_name = 'activitytag' event_base_name = 'event-activitytag' -class EventSpecficPlaceTest(EventSpecificMixin, APITestCase): +class EventSpecficPlaceTest(EventSpecificTestMixin, APITestCase): model = Place root_base_name = 'place' event_base_name = 'event-place' diff --git a/api/test_mixins.py b/api/test_mixins.py index 094676d..9f524d7 100644 --- a/api/test_mixins.py +++ b/api/test_mixins.py @@ -14,6 +14,9 @@ User = get_user_model() class DataBaseMixin(object): + """ + provides a datatabse for API tests + """ @classmethod def setUpTestData(cls): # Users @@ -49,23 +52,35 @@ class DataBaseMixin(object): self.act_temp1.tags.add(self.tag1) -class EventBasedModelMixin(DataBaseMixin): +class EventBasedModelTestMixin(DataBaseMixin): """ Note : need to define : `model`, `base_name`, `initial_count`, `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//%model """ - def test_user_create_extra(self): + def user_create_extra(self): + """ + extra test in creation by a permited user + """ pass def pre_update_extra(self, data): + """ + extra modification for the data sent for update + """ return data def post_update_extra(self): + """ + extra test for updated model + """ pass 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) @@ -80,11 +95,11 @@ class EventBasedModelMixin(DataBaseMixin): self.assertEqual(self.model.objects.get(id=self.initial_count+1).event, self.event1) - self.test_create_extra() + self.user_create_extra() 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) factory = APIRequestFactory() @@ -114,7 +129,7 @@ class EventBasedModelMixin(DataBaseMixin): 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) @@ -133,11 +148,13 @@ class EventBasedModelMixin(DataBaseMixin): # TODO rajouter la gestion des permissions dans le Mixin # TODO rajouter un test pour s'assurer que les personnes non # connectées ne peuvent pas create/update/delete -class EventSpecificMixin(object): +class EventSpecificTestMixin(object): """ Tests is the EventSpecifics querysets are rendered correctly using the API Note : need to define : `model`, `root_base_name` and `event_base_name` + + tests for models served by the API that inherit EventSpecificMixin """ @classmethod def setUpTestData(cls): @@ -168,6 +185,12 @@ class EventSpecificMixin(object): self.place_event = Place.objects.create(**self.place_event_data) 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_base_name/ + """ event_id = self.event1.id root_count = self.model.objects.filter(event=None).count() event_count = (self.model.objects @@ -196,10 +219,13 @@ class ModelTestMixin(DataBaseMixin): """ Note : need to define : `model`, `base_name`, `instance_name`, `field_tested`, `serializer` + + generic mixin for testing creation/update/delete + of models served by the API """ 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) initial_count = self.model.objects.count() @@ -217,7 +243,7 @@ class ModelTestMixin(DataBaseMixin): 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) factory = APIRequestFactory() @@ -241,7 +267,7 @@ class ModelTestMixin(DataBaseMixin): 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) initial_count = self.model.objects.count()