Esempio n. 1
0
 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'
     )
Esempio n. 2
0
 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) 
Esempio n. 3
0
 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')
Esempio n. 4
0
 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)
Esempio n. 5
0
    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')    
Esempio n. 6
0
    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))
Esempio n. 7
0
 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') 
Esempio n. 8
0
 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') 
Esempio n. 9
0
 def test_get_users(self):
     UserModelTestCase.create_users(1)
     response = self.app.get('/api/v1/users')
     self.assertEqual(User.select().get().username, 'user_0')  
Esempio n. 10
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)