| 
									
										
										
										
											2017-08-17 22:42:48 +02:00
										 |  |  | 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( | 
					
						
							| 
									
										
										
										
											2017-08-22 21:02:43 +02:00
										 |  |  |             name='Deponia', playing=False, collection=self.console) | 
					
						
							| 
									
										
										
										
											2017-08-17 22:42:48 +02:00
										 |  |  |         Game.objects.create( | 
					
						
							| 
									
										
										
										
											2017-08-22 21:02:43 +02:00
										 |  |  |             name='Aladdin', playing=True, collection=self.console) | 
					
						
							| 
									
										
										
										
											2017-08-17 22:42:48 +02:00
										 |  |  |         Game.objects.create( | 
					
						
							| 
									
										
										
										
											2017-08-22 21:02:43 +02:00
										 |  |  |             name='Persona 5', playing=True, collection=self.console) | 
					
						
							| 
									
										
										
										
											2017-08-17 22:42:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     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) |