API Game : ajout des champs status, unplayed, playing et wish

This commit is contained in:
2017-09-16 22:28:41 +02:00
parent 8dec41073f
commit 1845ae9eac
3 changed files with 32 additions and 11 deletions

View File

@ -2,13 +2,21 @@ from games.models import Game, Platform
from rest_framework import serializers
class GameSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Game
fields = (
'collection',
'name',
'note',
'playing',
'status',
'unplayed',
'wish',
)
class PlatformSerializer(serializers.ModelSerializer):
class Meta:
model = Platform
fields = ('name',)
class GameSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Game
fields = ('name', 'collection')

View File

@ -64,8 +64,8 @@ class GameTest(APITestCase):
url = reverse('game-list')
data = {
'name': 'Tetris',
'collection': console_url,
'name': 'Tetris',
'collection': console_url,
}
self.client.force_authenticate(user=self.superuser)
response = self.client.post(url, data, format='json')
@ -98,3 +98,17 @@ class GameTest(APITestCase):
games = [x.get('name') for x in json.loads(response.content)]
self.assertEqual(games, sorted_games)
def test_not_allowed_status(self):
"""
Check that we cannot insert a not allowed status in a Game
"""
console = Platform.objects.create(name='BestPlatform4Ever')
url = reverse('game-list')
data = {
'name': 'Vilebrequin',
'status': 'wrecked',
}
self.client.force_authenticate(user=self.superuser)
response = self.client.post(url, data, format='json')
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(Game.objects.count(), 0)