def make_user(login, nickname):
    try:
        return User.objects(test_login=login).get()
    except User.DoesNotExist:
        u = User(test_login=login, nickname=nickname)
        u.save()
        return u
def test_login():
    if not request.is_json:
        return jsonify({'msg': 'Missing JSON in request', 'err': True}), 400
    name = request.json.get('name', None)
    if not name:
        return jsonify({'msg': 'No name provided', 'err': True}), 400
    test_login = f'test-{name}'
    user = User.objects(test_login=test_login).upsert_one(
        set_on_insert__nickname=name)
    user.save()
    token = create_access_token(identity=str(user.id),
                                user_claims={'nickname': user.nickname})
    return jsonify(access_token=token), 200