def test_get_games_in_state(self): g1 = Game(map=self.map, players="['', '']", state=Game.LOBBY) g1.save() g2 = Game(map=self.map, players="['', '']", state=Game.LOBBY) g2.save() g3 = Game(map=self.map, players="['', '']", state=Game.ACTIVE) g3.save() lobby_games = set(list(Game.get_games_in_state(Game.LOBBY))) self.assertEqual(lobby_games, set([g1, g2])) active_games = set(list(Game.get_games_in_state(Game.ACTIVE))) self.assertEqual(active_games, set([g3])) finished_games = set(list(Game.get_games_in_state(Game.FINISHED))) self.assertEqual(finished_games, set([]))
def test_ajax_lobby_games(self): User.objects.create_user('aaa', 'aaa', 'aaa') c = self.client login(c, 'aaa', 'aaa') s_resp = c.get(reverse('ajax_lobby_games')) resp_object = json.loads(s_resp.content) num = len(Game.get_games_in_state(Game.LOBBY)) self.assertEqual(len(resp_object), num)
def get(self, request): """ Gets the list of all games in the LOBBY state """ game_list = [] games = Game.get_games_in_state(Game.LOBBY).order_by("id").reverse() for game in games: game_list.append(game.to_map()) map_list = [] maps = Map.objects.all() for a_map in maps: map_list.append(a_map.to_map()) context = {"maps": map_list, "games": game_list} return render(request, "the_game_bazaar/play.html", context)
def ajax_lobby_games(request): game_list = [] games = Game.get_games_in_state(Game.LOBBY).order_by('id').reverse() for game in games: game_list.append(game.to_map()) return HttpResponse(json.dumps(game_list), mimetype="application/json")