Example #1
0
def test_get_all_instances(context):
    ("user.get_all_instances should return a list of users")

    # Given that I have already users in the database
    first_name_1 = 'Guido'
    email_1 = '*****@*****.**'
    password_1 = 'py123'
    user_created_1 = User(first_name_1, email_1, password_1)
    user_created_1.persist()
    context.objects.append(user_created_1)

    first_name_2 = 'Raymond'
    email_2 = '*****@*****.**'
    password_2 = 'py567'
    user_created_2 = User(first_name_2, email_2, password_2)
    user_created_2.persist()
    context.objects.append(user_created_2)

    # And that I call get_all_instances
    result = User.get_all_instances()

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

    # And the users payload should be in the list
    user_created_1.should.be.within(result)
    user_created_2.should.be.within(result)
Example #2
0
def get_database_users(**kwargs):
    ''' Interface to get user database entries
    '''
    user_list = User.get_all_instances()
    if user_list:
        return [user.payload() for user in user_list]

    else:
        raise Exception('No user found in the database')