Exemplo n.º 1
0
def test_find_instance_by_uuid(context):
    ("user.find_instance_by_uuid should return a list of users with no element or a single one"
     )

    # Given I have an existing user
    first_name = 'Guido'
    email = '*****@*****.**'
    password = '******'
    user = User(first_name, email, password)
    user.persist()
    context.objects.append(user)

    # And that I call the find_instance_by_email with the user email
    result = User.find_instance_by_uuid(user.uuid)

    # Then the result should be a list
    result.should.be.a(list)

    # And the list should have an unique element
    len(result).should.equal(1)

    # And the user should be in the list
    user.should.be.within(result)

    # However if I call the find_instance_by_email with an invalid email
    result = User.find_instance_by_uuid("herecomesaninvalidUUID")

    # Then the result should be a list
    result.should.be.a(list)

    # And the list should be empty
    result.should.be.empty
Exemplo n.º 2
0
def edit_database_user(**kwargs):
    ''' Interface to edit user database entry
        Should receive UUID and first_name and/or email and/or password
        Will return first_name, email and uuid upon success
    '''
    user_list = User.find_instance_by_uuid(kwargs.get(enums.UUID_KEY))
    if user_list:
        user = user_list[0]
        first_name = kwargs.get(enums.FIRST_NAME_KEY)
        email = kwargs.get(enums.EMAIL_KEY)
        if email and User.find_instance_by_email(email):
            raise Exception(f'Could not edit user: {email} already in use')

        password = kwargs.get(enums.PASSWORD_KEY)
        if any([first_name, email, password]):
            try:
                user.edit_user(first_name, email, password)
                user.persist()
                return user.payload()
            except Exception as err:
                raise Exception(f'Could not edit user: {err}')

        else:
            raise Exception('No new user information was passed in')

    else:
        raise Exception('No user was found for the given UUID')
Exemplo n.º 3
0
def get_database_user(**kwargs):
    ''' Interface to get user database entry
        Should receive UUID
    '''
    uuid = kwargs.get(enums.UUID_KEY)
    user_list = User.find_instance_by_uuid(uuid)
    if user_list:
        user = user_list[0]
        return user.payload()

    else:
        raise Exception(f'No user was found for the passed in UUID {uuid}')