API Timeline ajoutée !

This commit is contained in:
2017-09-17 00:04:26 +02:00
parent 95d8b30c3c
commit 92ea2f6af7
10 changed files with 200 additions and 16 deletions

View File

@ -1,8 +1,9 @@
from django.contrib.auth.models import User
from django.urls import reverse
from games.models import Game, Platform
from games.models import Game, Platform, Timeline
from rest_framework import status
from rest_framework.test import APITestCase, force_authenticate
from datetime import date
import json
@ -112,3 +113,46 @@ class GameTest(APITestCase):
response = self.client.post(url, data, format='json')
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(Game.objects.count(), 0)
class TimelineTest(APITestCase):
@classmethod
def setUpTestData(cls):
cls.superuser = User.objects.create_superuser(
'admin',
'admin@localhost',
'admin')
def test_create_timeline(self):
"""
Check we can create a timeline object.
"""
console = Platform.objects.create(name='BestPlatform4Ever')
game = Game.objects.create(
name='Cherubin',
collection=console,
status='created')
# By default a timeline is generated with current datetime.
# We need to change this date.
timeline = Timeline.objects.first()
timeline.date = date(2017, 9, 15)
timeline.save()
url = reverse('game_timeline-list')
data = {
'item': reverse('game-detail', kwargs={'pk': game.id}),
'date': date(2017, 9, 16),
'status': 'beaten',
}
self.client.force_authenticate(user=self.superuser)
response = self.client.post(url, data, format='json')
self.assertEqual(
response.status_code,
status.HTTP_201_CREATED,
response.content)
self.assertEqual(Timeline.objects.count(), 2)
def test_sorted_game_timeline(self):
# TODO: Check descending date order.
pass