def test_proto_upload_with_tags(self, test_client): proto, pandas, proto_game = write_proto_pandas_to_file(get_test_file(get_complex_replay_list()[0], is_replay=True)) with open(proto, 'rb') as f: encoded_proto = base64.b64encode(zlib.compress(f.read())).decode() with open(pandas, 'rb') as f: encoded_pandas = base64.b64encode(zlib.compress(f.read())).decode() obj = { 'status': '200', 'proto': encoded_proto, 'pandas': encoded_pandas } r = Request('POST', LOCAL_URL + '/api/upload/proto', json=obj, params={'tags': [TAG_NAME, TAG_NAME + "hello"], 'player_id': proto_game.players[0].id.id}) response = test_client.send(r) assert(response.status_code == 200) fake_session = get_current_session() game = fake_session.query(Game).first() assert(game.hash == '70DDECEA4653AC55EA77DBA0DB497995') assert(game.name == '3 kickoffs 4 shots') assert(len(game.tags) == 2) assert(game.tags[0].name == TAG_NAME) assert(game.tags[0].owner == proto_game.players[0].id.id) assert(game.tags[0].games[0] == game) assert(game.tags[1].name == (TAG_NAME + "hello")) player = fake_session.query(Player.platformid == proto_game.players[0].id.id).first() assert(player is not None)
def test_heatmaps(self): proto, pandas, proto_game = write_proto_pandas_to_file( get_test_file("3_DRIBBLES_2_FLICKS.replay", is_replay=True)) f = download_replay_discord("3_DRIBBLES_2_FLICKS.replay") r = requests.post(LOCAL_URL + '/api/upload', files={'replays': ('fake_file.replay', f)}) r.raise_for_status() assert (r.status_code == 202) time.sleep(30) r = requests.get(LOCAL_URL + '/api/global/replay_count') result = json.loads(r.content) assert int(result) > 0 # actual test id = proto_game.game_metadata.match_guid r = requests.get(LOCAL_URL + '/api/replay/' + id + '/heatmaps') r.raise_for_status() assert r.status_code == 200 result = json.loads(r.content) assert 'data' in result assert 'maxs' in result def assert_keys(value): assert 'ball' in value assert proto_game.players[0].name in value assert_keys(result['data']) assert_keys(result['maxs'])
def test_proto_upload_with_privacy(self, test_client): proto, pandas, proto_game = write_proto_pandas_to_file(get_test_file(get_complex_replay_list()[0], is_replay=True)) with open(proto, 'rb') as f: encoded_proto = base64.b64encode(zlib.compress(f.read())).decode() with open(pandas, 'rb') as f: encoded_pandas = base64.b64encode(zlib.compress(f.read())).decode() obj = { 'status': '200', 'proto': encoded_proto, 'pandas': encoded_pandas } r = Request('POST', LOCAL_URL + '/api/upload/proto', json=obj, params={'visibility': GameVisibilitySetting.PRIVATE.name, 'player_id': proto_game.players[0].id.id}) response = test_client.send(r) assert(response.status_code == 200) fake_session = get_current_session() game = fake_session.query(Game).first() assert(game.hash == '70DDECEA4653AC55EA77DBA0DB497995') assert(game.name == '3 kickoffs 4 shots') assert(game.visibility == GameVisibilitySetting.PRIVATE) game_visiblity = fake_session.query(GameVisibility).first() assert(game_visiblity.game == game.hash) assert(game_visiblity.player == proto_game.players[0].id.id) assert(game_visiblity.visibility == GameVisibilitySetting.PRIVATE) assert(game_visiblity.release_date == datetime.max) player = fake_session.query(Player.platformid == proto_game.players[0].id.id).first() assert(player is not None)
def test_upload_proto(self): proto, pandas, proto_game = write_proto_pandas_to_file(get_test_file("3_KICKOFFS_4_SHOTS.replay", is_replay=True)) with open(proto, 'rb') as f: encoded_proto = base64.b64encode(zlib.compress(f.read())).decode() with open(pandas, 'rb') as f: encoded_pandas = base64.b64encode(zlib.compress(f.read())).decode() obj = { 'status': '200', 'proto': encoded_proto, 'pandas': encoded_pandas } r = requests.post(LOCAL_URL + '/api/upload/proto', json=obj, params={'tags': ['TAG'], 'visibility': GameVisibilitySetting.PRIVATE.name, 'player_id': proto_game.players[0].id.id}) r.raise_for_status() assert r.status_code == 200 r = requests.get(LOCAL_URL + '/api/global/replay_count') result = json.loads(r.content) assert int(result) == 1 response = requests.get(LOCAL_URL + '/api/tag') result = json.loads(response.content) assert result[0]['owner_id'] == "76561198018756583" assert result[0]['name'].startswith('TAG') assert len(result) == 1 response = requests.get(LOCAL_URL + '/api/player/76561198018756583/match_history?page=0&limit=10') assert response.status_code == 200 assert len(response.json()['replays']) >= 1
def test_parse_replay(self, temp_folder): write_files_to_disk([get_complex_replay_list()[0]], temp_folder=temp_folder) result = parse_replay_task.apply(throw=True, kwargs={ 'replay_to_parse_path': get_test_file( '3_KICKOFFS_4_SHOTS.replay', temp_folder=temp_folder), 'force_reparse': True }).get() assert (result == '70DDECEA4653AC55EA77DBA0DB497995')
def test_heatmaps(self, use_test_paths, temp_file): use_test_paths.patch() test_path = use_test_paths.get_temp_path() proto, pandas, proto_game = write_proto_pandas_to_file( get_test_file("ALL_STAR.replay", is_replay=True)) with open(proto, 'rb') as f: encoded_proto = base64.b64encode(zlib.compress(f.read())).decode() obj = {'status': '200', 'proto': encoded_proto} r = requests.post(LOCAL_URL + '/api/upload/proto', json=obj) r.raise_for_status() assert (r.status_code == 200) save_replay(proto_game, temp_file, pandas[:-len(PANDAS_EXTENSION)], proto[:-len(PROTO_EXTENSION)]) r = requests.get(LOCAL_URL + '/api/global/replay_count') result = json.loads(r.content) assert int( result ) > 0, 'This test can not run without a replay in the database' # test default self.assert_heatmap(proto_game, has_ball=True) # test query params self.assert_heatmap( proto_game, query_params={"type": HeatMapType.POSITIONING.value}, has_ball=True) self.assert_heatmap(proto_game, query_params={"type": HeatMapType.BOOST.value}) self.assert_heatmap( proto_game, query_params={"type": HeatMapType.BOOST_COLLECT.value}) self.assert_heatmap( proto_game, query_params={"type": HeatMapType.BOOST_SPEED.value}) self.assert_heatmap( proto_game, query_params={"type": HeatMapType.SLOW_SPEED.value})
def test_heatmaps(self): proto, pandas, proto_game = write_proto_pandas_to_file(get_test_file("ALL_STAR.replay", is_replay=True)) f = download_replay_discord("ALL_STAR.replay") r = requests.post(LOCAL_URL + '/api/upload', files={'replays': ('fake_file.replay', f)}) r.raise_for_status() assert(r.status_code == 202) time.sleep(35) r = requests.get(LOCAL_URL + '/api/global/replay_count') result = json.loads(r.content) assert int(result) > 0, 'This test can not run without a replay in the database' # test default self.assert_heatmap(proto_game, has_ball=True) # test query params self.assert_heatmap(proto_game, query_params={"type": HeatMapType.POSITIONING.value}, has_ball=True) self.assert_heatmap(proto_game, query_params={"type": HeatMapType.BOOST.value}) self.assert_heatmap(proto_game, query_params={"type": HeatMapType.BOOST_COLLECT.value}) self.assert_heatmap(proto_game, query_params={"type": HeatMapType.BOOST_SPEED.value}) self.assert_heatmap(proto_game, query_params={"type": HeatMapType.SLOW_SPEED.value})