Ajout d'un test sur l'ordre des game_timeline sur l'API
This commit is contained in:
parent
a5ff2326f7
commit
0536b16d6d
1
TODO
1
TODO
@ -1,6 +1,5 @@
|
||||
# À faire
|
||||
|
||||
* Test API sur l'ordre de tri des date pour les Timeline
|
||||
* étudier la possibilité à l'utilisateur, via des variables d'environnement, de configurer un email, une autre BDD, etc.
|
||||
|
||||
## Dépôt / code
|
||||
|
@ -3,7 +3,7 @@ from django.urls import reverse
|
||||
from games.models import Game, Platform, Timeline
|
||||
from rest_framework import status
|
||||
from rest_framework.test import APITestCase, force_authenticate
|
||||
from datetime import date
|
||||
from datetime import date, datetime
|
||||
import json
|
||||
|
||||
|
||||
@ -154,5 +154,35 @@ class TimelineTest(APITestCase):
|
||||
self.assertEqual(Timeline.objects.count(), 2)
|
||||
|
||||
def test_sorted_game_timeline(self):
|
||||
# TODO: Check descending date order.
|
||||
pass
|
||||
"""
|
||||
Check that timelines are sorted by date in descending order.
|
||||
"""
|
||||
# Prepare timeline with some different dates
|
||||
console = Platform.objects.create(name='BestPlatform4Ever')
|
||||
game = Game.objects.create(
|
||||
name='Symptomatic',
|
||||
collection=console,
|
||||
status='created')
|
||||
game.status = 'beaten'
|
||||
game.save()
|
||||
game.status = 'completed'
|
||||
game.save()
|
||||
# Change date from Timelines
|
||||
Timeline.objects.filter(status='created').update(
|
||||
date='2017-03-01')
|
||||
Timeline.objects.filter(status='completed').update(
|
||||
date='2017-03-05')
|
||||
Timeline.objects.filter(status='beaten').update(
|
||||
date='2017-03-07')
|
||||
# Check dates
|
||||
url = reverse('game_timeline-list')
|
||||
self.client.force_authenticate(user=self.superuser)
|
||||
response = self.client.get(url, format='json')
|
||||
# sorted_timelines are datetime.date
|
||||
sorted_timelines = list(
|
||||
Timeline.objects.all().order_by('-date').values_list(
|
||||
'date', flat=True))
|
||||
# dates are string date, format %Y-%m-%d
|
||||
dates = [x.get('date') for x in json.loads(response.content)]
|
||||
da = [datetime.date(datetime.strptime(x, '%Y-%m-%d')) for x in dates]
|
||||
self.assertEqual(da, sorted_timelines)
|
||||
|
Loading…
Reference in New Issue
Block a user