poulpe/api/test_event.py

57 lines
1.6 KiB
Python
Raw Normal View History

2017-07-23 16:06:52 +02:00
from django.contrib.auth import get_user_model
2017-07-23 18:23:25 +02:00
2017-07-25 14:02:57 +02:00
from rest_framework.test import APITestCase
2017-07-23 18:23:25 +02:00
from event.models import Event, Place, ActivityTag, ActivityTemplate
2017-07-23 16:06:52 +02:00
2017-07-25 14:02:57 +02:00
from api.event.serializers import ActivityTemplateSerializer, EventSerializer
2017-07-26 14:51:29 +02:00
from api.test_mixins import EventBasedModelTestMixin, EventSpecificTestMixin,\
2017-07-25 14:02:57 +02:00
ModelTestMixin
2017-07-23 16:06:52 +02:00
2017-07-25 14:02:57 +02:00
User = get_user_model()
2017-07-23 18:23:25 +02:00
2017-07-25 14:02:57 +02:00
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
2017-07-23 18:23:25 +02:00
2017-07-26 14:51:29 +02:00
class ActivityTemplateTest(EventBasedModelTestMixin, APITestCase):
2017-07-25 14:02:57 +02:00
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
2017-07-23 18:23:25 +02:00
2017-07-25 14:02:57 +02:00
def test_create_extra(self):
self.assertEqual(self.model.objects.get(id=1).tags.count(), 1)
2017-07-23 18:23:25 +02:00
2017-07-25 14:02:57 +02:00
def pre_update_extra(self, data):
data['tags'].append(self.tag2_data)
return data
2017-07-23 18:23:25 +02:00
2017-07-25 14:02:57 +02:00
def post_update_extra(self, instance):
self.assertEqual(instance.tags.count(), 2)
2017-07-23 18:23:25 +02:00
2017-07-26 14:51:29 +02:00
class EventSpecficTagTest(EventSpecificTestMixin, APITestCase):
2017-07-25 14:02:57 +02:00
model = ActivityTag
root_base_name = 'activitytag'
event_base_name = 'event-activitytag'
2017-07-23 18:23:25 +02:00
2017-07-26 14:51:29 +02:00
class EventSpecficPlaceTest(EventSpecificTestMixin, APITestCase):
2017-07-25 14:02:57 +02:00
model = Place
root_base_name = 'place'
event_base_name = 'event-place'