poulpe/api/test_event.py
2017-07-25 14:02:57 +02:00

56 lines
1.5 KiB
Python

from django.contrib.auth import get_user_model
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,\
ModelTestMixin
User = get_user_model()
class EventTest(ModelTestMixin, APITestCase):
model = Event
base_name = 'event'
tested_fields = {'title': "I'm a test", }
# Création
data_creation = 'event2_data'
# Update/Delete
instance_name = 'event1'
serializer = EventSerializer
class ActivityTemplateTest(EventBasedModelMixin, APITestCase):
model = ActivityTemplate
base_name = 'event-activitytemplate'
initial_count = 1
# Creation
data_creation = 'act_temp2_data'
# Update/Delete
instance_name = 'act_temp1'
field_tested = 'title'
serializer = ActivityTemplateSerializer
def test_create_extra(self):
self.assertEqual(self.model.objects.get(id=1).tags.count(), 1)
def pre_update_extra(self, data):
data['tags'].append(self.tag2_data)
return data
def post_update_extra(self, instance):
self.assertEqual(instance.tags.count(), 2)
class EventSpecficTagTest(EventSpecificMixin, APITestCase):
model = ActivityTag
root_base_name = 'activitytag'
event_base_name = 'event-activitytag'
class EventSpecficPlaceTest(EventSpecificMixin, APITestCase):
model = Place
root_base_name = 'place'
event_base_name = 'event-place'