def todo_list(event, context): # fetch all todos from the database results = TodoModel.scan() # create a response return {'statusCode': 200, 'body': json.dumps({'items': [dict(result) for result in results]})}
def test_delete(self): found_todos = TodoModel.scan() todos = [result for result in found_todos] self.assertEquals(len(todos), 1) self.assertEquals(todos[0].text, 'text of d490d766-8b60-11e7-adba-e0accb8996e6') self.assertEquals(todos[0].todo_id, 'd490d766-8b60-11e7-adba-e0accb8996e6')
def todo_list(event, context): # fetch all todos from the database results = TodoModel.scan() # create a response return { 'statusCode': 200, 'body': json.dumps({'items': [dict(result) for result in results]}) }
def todo_list(event, context): # fetch all todos from the database results = TodoModel.scan() # create a response return { 'statusCode': 200, 'headers': { 'Access-Control-Allow-Origin': todos.config.aws['allow-origin'], }, 'body': json.dumps({'items': [dict(result) for result in results]}) }
def test_create(self): todo_text = 'text' todo_id = str(uuid.uuid1()) t1 = TodoModel(todo_id=todo_id, text=todo_text, created_at=datetime.now()) t1.save() self.assertEquals(t1.text, todo_text) self.assertEquals(t1.checked, False) t2 = TodoModel.get(hash_key=todo_id) self.assertEquals(t2.text, todo_text) r = [result for result in TodoModel.scan()] self.assertEquals(len(r), 1) self.assertEquals(r[0].text, todo_text) self.assertEquals(r[0].todo_id, todo_id) t2.delete()
def handle(event, context): try: table_name = os.environ[ENV_VAR_DYNAMODB_TABLE] region = os.environ[ENV_VAR_DYNAMODB_REGION] except KeyError as err: error_message = '{0} is missing from environment variables'.format( str(err)) return HttpResponseServerError(error_code='ENV_VAR_NOT_SET', error_message=error_message).__dict__() TodoModel.setup_model(TodoModel, region, table_name, ENV_VAR_ENVIRONMENT not in os.environ) # fetch all todos from the database results = TodoModel.scan() # create a response items = {'items': [dict(result) for result in results]} return HttpOkJSONResponse(body=items).__dict__()