def test_process_raw_upload_timeout(mocker): moto_s3_storage = S3Boto3Storage(access_key="test", auto_create_bucket=True, bucket="hsreplaynet-replays", secret_key="test") mocker.patch("django.core.files.storage.default_storage._wrapped", moto_s3_storage) raw_upload = MockRawUpload( os.path.join(LOG_DATA_DIR, "hsreplaynet-tests", "uploads", "2hwp7nDJMyWvrHQGBYTvVM"), moto_s3_storage) from botocore.vendored.requests.packages.urllib3.exceptions import ReadTimeoutError mocker.patch.object(S3Boto3Storage, "open") S3Boto3Storage.open.side_effect = ReadTimeoutError(None, None, "Read timed out.") with pytest.raises(ValidationError): process_raw_upload(raw_upload, False) upload_event = UploadEvent.objects.get(shortid=raw_upload.shortid) assert upload_event.status == UploadEventStatus.VALIDATION_ERROR assert upload_event.error is not None assert S3Boto3Storage.open.call_count == 2
def test_process_raw_upload_to_dynamodb(mocker, settings): mocker.patch( "hsreplaynet.games.processing.update_player_class_distribution") mocker.patch("hsreplaynet.games.processing.update_replay_feed") mocker.patch("hsreplaynet.games.processing.update_game_counter") settings.LOAD_REPLAYS_INTO_DYNAMODB = True settings.FULL_DECK_PREDICTION_ENABLED = False settings.REDSHIFT_LOADING_ENABLED = False raw_upload = MockRawUpload( os.path.join(LOG_DATA_DIR, "hsreplaynet-tests", "uploads", "u4HUJnBGVpytdFVWgNumfU"), default_storage) process_raw_upload(raw_upload) user = raw_upload.auth_token.user user_id = int(user.id) rows = DynamoDBGameReplay.query(user_id) replay = rows.next() assert replay.user_id == user_id assert replay.match_start == 1534252613613 assert replay.short_id == raw_upload.shortid assert replay.game_type_match_start == "2:1534252613613" assert replay.ladder_season == 58 assert replay.brawl_season is None assert replay.scenario_id == 2 assert replay.num_turns == 33 assert replay.opponent_predicted_deck is None
def do_process_raw_upload(raw_upload, is_reprocessing): process_raw_upload(raw_upload, is_reprocessing) # Begin asserting correctness created_upload_event = UploadEvent.objects.get(shortid=raw_upload.shortid) assert str(created_upload_event.token_uuid) == str( raw_upload.auth_token.key) source_ip = raw_upload.descriptor["event"]["requestContext"]["identity"][ "sourceIp"] assert created_upload_event.upload_ip == source_ip replay = created_upload_event.game assert replay.opponent_revealed_deck is not None assert replay.opponent_revealed_deck.size > 0 validate_fuzzy_date_match(raw_upload.timestamp, replay.global_game.match_start) validate_player_data(raw_upload, replay, 1) validate_player_data(raw_upload, replay, 2) for player_id in (1, 2): for card in replay.global_game.players.get( player_id=player_id).deck_list: assert card.collectible replay_data = HSReplayDocument.from_xml_file(replay.replay_xml) exporter = GameDigestExporter(replay_data.to_packet_tree()[0]) exporter.export() assert exporter.digest == replay.global_game.digest
def do_process_raw_upload(raw_upload, is_reprocessing): process_raw_upload(raw_upload, is_reprocessing) # Begin asserting correctness created_upload_event = UploadEvent.objects.get(shortid=raw_upload.shortid) assert str(created_upload_event.token.key) == str(raw_upload.auth_token.key) assert created_upload_event.upload_ip == raw_upload.source_ip replay = created_upload_event.game validate_fuzzy_date_match(raw_upload.timestamp, replay.global_game.match_start) validate_player_data(raw_upload, replay, 1) validate_player_data(raw_upload, replay, 2)
def do_process_raw_upload(raw_upload, is_reprocessing): process_raw_upload(raw_upload, is_reprocessing) # Begin asserting correctness created_upload_event = UploadEvent.objects.get(shortid=raw_upload.shortid) assert str(created_upload_event.token.key) == str(raw_upload.auth_token.key) assert created_upload_event.upload_ip == raw_upload.source_ip replay = created_upload_event.game assert replay.opponent_revealed_deck is not None assert replay.opponent_revealed_deck.size > 0 validate_fuzzy_date_match(raw_upload.timestamp, replay.global_game.match_start) validate_player_data(raw_upload, replay, 1) validate_player_data(raw_upload, replay, 2)
def test_process_raw_upload_corrupt(mocker): moto_s3_storage = S3Boto3Storage(access_key="test", auto_create_bucket=True, bucket="hsreplaynet-replays", gzip_content_types=(), secret_key="test") mocker.patch("django.core.files.storage.default_storage._wrapped", moto_s3_storage) mocker.patch("storages.backends.s3boto3.mimetypes.guess_type", lambda name: (None, "gzip")) raw_upload = MockRawUpload( os.path.join(LOG_DATA_DIR, "hsreplaynet-tests", "uploads-invalid", "gzip-corrupt"), moto_s3_storage) with pytest.raises(ValidationError): process_raw_upload(raw_upload, False) upload_event = UploadEvent.objects.get(shortid=raw_upload.shortid) assert upload_event.status == UploadEventStatus.VALIDATION_ERROR assert upload_event.error is not None
def do_process_raw_upload(raw_upload, is_reprocessing): process_raw_upload(raw_upload, is_reprocessing) # Begin asserting correctness created_upload_event = UploadEvent.objects.get(shortid=raw_upload.shortid) assert str(created_upload_event.token.key) == str( raw_upload.auth_token.key) source_ip = raw_upload.descriptor["event"]["requestContext"]["identity"][ "sourceIp"] assert created_upload_event.upload_ip == source_ip replay = created_upload_event.game assert replay.opponent_revealed_deck is not None assert replay.opponent_revealed_deck.size > 0 validate_fuzzy_date_match(raw_upload.timestamp, replay.global_game.match_start) validate_player_data(raw_upload, replay, 1) validate_player_data(raw_upload, replay, 2) for player_id in (1, 2): for card in replay.global_game.players.get( player_id=player_id).deck_list: assert card.type != CardType.HERO