Пример #1
0
 def test_c7_user_deletes_all_posts(self):
     data = dict(email='*****@*****.**', password='******')
     self.client.post(api_v1.url_for(Login),
                      data=str(data),
                      content_type='application/json')
     rv = self.client.delete(api_v1.url_for(SingleUserAllPosts, user_id=1))
     self.assertEqual(204, rv.status_code)
Пример #2
0
 def test_a9_logout(self):
     self.login('*****@*****.**', 'password.Pa55word')
     rv = self.client.post(api_v1.url_for(Logout))
     self.assert200(rv)
     self.assertIn(b'logged out successfully', rv.data)
     rv = self.client.post(api_v1.url_for(Logout))
     self.assert400(rv)
     self.assertIn(b'no user in session', rv.data)
Пример #3
0
 def test_c6_user_deletes_single_post(self):
     data = dict(email='*****@*****.**', password='******')
     self.client.post(api_v1.url_for(Login),
                      data=str(data),
                      content_type='application/json')
     self.create_post('My post title Number 2',
                      'Something interesting for people to read.')
     rv = self.client.delete(
         api_v1.url_for(SingleUserSinglePost, user_id=1, post_id=1))
     self.assertEqual(204, rv.status_code)
Пример #4
0
 def test_c5_user_patches_post(self):
     data = dict(email='*****@*****.**', password='******')
     self.client.post(api_v1.url_for(Login),
                      data=str(data),
                      content_type='application/json')
     data = dict(title='My Second Post Title')
     rv = self.client.patch(api_v1.url_for(SingleUserSinglePost,
                                           user_id=1,
                                           post_id=1),
                            data=str(data),
                            content_type='application/json')
     # self.assert200(rv)
     self.assertIn(b'My Second Post Title', rv.data)
Пример #5
0
 def test_c4_user_creates_post(self):
     # user logs in
     data = dict(email='*****@*****.**', password='******')
     self.client.post(api_v1.url_for(Login),
                      data=str(data),
                      content_type='application/json')
     rv = self.create_post('My post title.',
                           'Something interesting for people to read.')
     self.assertEqual(201, rv.status_code)
Пример #6
0
 def register(self,
              email: str = None,
              password_tuple: tuple = (None, None),
              security_tuple: tuple = (None, None)):
     data = dict(email=email)
     data['password'], data['confirm_password'] = password_tuple
     data['security_question'], data['security_answer'] = security_tuple
     return self.client.post(api_v1.url_for(Register),
                             data=str(data),
                             content_type='application/json')
Пример #7
0
 def test_no_data(self):
     rv = self.client.post(api_v1.url_for(Register),
                           content_type='application/json')
     self.assertEqual(400, rv.status_code)
     self.assertIn(b'no data was found in the request', rv.data)
Пример #8
0
 def test_not_json(self):
     rv = self.client.post(api_v1.url_for(Register))
     self.assertEqual(415, rv.status_code)
Пример #9
0
 def test_b2_view_single_post_fail(self):
     rv = self.client.get(api_v1.url_for(SinglePost, post_id=1))
     self.assert400(rv)
     self.assertIn(b'Post not found!', rv.data)
Пример #10
0
 def create_post(self, title, body):
     data = dict(title=title, body=body)
     return self.client.post(api_v1.url_for(SingleUserAllPosts, user_id=1),
                             data=str(data),
                             content_type='application/json')
Пример #11
0
 def test_c3_view_user_posts_empty(self):
     rv = self.client.get(api_v1.url_for(SingleUserAllPosts, user_id=1))
     self.assert200(rv)
     self.assertIn(b'"posts": []', rv.data)
Пример #12
0
 def test_c2_view_single_user(self):
     rv = self.client.get(api_v1.url_for(SingleUser, user_id=1))
     self.assert200(rv)
     self.assertIn(b'{"user":'******'"email":', rv.data)
     self.assertIn(b'"url":', rv.data)
Пример #13
0
 def test_c1_view_all_users(self):
     rv = self.client.get(api_v1.url_for(AllUsers))
     self.assert200(rv)
     self.assertIn(b'{"users": [', rv.data)
Пример #14
0
 def test_d3_view_single_user_fail(self):
     rv = self.client.get(api_v1.url_for(SingleUser, user_id=1))
     self.assert400(rv)
     self.assertIn(b'User not found!', rv.data)
Пример #15
0
 def test_c4_user_views_post(self):
     rv = self.client.get(api_v1.url_for(SingleUserSinglePost,
                                         user_id=1,
                                         post_id=1),
                          follow_redirects=True)
     self.assertIn(b'My post title.', rv.data)
Пример #16
0
 def login(self, email: str = None, password: str = None):
     data = dict(email=email, password=password)
     return self.client.post(api_v1.url_for(Login),
                             data=str(data),
                             content_type='application/json')
Пример #17
0
 def test_b1_view_all_posts(self):
     rv = self.client.get(api_v1.url_for(AllPosts))
     self.assert200(rv)
     self.assertIn(b'[]', rv.data)