openbackloggery/collection/games/tests/test_game.py

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)