def test_key_encode_decode(self):
     ids = [10, 20000, 5, 12345678, 5, 20, 5]
     keys = [
         '10', '::::', 'banana', 'abcdefghijklmnopqrstuvwxyz', '', 'test',
         '!@#$%^&*()+'
     ]
     for index, id in enumerate(ids):
         encoded = ServiceTag.encode_tag(id, keys[index])
         test_id, test_key = ServiceTag.decode_tag(encoded)
         assert test_id == id
         assert test_key == keys[index]
    def test_tag_modification_with_private_key(self, test_client, mock_user):
        fake_session = get_current_session()
        r = Request('PUT', LOCAL_URL + '/api/tag/TAG')
        response = test_client.send(r)

        assert (response.status_code == 201)
        data = response.json
        assert data['name'] == 'TAG'
        assert data['owner_id'] == default_player_id()

        tag = fake_session.query(Tag).first()
        assert tag.name == 'TAG'
        assert tag.owner == default_player_id()
        assert tag.private_id is None

        r = Request('PUT',
                    LOCAL_URL + '/api/tag/TAG/private_key/fake_private_key')
        response = test_client.send(r)
        assert (response.status_code == 204)

        fake_session.close()
        fake_session = get_current_session()

        tag = fake_session.query(Tag).first()
        assert tag.name == 'TAG'
        assert tag.owner == default_player_id()
        assert tag.private_id == 'fake_private_key'

        r = Request('GET', LOCAL_URL + '/api/tag/TAG/private_key')
        response = test_client.send(r)

        assert (response.status_code == 200)
        assert response.json == ServiceTag.encode_tag(tag.id,
                                                      'fake_private_key')
    def test_replay_basic_server_upload_with_private_tags(
            self, test_client, mock_user):
        fake_session = get_current_session()
        game = fake_session.query(Game).first()
        assert game is None

        params = {'private_key': 'fake_private_key'}
        r = Request('PUT', LOCAL_URL + '/api/tag/' + TAG_NAME, params=params)
        response = test_client.send(r)

        assert (response.status_code == 201)

        tag = fake_session.query(Tag).first()

        r = Request('GET', LOCAL_URL + '/api/tag/' + TAG_NAME + '/private_key')
        response = test_client.send(r)

        encoded_key = ServiceTag.encode_tag(tag.id, tag.private_id)
        assert response.json == encoded_key

        params = {'private_tag_keys': [encoded_key]}
        r = Request('POST',
                    LOCAL_URL + '/api/upload',
                    files={'replays': ('fake_file.replay', self.stream)},
                    params=params)

        response = test_client.send(r)

        assert (response.status_code == 202)

        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) == 1)
        assert (game.tags[0].name == TAG_NAME)
        assert (game.tags[0].owner == default_player_id())
        assert (game.tags[0].games[0] == game)
        assert (game.tags[0].private_id == 'fake_private_key')

        player = fake_session.query(
            Player.platformid == '76561198018756583').first()
        assert (player is not None)
Beispiel #4
0
 def create_from_game(game: Game) -> 'Replay':
     return Replay(id_=game.hash,
                   name=game.name,
                   date=game.match_date.isoformat(),
                   map=game.map,
                   game_mode=get_playlist(game.playlist, game.teamsize),
                   game_score=GameScore.create_from_game(game),
                   players=[
                       ReplayPlayer.create_from_player_game(player_game)
                       for player_game in sort_player_games_by_team_then_id(
                           cast(List[PlayerGame], game.playergames))
                   ],
                   tags=[
                       Tag.create_from_dbtag(tag) for tag in game.tags
                       if tag.owner == get_current_user_id()
                   ],
                   visibility=game.visibility,
                   ranks=game.ranks,
                   mmrs=game.mmrs)
def api_remove_tag_from_game(name: str, id_: str):
    Tag.remove_tag_from_game(name, id_)
    return '', 204
def api_add_tag_to_game(name: str, id_: str):
    Tag.add_tag_to_game(name, id_)
    return '', 204
def api_add_tag_key(name: str, private_id: str):
    Tag.add_private_key(name, private_id)
    return better_jsonify(private_id), 204
def api_get_tag_key(name: str):
    return better_jsonify(Tag.get_encoded_private_key(name))
def api_get_tags(query_params=None):
    tags = Tag.get_all()
    with_id = False
    if 'with_id' in query_params:
        with_id = query_params['with_id']
    return better_jsonify([tag.to_JSON(with_id=with_id) for tag in tags])
def api_delete_tag(name: str):
    Tag.delete(name)
    return '', 204
def api_rename_tag(current_name: str):
    accepted_query_params = [QueryParam(name='new_name')]
    query_params = get_query_params(accepted_query_params, request)

    tag = Tag.rename(current_name, query_params['new_name'])
    return better_jsonify(tag), 200
def api_create_tag(name: str, query_params=None):
    private_key = None
    if 'private_key' in query_params:
        private_key = query_params['private_key']
    tag = Tag.create(name, private_key=private_key)
    return better_jsonify(tag), 201