def modify_profile():
    """Permite a un usuario actualizar su perfil"""
    if not request.is_json:
        abort(400)
    data = request.get_json()
    uid = get_jwt_identity()
    UserService.modify_profile(uid, data)
    return jsonify(result='success'), 200
def register():
    """Servicio de registro: permite a los usuarios darse de alta en el sistema."""
    if not request.is_json:
        abort(400)
    data = request.get_json()
    uid = UserService.register(data)
    return jsonify(result='success', uid=uid), 200
def login():
    """Servicio de autenticación: permite a los usuarios poder ingresar al sistema con
    un token de firebase, obteniendo un token para utilizar con los demás servicios."""
    if not request.is_json:
        abort(400)
    firebase_token = request.get_json()
    access_token = UserService.login(firebase_token)
    return jsonify(token=access_token), 200
def get_profile():
    """Permite consultar el perfil de un usuario"""
    uid = get_jwt_identity()
    user = UserService.get_profile(uid)
    return jsonify(user), 200
Exemplo n.º 5
0
def test_get_profile_if_not_found_raises_not_found_error(
        get_one_mock, user_data):
    get_one_mock.return_value = None
    with pytest.raises(NotFoundError):
        UserService.get_profile(user_data.uid)
Exemplo n.º 6
0
def test_register_if_wrong_schema_raises_validation_error(user_data):
    with pytest.raises(ValidationError):
        UserService.register(user_data.invalid_user)
Exemplo n.º 7
0
def test_register_if_user_exists_raises_user_exists_error(
        user_exists_mock, user_data):
    user_exists_mock.return_value = True
    with pytest.raises(DataExistsError):
        UserService.register(user_data.valid_user)
Exemplo n.º 8
0
def test_modify_profile_if_wrong_schema_raises_validation_error(user_data):
    with pytest.raises(ValidationError):
        UserService.modify_profile(user_data.uid, user_data.invalid_user)
Exemplo n.º 9
0
def test_login_if_user_not_found_raises_not_found_error(
        firebase_mock, um_mock, user_data):
    firebase_mock.return_value = user_data.valid_user
    um_mock.return_value = None
    with pytest.raises(NotFoundError):
        UserService.login(user_data.valid_token)