示例#1
0
 def public_id_generator(lottery, kind):
     """return list of winners' public_id for selected 'kind'
         original at: L.336, written by @tamazasa
     """
     for app in lottery.application:
         if app.status == 'won' and app.user.kind == kind:
             yield encode_public_id(app.user.public_id)
示例#2
0
def translate_secret_to_public(secret_id):
    """translate secret_id into public_id
        This will used for checking the guests at each classes
    """
    user = User.query.filter_by(secret_id=secret_id).first()
    if not user:
        return error_response(5)  # no such user found
    else:
        return jsonify({"public_id": encode_public_id(user.public_id)})
示例#3
0
def test_translate_user_ids(client):
    """test it return a vaild response
        test: response contains correct public_id
        target_url: /public_id
    """
    token_user = admin
    target_user = test_user
    token = login(client, token_user['secret_id'], '')['token']
    resp = client.get('public_id/' + target_user['secret_id'],
                      headers={'Authorization': f'Bearer {token}'})

    with client.application.app_context():
        public_id = User.query.filter_by(
            secret_id=target_user['secret_id']).first().public_id

    assert resp.status_code == 200
    assert resp.get_json()['public_id'] == encode_public_id(public_id)
示例#4
0
 def get_public_id_str(self, group_member):
     return encode_public_id(group_member.user.public_id)
示例#5
0
 def get_public_id_str(self, user):
     return encode_public_id(user.public_id)