eventspecific tests

This commit is contained in:
Qwann 2017-07-23 18:23:25 +02:00
parent 7585a8246d
commit a4da5d94c4
2 changed files with 85 additions and 12 deletions

View file

@ -1,10 +1,13 @@
from datetime import timedelta
from django.contrib.auth import get_user_model
from django.test import TestCase
from django.utils import timezone
from django.urls import reverse
from rest_framework.test import APIRequestFactory, APITestCase,\
force_authenticate, APIClient
from rest_framework.test import APIRequestFactory, APITestCase
from rest_framework import status
from event.models import Event
from event.models import Event, Place, ActivityTag, ActivityTemplate
User = get_user_model()
@ -26,13 +29,13 @@ class EventTest(APITestCase):
"ending_date": "2017-07-19T18:05:00Z",
}
def test_anonymous_create(self):
"""
ensure anonymous can't create a new event object using API
"""
url = reverse('event-list')
response = self.client.post(url, self.event_data, format='json')
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
# def test_anonymous_create(self):
# """
# ensure anonymous can't create a new event object using API
# """
# url = reverse('event-list')
# response = self.client.post(url, self.event_data, format='json')
# self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
def test_user_create(self):
"""
@ -44,3 +47,72 @@ class EventTest(APITestCase):
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
self.assertEqual(Event.objects.count(), 1)
self.assertEqual(Event.objects.get().title, 'test event')
class EventSpecificTest(APITestCase):
"""
Tests is the EventSpecifics querysets are rendered correctly
using the API
"""
@classmethod
def setUpTestData(cls):
cls.user = User.objects.create_user(username='user', password='pass', )
cls.event = Event.objects.create(
title='La Nuit 2042',
slug='nuit42',
created_by=cls.user,
creation_date=timezone.now(),
description="La nuit c'est lol",
beginning_date=timezone.now()
+ timedelta(days=30),
ending_date=timezone.now()
+ timedelta(days=31),
)
cls.factory = APIRequestFactory()
def test_place(self):
Place.objects.create(name="root-place", event=None)
Place.objects.create(name="event-place", event=self.event)
self.client.force_authenticate(user=self.user)
url = reverse('place-list')
response = self.client.get(url, format='json')
self.assertEqual(response.json()['count'], 1)
event_id = self.event.id
url = reverse('event-place-list', kwargs={'event_pk': event_id})
response = self.client.get(url, format='json')
self.assertEqual(response.json()['count'], 2)
def test_tag(self):
ActivityTag.objects.create(name="root-tag",
is_public=True,
color="#000",
event=None)
ActivityTag.objects.create(name="event-tag",
is_public=True,
color="#FFF",
event=self.event)
self.client.force_authenticate(user=self.user)
url = reverse('activitytag-list')
response = self.client.get(url, format='json')
self.assertEqual(response.json()['count'], 1)
event_id = self.event.id
url = reverse('event-activitytag-list', kwargs={'event_pk': event_id})
response = self.client.get(url, format='json')
self.assertEqual(response.json()['count'], 2)
def test_activitytemplate(self):
ActivityTemplate.objects.create(title="test", event=self.event)
self.client.force_authenticate(user=self.user)
event_id = self.event.id
url = reverse('event-activitytemplate-list',
kwargs={'event_pk': event_id})
response = self.client.get(url, format='json')
self.assertEqual(response.json()['count'], 1)

View file

@ -77,7 +77,8 @@ REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.AllowAny',
],
'PAGE_SIZE': 10
'PAGE_SIZE': 10,
'TEST_REQUEST_DEFAULT_FORMAT': 'json',
}
ROOT_URLCONF = 'evenementiel.urls'