def test_record_twitch_vod_ai(user, twitch_vod_game): deck = _create_deck(TEST_TWITCH_DECK_STRING_1) _create_player("Test Player 1", 1, deck, twitch_vod_game, rank=25) _create_player("Test Player 2", 2, deck, twitch_vod_game, rank=-1, is_ai=True) replay = _create_replay(user, twitch_vod_game) record_twitch_vod(replay, TEST_REPLAY_META) expected_vod = TwitchVod(hsreplaynet_user_id=user.id, rank=25, replay_shortid=replay.shortid, combined_rank="R25", **TEST_TWITCH_VOD_PARAMS) actual_vod = TwitchVod.get(TEST_REPLAY_META["twitch_vod"]["channel_name"], "R25") # Patch the TTL expected_vod.ttl = actual_vod.ttl assert expected_vod == actual_vod
def test_record_twitch_vod_arena(user): game = GlobalGame(game_type=BnetGameType.BGT_ARENA, format=FormatType.FT_STANDARD, match_start=datetime(2018, 7, 15, tzinfo=pytz.utc), match_end=datetime(2018, 7, 15, minute=5, tzinfo=pytz.utc)) game.save() deck = _create_deck(TEST_TWITCH_DECK_STRING_1) _create_player("Test Player 1", 1, deck, game, rank=0) _create_player("Test Player 2", 2, deck, game, rank=0) replay = _create_replay(user, game) record_twitch_vod(replay, TEST_REPLAY_META) expected_vod = TwitchVod(hsreplaynet_user_id=user.id, rank=0, replay_shortid=replay.shortid, combined_rank="R0", **dict(TEST_TWITCH_VOD_PARAMS, game_type="BGT_ARENA")) actual_vod = TwitchVod.get(TEST_REPLAY_META["twitch_vod"]["channel_name"], "R0") # Patch the TTL expected_vod.ttl = actual_vod.ttl assert expected_vod == actual_vod
def test_vod_index_view(client, twitch_vod_game, user, mocker): mocker.patch("hsreplaynet.api.views.vods.classify_deck", return_value=123) mocker.patch.multiple( "hsreplaynet.api.views.vods.VodIndexView", authentication_classes=(), permission_classes=(), ) deck1 = create_deck_from_deckstring(TEST_TWITCH_DECKSTRING_1, archetype_id=123) deck2 = create_deck_from_deckstring(TEST_TWITCH_DECKSTRING_2, archetype_id=123) create_player("Test Player 1", 1, deck1, twitch_vod_game, rank=24) create_player("Test Player 2", 2, deck2, twitch_vod_game, rank=25) replay = create_replay(user, twitch_vod_game) record_twitch_vod(replay, TEST_TWITCH_VOD_META) response = client.get("/api/v1/vods/index/") assert response.status_code == status.HTTP_200_OK, \ "Got invalid response: %r" % response.data assert response.data == {123: [123]}
def test_record_twitch_vod(user, twitch_vod_game): deck1 = _create_deck(TEST_TWITCH_DECK_STRING_1, archetype_id=123) deck2 = _create_deck(TEST_TWITCH_DECK_STRING_2) _create_player("Test Player 1", 1, deck1, twitch_vod_game, rank=25) _create_player("Test Player 2", 2, deck2, twitch_vod_game, rank=25) replay = _create_replay(user, twitch_vod_game) record_twitch_vod(replay, TEST_REPLAY_META) expected_vod = TwitchVod(friendly_player_archetype_id=123, hsreplaynet_user_id=user.id, rank=25, replay_shortid=replay.shortid, combined_rank="R25", **TEST_TWITCH_VOD_PARAMS) actual_vod = TwitchVod.get(TEST_REPLAY_META["twitch_vod"]["channel_name"], "R25") # Patch the TTL expected_vod.ttl = actual_vod.ttl assert expected_vod == actual_vod
def test_record_twitch_vod_missing_language(user, twitch_vod_game): deck1 = create_deck_from_deckstring(TEST_TWITCH_DECK_STRING_1, archetype_id=123) deck2 = create_deck_from_deckstring(TEST_TWITCH_DECK_STRING_2) create_player("Test Player 1", 1, deck1, twitch_vod_game, rank=25) create_player("Test Player 2", 2, deck2, twitch_vod_game, rank=25) replay = create_replay(user, twitch_vod_game) def prune_language(d: dict): return {k: v for k, v in d.items() if k != "language"} replay_meta_no_language = { "twitch_vod": prune_language(TEST_REPLAY_META["twitch_vod"]) } expected_twitch_vod_params = prune_language(TEST_TWITCH_VOD_PARAMS) record_twitch_vod(replay, replay_meta_no_language) expected_vod = TwitchVod(friendly_player_archetype_id=123, hsreplaynet_user_id=user.id, rank=25, replay_shortid=replay.shortid, combined_rank="R25", **expected_twitch_vod_params) actual_vod = TwitchVod.get(TEST_REPLAY_META["twitch_vod"]["channel_name"], "R25") # Patch the TTL expected_vod.ttl = actual_vod.ttl assert expected_vod == actual_vod
def test_record_twitch_vod_legend_rank(user, twitch_vod_game): deck1 = create_deck_from_deckstring(TEST_TWITCH_DECK_STRING_1, archetype_id=123) deck2 = create_deck_from_deckstring(TEST_TWITCH_DECK_STRING_2, archetype_id=456) create_player("Test Player 1", 1, deck1, twitch_vod_game, rank=0, legend_rank=50) create_player("Test Player 2", 2, deck2, twitch_vod_game, rank=0, legend_rank=49) replay = create_replay(user, twitch_vod_game) record_twitch_vod(replay, TEST_REPLAY_META) expected_vod = TwitchVod( friendly_player_archetype_id=123, hsreplaynet_user_id=user.id, legend_rank=50, opposing_player_archetype_id=456, rank=0, replay_shortid=replay.shortid, combined_rank="L50", **TEST_TWITCH_VOD_PARAMS ) actual_vod = TwitchVod.get(TEST_REPLAY_META["twitch_vod"]["channel_name"], "L50") # Patch the TTL expected_vod.ttl = actual_vod.ttl assert expected_vod == actual_vod
def test_vod_list_view_at_legend_rank(client, twitch_vod_game, user, mocker): # noqa: F811 mocker.patch.multiple( "hsreplaynet.api.views.vods.VodListView", authentication_classes=(), permission_classes=(), ) deck1 = create_deck_from_deckstring(TEST_TWITCH_DECKSTRING_1, archetype_id=123) deck2 = create_deck_from_deckstring(TEST_TWITCH_DECKSTRING_2) create_player("Test Player 1", 1, deck1, twitch_vod_game, rank=None, legend_rank=1) create_player("Test Player 2", 2, deck2, twitch_vod_game, rank=None, legend_rank=2) replay = create_replay(user, twitch_vod_game) record_twitch_vod(replay, TEST_TWITCH_VOD_META) response = client.get("/api/v1/vods/?user_id=%s" % (user.id)) assert response.status_code == status.HTTP_200_OK, \ "Got invalid response: %r" % response.data assert type(response.data) == list channel_name = TEST_TWITCH_VOD_META["twitch_vod"]["channel_name"] url = TEST_TWITCH_VOD_META["twitch_vod"]["url"] assert response.data == [{ "channel_name": channel_name, "language": "en", "url": url, "game_date": "2018-07-15T00:00:00Z", "game_type": "BGT_RANKED_STANDARD", "rank": 0, "legend_rank": 1, "friendly_player_archetype_id": 123, "opposing_player_class": "PRIEST", "opposing_player_archetype_id": None, "won": False, "went_first": True, "game_length_seconds": 300, "replay_shortid": replay.shortid, }]
def test_record_twitch_vod_dynamodb_exception(user, twitch_vod_game): deck = create_deck_from_deckstring(TEST_TWITCH_DECK_STRING_1) create_player("Test Player 1", 1, deck, twitch_vod_game, rank=25) create_player("Test Player 2", 2, deck, twitch_vod_game, rank=25) replay = create_replay(user, twitch_vod_game) def put_item_raise(*_args, **_kwargs): raise PutError() with patch.object(TableConnection, "put_item", put_item_raise): record_twitch_vod(replay, TEST_REPLAY_META) with raises(DoesNotExist): TwitchVod.get(TEST_REPLAY_META["twitch_vod"]["channel_name"], "R25")
def test_record_twitch_vod_missing_rank(user, twitch_vod_game): deck = create_deck_from_deckstring(TEST_TWITCH_DECK_STRING_1) create_player("Test Player 1", 1, deck, twitch_vod_game, rank=None) create_player("Test Player 2", 2, deck, twitch_vod_game, rank=None) replay = create_replay(user, twitch_vod_game) record_twitch_vod(replay, TEST_REPLAY_META) expected_vod = TwitchVod(hsreplaynet_user_id=user.id, rank=0, replay_shortid=replay.shortid, combined_rank="R0", **TEST_TWITCH_VOD_PARAMS) actual_vod = TwitchVod.get(TEST_REPLAY_META["twitch_vod"]["channel_name"], "R0") # Patch the TTL expected_vod.ttl = actual_vod.ttl assert expected_vod == actual_vod