API: champ 'shortname' manquant
This commit is contained in:
parent
a6dcad77d9
commit
91cc57f166
@ -1,4 +1,6 @@
|
|||||||
from games.models import Game, Platform, Timeline
|
from games.models import Game
|
||||||
|
from games.models import Platform
|
||||||
|
from games.models import Timeline
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
|
|
||||||
@ -12,8 +14,7 @@ class GameSerializer(serializers.HyperlinkedModelSerializer):
|
|||||||
'playing',
|
'playing',
|
||||||
'status',
|
'status',
|
||||||
'unplayed',
|
'unplayed',
|
||||||
'wish',
|
'wish', )
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class GameTimelineSerializer(serializers.HyperlinkedModelSerializer):
|
class GameTimelineSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
@ -22,11 +23,10 @@ class GameTimelineSerializer(serializers.HyperlinkedModelSerializer):
|
|||||||
fields = (
|
fields = (
|
||||||
'date',
|
'date',
|
||||||
'item',
|
'item',
|
||||||
'status',
|
'status', )
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class PlatformSerializer(serializers.ModelSerializer):
|
class PlatformSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Platform
|
model = Platform
|
||||||
fields = ('name',)
|
fields = ('name', 'shortname')
|
||||||
|
@ -1,27 +1,28 @@
|
|||||||
|
import json
|
||||||
|
from datetime import date
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from games.models import Game, Platform, Timeline
|
from games.models import Game
|
||||||
|
from games.models import Platform
|
||||||
|
from games.models import Timeline
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from rest_framework.test import APITestCase, force_authenticate
|
from rest_framework.test import APITestCase
|
||||||
from datetime import date, datetime
|
|
||||||
import json
|
|
||||||
|
|
||||||
|
|
||||||
class PlatformTest(APITestCase):
|
class PlatformTest(APITestCase):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpTestData(cls):
|
def setUpTestData(cls):
|
||||||
cls.superuser = User.objects.create_superuser(
|
cls.superuser = User.objects.create_superuser(
|
||||||
'admin',
|
'admin', 'admin@localhost', 'admin')
|
||||||
'admin@localhost',
|
|
||||||
'admin')
|
|
||||||
|
|
||||||
def test_create_platform(self):
|
def test_create_platform(self):
|
||||||
"""
|
"""
|
||||||
Check we can create a platform object.
|
Check we can create a platform object.
|
||||||
"""
|
"""
|
||||||
url = reverse('platform-list')
|
url = reverse('platform-list')
|
||||||
data = {'name': 'GP2X'}
|
data = {'name': 'GP2X', 'shortname': 'GP2X'}
|
||||||
self.client.force_authenticate(user=self.superuser)
|
self.client.force_authenticate(user=self.superuser)
|
||||||
response = self.client.post(url, data, format='json')
|
response = self.client.post(url, data, format='json')
|
||||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||||
@ -39,21 +40,17 @@ class PlatformTest(APITestCase):
|
|||||||
url = reverse('platform-list')
|
url = reverse('platform-list')
|
||||||
self.client.force_authenticate(user=self.superuser)
|
self.client.force_authenticate(user=self.superuser)
|
||||||
response = self.client.get(url, format='json')
|
response = self.client.get(url, format='json')
|
||||||
sorted_platforms = list(
|
sorted_platforms = list(Platform.objects.all().order_by('name')
|
||||||
Platform.objects.all().order_by('name').values_list(
|
.values_list('name', flat=True))
|
||||||
'name', flat=True))
|
|
||||||
platforms = [x.get('name') for x in json.loads(response.content)]
|
platforms = [x.get('name') for x in json.loads(response.content)]
|
||||||
self.assertEqual(platforms, sorted_platforms)
|
self.assertEqual(platforms, sorted_platforms)
|
||||||
|
|
||||||
|
|
||||||
class GameTest(APITestCase):
|
class GameTest(APITestCase):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpTestData(cls):
|
def setUpTestData(cls):
|
||||||
cls.superuser = User.objects.create_superuser(
|
cls.superuser = User.objects.create_superuser(
|
||||||
'admin',
|
'admin', 'admin@localhost', 'admin')
|
||||||
'admin@localhost',
|
|
||||||
'admin')
|
|
||||||
|
|
||||||
def test_create_game(self):
|
def test_create_game(self):
|
||||||
"""
|
"""
|
||||||
@ -75,27 +72,19 @@ class GameTest(APITestCase):
|
|||||||
self.assertEqual(Game.objects.get().name, 'Tetris')
|
self.assertEqual(Game.objects.get().name, 'Tetris')
|
||||||
self.assertEqual(Game.objects.get().collection_id, console.id)
|
self.assertEqual(Game.objects.get().collection_id, console.id)
|
||||||
|
|
||||||
|
|
||||||
def test_sorted_games(self):
|
def test_sorted_games(self):
|
||||||
"""
|
"""
|
||||||
Check that game list is sorted.
|
Check that game list is sorted.
|
||||||
"""
|
"""
|
||||||
console = Platform.objects.create(name='BestPlatform4Ever')
|
console = Platform.objects.create(name='BestPlatform4Ever')
|
||||||
Game.objects.create(
|
Game.objects.create(name='Pomperman', collection=console)
|
||||||
name='Pomperman',
|
Game.objects.create(name='Vektoria', collection=console)
|
||||||
collection=console)
|
Game.objects.create(name='Qrackovitchya', collection=console)
|
||||||
Game.objects.create(
|
|
||||||
name='Vektoria',
|
|
||||||
collection=console)
|
|
||||||
Game.objects.create(
|
|
||||||
name='Qrackovitchya',
|
|
||||||
collection=console)
|
|
||||||
url = reverse('game-list')
|
url = reverse('game-list')
|
||||||
self.client.force_authenticate(user=self.superuser)
|
self.client.force_authenticate(user=self.superuser)
|
||||||
response = self.client.get(url, format='json')
|
response = self.client.get(url, format='json')
|
||||||
sorted_games = list(
|
sorted_games = list(
|
||||||
Game.objects.all().order_by('name').values_list(
|
Game.objects.all().order_by('name').values_list('name', flat=True))
|
||||||
'name', flat=True))
|
|
||||||
games = [x.get('name') for x in json.loads(response.content)]
|
games = [x.get('name') for x in json.loads(response.content)]
|
||||||
self.assertEqual(games, sorted_games)
|
self.assertEqual(games, sorted_games)
|
||||||
|
|
||||||
@ -103,7 +92,7 @@ class GameTest(APITestCase):
|
|||||||
"""
|
"""
|
||||||
Check that we cannot insert a not allowed status in a Game
|
Check that we cannot insert a not allowed status in a Game
|
||||||
"""
|
"""
|
||||||
console = Platform.objects.create(name='BestPlatform4Ever')
|
Platform.objects.create(name='BestPlatform4Ever')
|
||||||
url = reverse('game-list')
|
url = reverse('game-list')
|
||||||
data = {
|
data = {
|
||||||
'name': 'Vilebrequin',
|
'name': 'Vilebrequin',
|
||||||
@ -119,9 +108,7 @@ class TimelineTest(APITestCase):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def setUpTestData(cls):
|
def setUpTestData(cls):
|
||||||
cls.superuser = User.objects.create_superuser(
|
cls.superuser = User.objects.create_superuser(
|
||||||
'admin',
|
'admin', 'admin@localhost', 'admin')
|
||||||
'admin@localhost',
|
|
||||||
'admin')
|
|
||||||
|
|
||||||
def test_create_timeline(self):
|
def test_create_timeline(self):
|
||||||
"""
|
"""
|
||||||
@ -129,9 +116,7 @@ class TimelineTest(APITestCase):
|
|||||||
"""
|
"""
|
||||||
console = Platform.objects.create(name='BestPlatform4Ever')
|
console = Platform.objects.create(name='BestPlatform4Ever')
|
||||||
game = Game.objects.create(
|
game = Game.objects.create(
|
||||||
name='Cherubin',
|
name='Cherubin', collection=console, status='created')
|
||||||
collection=console,
|
|
||||||
status='created')
|
|
||||||
|
|
||||||
# By default a timeline is generated with current datetime.
|
# By default a timeline is generated with current datetime.
|
||||||
# We need to change this date.
|
# We need to change this date.
|
||||||
@ -147,10 +132,8 @@ class TimelineTest(APITestCase):
|
|||||||
}
|
}
|
||||||
self.client.force_authenticate(user=self.superuser)
|
self.client.force_authenticate(user=self.superuser)
|
||||||
response = self.client.post(url, data, format='json')
|
response = self.client.post(url, data, format='json')
|
||||||
self.assertEqual(
|
self.assertEqual(response.status_code, status.HTTP_201_CREATED,
|
||||||
response.status_code,
|
response.content)
|
||||||
status.HTTP_201_CREATED,
|
|
||||||
response.content)
|
|
||||||
self.assertEqual(Timeline.objects.count(), 2)
|
self.assertEqual(Timeline.objects.count(), 2)
|
||||||
|
|
||||||
def test_sorted_game_timeline(self):
|
def test_sorted_game_timeline(self):
|
||||||
@ -160,28 +143,22 @@ class TimelineTest(APITestCase):
|
|||||||
# Prepare timeline with some different dates
|
# Prepare timeline with some different dates
|
||||||
console = Platform.objects.create(name='BestPlatform4Ever')
|
console = Platform.objects.create(name='BestPlatform4Ever')
|
||||||
game = Game.objects.create(
|
game = Game.objects.create(
|
||||||
name='Symptomatic',
|
name='Symptomatic', collection=console, status='created')
|
||||||
collection=console,
|
|
||||||
status='created')
|
|
||||||
game.status = 'beaten'
|
game.status = 'beaten'
|
||||||
game.save()
|
game.save()
|
||||||
game.status = 'completed'
|
game.status = 'completed'
|
||||||
game.save()
|
game.save()
|
||||||
# Change date from Timelines
|
# Change date from Timelines
|
||||||
Timeline.objects.filter(status='created').update(
|
Timeline.objects.filter(status='created').update(date='2017-03-01')
|
||||||
date='2017-03-01')
|
Timeline.objects.filter(status='completed').update(date='2017-03-05')
|
||||||
Timeline.objects.filter(status='completed').update(
|
Timeline.objects.filter(status='beaten').update(date='2017-03-07')
|
||||||
date='2017-03-05')
|
|
||||||
Timeline.objects.filter(status='beaten').update(
|
|
||||||
date='2017-03-07')
|
|
||||||
# Check dates
|
# Check dates
|
||||||
url = reverse('game_timeline-list')
|
url = reverse('game_timeline-list')
|
||||||
self.client.force_authenticate(user=self.superuser)
|
self.client.force_authenticate(user=self.superuser)
|
||||||
response = self.client.get(url, format='json')
|
response = self.client.get(url, format='json')
|
||||||
# sorted_timelines are datetime.date
|
# sorted_timelines are datetime.date
|
||||||
sorted_timelines = list(
|
sorted_timelines = list(Timeline.objects.all().order_by('-date')
|
||||||
Timeline.objects.all().order_by('-date').values_list(
|
.values_list('date', flat=True))
|
||||||
'date', flat=True))
|
|
||||||
# dates are string date, format %Y-%m-%d
|
# dates are string date, format %Y-%m-%d
|
||||||
dates = [x.get('date') for x in json.loads(response.content)]
|
dates = [x.get('date') for x in json.loads(response.content)]
|
||||||
da = [datetime.date(datetime.strptime(x, '%Y-%m-%d')) for x in dates]
|
da = [datetime.date(datetime.strptime(x, '%Y-%m-%d')) for x in dates]
|
||||||
|
Loading…
Reference in New Issue
Block a user