Example #1
0
def test_get_owned_games():

    api = MockSteamApi()

    games_resp = api.get_owned_games('1')

    games = []
    found = False
    for curr in games_resp:

        curr_game = OwnedGame.from_response(curr)
        games.append(curr_game)
        if curr_game.game.appid != 234650:
            continue

        found = True
        assert curr['appid'] == 234650
        assert curr['name'] == "Shadowrun Returns"
        assert curr['has_community_visible_stats'] == True
        assert curr['img_logo_url'] == "70f084857297d5fdd96d019db3a990d6d9ec64f1"
        assert curr['img_icon_url'] == "64eec20c9375e7473b964f0d0bc41d19f03add3b"
        assert curr['playtime_forever'] == 200

    assert(found)
    assert(len(games) == 3)

    games_by_playtime = sorted(games, key=lambda k: k.playtime_forever, reverse=True)

    assert(games_by_playtime[0].game.name == "Mass Effect 2")
    assert(games_by_playtime[0].playtime_forever == 400)
    assert(games_by_playtime[-1].game.name == "Railroad Tycoon 3")
    assert(games_by_playtime[-1].playtime_forever == 100)
Example #2
0
def test_get_player_summaries():

    api = MockSteamApi()

    single_result = api.get_player_summary(3)
    assert single_result['realname'] == 'Carl'

    multiple_results = api.get_player_summaries([2, 3])
    assert multiple_results[0]['realname'] == 'Bob'
    assert multiple_results[1]['realname'] == 'Carl'
Example #3
0
def test_get_player_achievements():
    api = MockSteamApi()

    achievements = api.get_player_achievements(3, APP_ID_FALLOUT_4)

    # Transform into a simple list of achivement names
    achivement_names = [a['name'] for a in achievements]

    assert("War Never Changes" in achivement_names)
    assert("The Nuclear Option" in achivement_names)
    assert("Institutionalized" in achivement_names)
    assert("Nuclear Family" in achivement_names)
    assert("Rockets' Red Glare" in achivement_names)
    assert("Masshole" in achivement_names)
Example #4
0
def test_player_count_recommendation():

    crawler = FriendCrawler(MockSteamApi())
    center = crawler.build_friend_graph(steamid=3)

    alice = center.friends[0]
    debra = center.friends[1]
    carl = center
    bob = debra.friends[0]
    eustace = debra.friends[2]

    graph = GraphDB()
    graph.insert_players([alice, bob, carl, debra, eustace])

    assert len(graph.nodes()) == 5
    assert len(graph.edges()) == 5

    exclude_debra = PlayerExclusionTraversalFilter([debra])
    recommender = Recommender(center, filters=[exclude_debra])
    recs = recommender.get_recommendations()

    # Sort by playtime_forever and return the top results
    rec_system = RecommendationSorting(systems=[PlayerCountRecommendation()])
    sorted_games = GameRecommendation.sort_by_playtime(recs,
                                                       rec_system,
                                                       reverse=True)

    # Build the output recommendations
    top_games = sorted_games[0:3]

    assert len(top_games) == 3

    assert top_games[0].game.appid in (7610, 24980)
    assert top_games[1].game.appid in (7610, 24980)
    assert top_games[2].game.appid in (234650, 33230, 102600)
Example #5
0
def test_get_friend_list():
    api = MockSteamApi()

    friends = api.get_friend_list(3, relationship='all')

    assert(len(friends) == 2)

    # Sort by time- oldest first
    friends_by_time = sorted(friends,
                             key=lambda k: k['friend_since'], reverse=False)

    assert(friends_by_time[0]['steamid'] == "4")
    assert(friends_by_time[0]['relationship'] == "friend")
    assert(friends_by_time[0]['friend_since'] == 1325266988)

    assert(friends_by_time[1]['steamid'] == "1")
    assert(friends_by_time[1]['relationship'] == "friend")
    assert(friends_by_time[1]['friend_since'] == 1447349026)
def test_crawl():

    GRAPH_DEPTH = 6

    crawler = FriendCrawler(MockSteamApi())

    center = crawler.build_friend_graph(steamid=3)
    output_player(player=center, level=0)

    perform_graph_assertions(center)
Example #7
0
def test_crawl():

    crawler = FriendCrawler(MockSteamApi())

    center = crawler.build_friend_graph(steamid=3, graph_depth=6)
    # output_player(player=center, level=0)

    assert (center.steamid == '3')
    assert (len(center.friends) == 2)
    assert ([f.steamid for f in center.friends] == ['1', '4'])
Example #8
0
def test_game_name_filter():

    returned_games = []
    api = MockSteamApi()

    games_resp = api.get_owned_games('1')
    for curr in games_resp:

        curr_game = OwnedGame.from_response(curr)
        returned_games.append(curr_game)

    # Filter out Mass Effect
    filters = [GameNameTraversalFilter('ffe', reverse=True)]

    # Fiter in Railroad Tycoon 3
    filters += [GameNameTraversalFilter('road')]

    matching = []
    for curr in returned_games:
        if TraversalFilter.passes(curr, filters):
            matching.append(curr)

    assert len(matching) == 1
    assert matching[0].game.name == "Railroad Tycoon 3"
Example #9
0
def test_minimum_playtime_filter():

    crawler = FriendCrawler(MockSteamApi())
    center = crawler.build_friend_graph(steamid=3)

    alice = center.friends[0]
    debra = center.friends[1]
    carl = center
    bob = debra.friends[0]
    eustace = debra.friends[2]
    graph = GraphDB()
    graph.insert_players([alice, bob, carl, debra, eustace])

    assert len(graph.nodes()) == 5
    assert len(graph.edges()) == 5

    # TODO: ,filters=[], weighter=None):
    exclude_debra = PlayerExclusionTraversalFilter([debra])
    minimum_playtime_filter = GamePlaytimeTraversalFilter(150)

    recommender = Recommender(center,
                              filters=[exclude_debra, minimum_playtime_filter])
    recs = recommender.get_recommendations()

    # Sort by playtime_forever and return the top results
    rec_system = RecommendationSorting(systems=[PlaytimeRecommendation()])
    sorted_games = GameRecommendation.sort_by_playtime(recs,
                                                       rec_system,
                                                       reverse=True)

    # Build the output recommendations
    top_games = sorted_games[0:3]

    assert len(top_games) == 3

    assert top_games[0].game.appid == 33230
    assert top_games[0].total_playtime == 3000
    assert bob in top_games[0].non_friend_owners

    assert top_games[1].game.appid == 7610
    assert top_games[1].total_playtime == 1000
    assert bob in top_games[1].non_friend_owners
    assert alice not in top_games[1].friends_with_game

    assert top_games[2].game.appid == 24980
    assert top_games[2].total_playtime == 400
    assert alice in top_games[2].friends_with_game
    assert carl not in top_games[2].non_friend_owners