def choose_a_random_game_to_play(choose_never_played, choose_installed): """ Gets a single random games from the list of games that you should really play now. :return: A game to play """ games = SteamApiClient().get_player_owned_games() if choose_never_played: games_never_played = [] for game in games: if 'playtime_forever' in game: if game['playtime_forever'] == 0: games_never_played.append(game) games = games_never_played if choose_installed: games_installed = [] for game in games: if installed_games.is_game_in_installed_games_list(game): games_installed.append(game) games = games_installed unexcluded_games = [] for game in games: if game['name'] not in settings.excluded_games: unexcluded_games.append(game) games = unexcluded_games if games.__len__() == 0: return False, None random_int = random.randrange(games.__len__()) return True, games[random_int]['name']
class SteamAPIClientTests(unittest.TestCase): def setUp(self): self.client = SteamApiClient() def test_get_player_summary_returns_json_dictionary(self): json = self.client.get_player_summary() self.assertTrue(isinstance(json, dict)) player = json['response']['players'][0] self.assertEqual(settings.steam_user_id, player['steamid']) def test_get_player_owned_games_returns_json_dictionary(self): games = self.client.get_player_owned_games() self.assertTrue(isinstance(games, list)) self.assertTrue(isinstance(games[0], dict))
def setUp(self): self.client = SteamApiClient()