def test_create_user(self): ''' test the creation of the user ''' self.create_users() self.assertEqual(User.select().count(), 2) self.assertNotEqual( User.select().get().password, 'password' )
def test_get_single_todo_does_not_exist(self): TodoModelTestCase.create_todos() user = User.select().get() headers = UserModelTestCase.get_headers(user) response = self.app.get('/api/v1/todos/3', headers=headers) self.assertEqual(response.status_code, 404)
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_get_todos_with_auth(self): test = ['Walk Dog', 'Clean Car'] TodoModelTestCase.create_todos() user = User.select().get() headers = UserModelTestCase.get_headers(user) response = self.app.get('/api/v1/todos', headers=headers) self.assertEqual(response.status_code, 200) for item in response.get_json(): self.assertIn(item['name'], test)
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_bad_post_todo(self): UserModelTestCase.create_users(1) user = User.select().get() todo_data = { '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, 400) self.assertIn('No task provided', response.get_data(as_text=True))
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')
def test_get_users(self): UserModelTestCase.create_users(1) response = self.app.get('/api/v1/users') self.assertEqual(User.select().get().username, 'user_0')
def create_todos(): UserModelTestCase.create_users(1) user = User.select().get() Todo.create(name='Walk Dog', created_by=user.id) Todo.create(name='Clean Car', created_by=user.id)