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
|
|
|
|
from api.test_mixins import EventBasedModelMixin, EventSpecificMixin,\
|
|
|
|
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-25 14:02:57 +02:00
|
|
|
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
|
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-25 14:02:57 +02:00
|
|
|
class EventSpecficTagTest(EventSpecificMixin, APITestCase):
|
|
|
|
model = ActivityTag
|
|
|
|
root_base_name = 'activitytag'
|
|
|
|
event_base_name = 'event-activitytag'
|
2017-07-23 18:23:25 +02:00
|
|
|
|
|
|
|
|
2017-07-25 14:02:57 +02:00
|
|
|
class EventSpecficPlaceTest(EventSpecificMixin, APITestCase):
|
|
|
|
model = Place
|
|
|
|
root_base_name = 'place'
|
|
|
|
event_base_name = 'event-place'
|