def test_create_todos(self): ''' test the creation of todos ''' self.create_todos() self.assertEqual(Todo.select().count(), 2) self.assertEqual( Todo.select().get().name, 'Walk Dog' )
def test_get_single_todo(self): TodoModelTestCase.create_todos() user = User.select().get() headers = UserModelTestCase.get_headers(user) response = self.app.get('/api/v1/todos/' + str(Todo.select().get().id), headers=headers) self.assertEqual(response.status_code, 200) self.assertEqual(Todo.select().get().name, 'Walk Dog')
def test_delete_todo(self): TodoModelTestCase.create_todos() user = User.select().get() headers = UserModelTestCase.get_headers(user) response = self.app.delete('/api/v1/todos/' + str(Todo.select().get().id), headers=headers) self.assertEqual(response.status_code, 204) self.assertNotEqual(Todo.select().get().name, 'Walk Dog') self.assertEqual(response.location, 'http://localhost/api/v1/todos')
def test_put_todo(self): TodoModelTestCase.create_todos() user = User.select().get() headers = UserModelTestCase.get_headers(user) todo_data = {'name': 'Feed Dog'} response = self.app.put('/api/v1/todos/' + str(Todo.select().get().id), data=todo_data, headers=headers) self.assertEqual(response.status_code, 200) self.assertEqual(Todo.select().get().name, 'Feed Dog') self.assertEqual(response.location, 'http://localhost/api/v1/todos/1')
def test_good_post_todo(self): UserModelTestCase.create_users(1) user = User.select().get() todo_data = { 'name': 'Finish Project', 'created_by': user.id } headers = UserModelTestCase.get_headers(user) response = self.app.post('/api/v1/todos', data=todo_data, headers=headers) self.assertEqual(response.status_code, 201) self.assertEqual(Todo.select().get().name, 'Finish Project') self.assertEqual(response.location, 'http://localhost/api/v1/todos/1')