def index(steam_id="76561197960435530"): if len(steam_id) > 17: return render_template("404.html") username = get_persona(steam_id) game_count = get_games(steam_id)["count"] top_game_counts = get_top_game_counts(steam_id) top_game_counts_chart = make_hbar_chart(top_game_counts, 'Top 5 friend game counts') top_games = get_top_games(steam_id) top_games_chart = make_pie_chart(top_games, 'Top 5 games by playtime (in hrs)') friends_count = len(get_friends(steam_id)) avatar = get_avatar(steam_id) playtime = get_playtime(steam_id) context = { "username": username, "game_count": game_count, "friends_count": friends_count, "avatar": avatar, "top_game_counts": top_game_counts, "top_games": top_games, "top_games_chart": top_games_chart, "top_game_counts_chart": top_game_counts_chart, "playtime": playtime, } return render_template("index.html", **context)
from steam import get_games # should mock this out but let's call feedparser for real # for a feedparser mocking see the AttrDict (advanced) Bite 50's tests games = get_games() def test_assert_number_of_entries(): assert len(games) == 30 def test_all_list_items_are_namedtuples(): assert all(isinstance(game, tuple) for game in games) def test_assert_all_links_contain_store(): assert all('store.steampowered.com' in game.link for game in games) def test_title_and_url_first_entry(): first_game = games[0] assert first_game.title == 'Midweek Madness - RiME, 33% Off' assert first_game.link == 'http://store.steampowered.com/news/31695/' def test_title_and_url_last_entry(): last_game = games[-1] assert last_game.title == 'Now Available on Steam - Loco Dojo, 35% off!' assert last_game.link == 'http://store.steampowered.com/news/31113/'
def test_games_not_present(): with pytest.raises(ValueError): result = get_games(12345646546572145)
def test_get_games(): tests = zip(TEST_IDS, [493, 228, 595]) for id, games in tests: assert get_games(id)["count"] == len(get_games(id)["games"]) assert get_games(id)["count"] >= games