diff --git a/TODO b/TODO index ebca1f3..b15dcb6 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,5 @@ # À faire - * Ajouter le champ "status" des jeux dans l'API - * API jeux : ajouter wish, playing et unplayed * Ajouter des help_text à tous les champs + classes enfants. Les traduire. * étudier la possibilité à l'utilisateur, via des variables d'environnement, de configurer un email, une autre BDD, etc. @@ -18,8 +16,9 @@ ## Tests - * Sur Console + * Sur Platform * Sur Game + * API : sur Game, pour les champs wish, unplayed, playing et status * travis.yml to launch test * Selenium pour vérifier : * que Nouveau n'apparaisse pas dans la liste des états possibles diff --git a/collection/games/serializers.py b/collection/games/serializers.py index 0a36201..62989a0 100644 --- a/collection/games/serializers.py +++ b/collection/games/serializers.py @@ -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') diff --git a/collection/games/tests/test_api.py b/collection/games/tests/test_api.py index eb0eb4b..d6052fc 100644 --- a/collection/games/tests/test_api.py +++ b/collection/games/tests/test_api.py @@ -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)