예제 #1
0
 def test_json_todo_404(self):
     """this todo doesnt exist 404 for response code"""
     with app.test_client() as client:
         client.post('/login', data=dict(username='******', password='******'))
         description = ''
         response = client.get('/todo/999999/json', data=dict(description=description))
         self.assertEquals(response.status_code, 404)
예제 #2
0
 def test_description_404(self):
     """The response code should be 404 as this endpoint does not exist"""
     with app.test_client() as client:
         client.post('/login', data=dict(username='******', password='******'))
         description = 'test'
         response = client.post('/todo0/', data=dict(description=description))
         self.assertEquals(response.status_code, 404)
예제 #3
0
 def test_valid_description_302(self):
     """OK test for a valid description, the table will be updated"""
     with app.test_client() as client:
         client.post('/login', data=dict(username='******', password='******'))
         description = 'valid string'
         response = client.post('/todo/', data=dict(description=description))
         self.assertEquals(response.status_code, 302)
예제 #4
0
 def test_update_is_completed_someone_else_task_401(self):
     """The response code should be 401: NOK case for the update of user 2 todo tast 6"""
     with app.test_client() as client:
         client.post('/login', data=dict(username='******', password='******'))
         description = 'test'
         response = client.post('/todo/%3Fis_completed%3DFalse%26id%3D6',
                                data=dict(description=description))
         self.assertEquals(response.status_code, 401)
예제 #5
0
 def test_update_is_completed_unknown_task_404(self):
     """The response code should be 404: NOK case for the update for this unknown todo"""
     with app.test_client() as client:
         client.post('/login', data=dict(username='******', password='******'))
         description = 'test'
         response = client.post('/todo/%3Fis_completed%3DFalse%26id%3D1000',
                                data=dict(description=description))
         self.assertEquals(response.status_code, 404)
예제 #6
0
 def test_empty_description(self):
     """Empty string for description will trigger flash message and the
     placeholder presented to user will be changed to notify the latter
     """
     with app.test_client() as client:
         client.post('/login', data=dict(username='******', password='******'))
         description = ''
         response = client.post('/todo/', data=dict(description=description))
         self.assertEquals(response.status_code, 302)
 def test_tododelete_Post(self):
     """
     Test method to test todo_delete post method.
     """
     with app.test_client() as c:
         with c.session_transaction() as sess:
             sess['logged_in'] = True
             sess['user'] = 1
     response = self.app.post('/todo/1', follow_redirects=True)
     self.assertEqual(response._status_code, 200)
예제 #8
0
def client():
    app.config['TESTING'] = True
    app.config['WTF_CSRF_ENABLED'] = False
    app.config['SQL_ALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
    client = app.test_client()

    with app.app_context():
        init_db()

    yield client
 def test_todos_Post(self):
     """
     Test method to test todos post method.
     """
     with app.test_client() as c:
         with c.session_transaction() as sess:
             sess['logged_in'] = True
             sess['user'] = 1
     response = self.app.post('/todo/',
                              data=dict(description="mock data"),
                              follow_redirects=True)
     self.assertEqual(response._status_code, 200)
 def test_todochk_Post(self):
     """
     Test method to test todochk post method.
     """
     with app.test_client() as c:
         with c.session_transaction() as sess:
             sess['logged_in'] = True
             sess['user'] = 1
     response = self.app.post('/todochk',
                              data=dict(isChecked='true'),
                              follow_redirects=True)
     self.assertEqual(response._status_code, 200)
 def setUp(self):
     self.app = app.test_client()
예제 #12
0
def logout():
    """helper function as we need to test if authenticated users can log out"""
    with app.test_client() as client:
        response = client.get('/logout', follow_redirects=True)
    return response
예제 #13
0
def login():
    """helper function as we need to test with authenticated users"""
    with app.test_client() as client:
        response = client.post('/login', follow_redirects=True,
                               data=dict(username='******', password='******'))
    return response