def test_get_handler_one(self): client, table = init() item = {'item': 'I need to finish this test!', 'completed': True} created = create(client, '1', item, table.table_name, ['completed', 'item']) event = { 'queryStringParameters': { 'id': created['todoId'] }, 'requestContext': { 'authorizer': { 'claims': { 'cognito:username': '******' } } } } results = handler(event, {}) # not using the context, so no need to mock it. # Verify the results are not null assert results # Verify the status code is '200' assert 'statusCode' in results and results['statusCode'] == '200' # Verify the contents of the body assert 'body' in results body = json.loads(results['body']) # Verify that the UUIDs were set assert body['userId'] == '1' assert body['todoId'] and len(body['todoId']) == 36 # Verify the items that a user can set were set correctly. assert body['item'] == created['item'] assert body['completed']
def test_get_handler_all(self): client, table = init() items = [{ 'item': 'A', 'completed': True }, { 'item': 'B', 'completed': False }, { 'item': 'C', 'completed': True }] # The first two will be created for user '1' the third for '2' create(client, '1', items[0], table.table_name, ['completed', 'item']) create(client, '1', items[1], table.table_name, ['completed', 'item']) create(client, '2', items[2], table.table_name, ['completed', 'item']) event = { 'requestContext': { 'authorizer': { 'claims': { 'cognito:username': '******' } } } } results = handler(event, {}) # not using the context, so no need to mock it. # Verify the results are not null assert results # Verify the status code is '200' assert 'statusCode' in results and results['statusCode'] == '200' # Verify the contents of the body assert 'body' in results body = json.loads(results['body']) assert len(body) == 2 # Verify that the correct records are returned assert all([i['userId'] == '1' for i in body]) assert all([len(i['todoId']) == 36 for i in body])