openbackloggery/collection/games/tests/test_game.py
Olivier DOSSMANN 242b0edff0 Refonte de la base:
* utilisation de classes abstraites Django : Item et Collection
  * héritage de ces classes pour Game et Console
  * création d'un objet Timeline contenant le changement d'état des jeux
  * affichage de la Timeline sur l'interface Admin
2017-08-22 21:02:43 +02:00

29 lines
959 B
Python

from django.test import TestCase
from games.models import Console, Game
class GameTest(TestCase):
"""
Game Model
"""
def setUp(self):
self.console = Console.objects.create(name='BestConsole4Ever')
Game.objects.create(
name='Deponia', playing=False, collection=self.console)
Game.objects.create(
name='Aladdin', playing=True, collection=self.console)
Game.objects.create(
name='Persona 5', playing=True, collection=self.console)
def test_game_are_sorted_by_playing_and_name(self):
"""
Games should be sorted by playing state (playing should be True first)
then by name in alphabetical order.
"""
games = list(Game.objects.all().values_list('name', flat=True))
sorted_games = list(Game.objects.all().order_by(
'-playing', 'name').values_list('name', flat=True))
self.assertEqual(games, sorted_games)