Beispiel #1
0
def delete(name):
    errors = {}
    if remove_program(name):
        return True, {}, None

    else:
        errors["name"] = get_response_error("PROGRAM_NOT_FOUND")
        return False, None, errors
Beispiel #2
0
def execute_login(user, password):
    # Check that an unencrypted password matches one that has
    # previously been hashed
    if bcrypt.hashpw(password, user.password) == user.password:
        token = generate_token(user.uuid)
        return True, {"token": token}, None
    else:
        return False, None, {"email": get_response_error("WRONG_EMAIL")}
Beispiel #3
0
def update(model, bits=None, ram=None, rom=None):
    errors = dict()
    if modify_program(model, bits, ram, rom):
        return True, {}, None

    else:
        errors["model"] = get_response_error("PROGRAM_NOT_FOUND")
        return False, None, errors
Beispiel #4
0
def unlike(user_id, artist_id):
    errors = {}

    user = get_user_by_id(user_id)
    artist = get_artist_by_id(artist_id)
    if not user:
        errors["user"] = get_response_error("USER_ID_NOT_FOUND")
    if not artist:
        errors["id"] = get_response_error("ARTIST_ID_NOT_FOUND")

    if artist and user:
        if unlike_artist(user_id, artist_id):
            return True, {}, None
        else:
            return False, None, {}

    if errors:
        return False, None, errors
Beispiel #5
0
def get(id):
    errors = {}
    artist = get_artist_by_id(id)
    if artist:
        return True, {"artist": artist}, None
    else:
        errors["id"] = get_response_error("ARTIST_ID_NOT_FOUND")

    if errors:
        return False, None, errors
Beispiel #6
0
def login(email, password):
    errors = {}

    user = get_user_by_email(email)

    if not user or not user.enabled:
        errors["email"] = get_response_error("WRONG_EMAIL")
    if errors:
        return False, None, errors

    return execute_login(user, password)
Beispiel #7
0
def register(email, password):
    errors = {}

    user = get_user_by_email(email)

    if user:
        errors["email"] = get_response_error("EMAIL_ALREADY_REGISTERED")
    if errors:
        return False, None, errors

    return execute_register(email, password)
Beispiel #8
0
def delete(id):
    errors = {}

    if delete_artist(id):
        return True, {}, None
    else:
        errors["id"] = get_response_error("ARTIST_ID_NOT_FOUND")

    if errors:
        return False, None, errors

    return create_artist(email, password)
Beispiel #9
0
def update(id, name, biography):
    errors = {}

    if update_artist(id, name, biography):
        # get updated artist
        artist = get_artist_by_id(id)
        return True, {"artist": artist}, None
    else:
        errors["id"] = get_response_error("ARTIST_ID_NOT_FOUND")

    if errors:
        return False, None, errors
Beispiel #10
0
def create(name, biography):
    errors = {}
    artist = get_artist_by_name(name)

    if artist:
        errors["name"] = get_response_error("ARTIST_NAME_ALREADY_EXISTS")
    else:
        artist = create_artist(name, biography)
        return True, {"artist": artist}, None

    if errors:
        return False, None, errors
Beispiel #11
0
def create(name, version, computer_model):
    errors = {}

    program = get_program_by_name(name)

    if program:
        errors["name"] = get_response_error("PROGRAM_DOES_EXIST")

    if errors:
        return False, None, errors

    program = add_program(name, version, computer_model)

    return True, {"program": program}, None
Beispiel #12
0
def test_integration_create_artist_fail():
    request = Request()
    input_data = {
        'name': '',
        'biography': 'American composer, pianist and bandleader of a jazz orchestra.',
    }
    
    request['body'] = input_data

    # create artist
    artist = create_artist(**input_data)

    # execute
    controller = Create()
    result = controller.post(request)

    assert result['status'] == 400
    assert result['body']['name'] == get_response_error("CANT_BE_EMPTY")
def unauthorized():
    return Unauthorized({"error": get_response_error("NOT_LOGGED")})
Beispiel #14
0
def test_error_key_ok():
    error = get_response_error("NOT_LOGGED")
    assert error["code"] == "NOT_LOGGED"
    assert error["message"] == "You need to login"
Beispiel #15
0
def test_error_key_error():
    with pytest.raises(ErrorKeyDoesntExistError):
        get_response_error("NOT_LOGGEDDDD")