def test_post_short_answer_body(self):
     '''test cant post invalid short answer'''
     response = login_user(self)
     result = json.loads(response.data)
     self.assertIn("access_token", result)
     new_answer = {'body': 'erro'}
     response = self.client.post('/api/v1/questions/2/answers', data=json.dumps(new_answer),
                                 headers={'Authorization': f'Bearer {result["access_token"]}',
                                          'Content-Type': 'application' '/json'})
     self.assertEqual(response.status_code, 400)
 def test_cant_post_to_non(self):
     '''test that an answer can be posted'''
     response = login_user(self)
     result = json.loads(response.data)
     self.assertIn("access_token", result)
     new_answer = {'body': 'errossssssssssssssssssssssssssssssssssssssssssssssssss', 'accept': False}
     response = self.client.post('/api/v1/questions/1258/answers', data=json.dumps(new_answer),
                                 headers={'Authorization': f'Bearer {result["access_token"]}',
                                          'Content-Type': 'application' '/json'})
     self.assertEqual(response.status_code, 404)
Example #3
0
 def test_post_invalid_body(self):
     # test cant post a question with an invalid body
     response = login_user(self)
     result = json.loads(response.data)
     self.assertIn("access_token", result)
     new_question = {'title': 'error sit voluptatem accusantium doloremque laudantium',
                     'body': 'error', 'user_id': 1}
     response = self.client.post('api/v1/questions', data=json.dumps(new_question),
                                 headers={'Authorization': f'Bearer {result["access_token"]}',
                                          'Content-Type': 'application' '/json'})
     self.assertEqual(response.status_code, 400)
Example #4
0
 def setUp(self):
     # setting up configurations for testing
     self.app = app
     self.app.config.from_object(TestingConfig)
     self.new_question = Question(id=4, title="how to init python",
                                  body="how to init python how to init python how to init python", user_id=1,
                                  date_created=datetime.now(), date_modified=datetime.now())
     self.client = self.app.test_client()
     self.app.testing = True
     register_user(self)
     response = login_user(self)
     self.token = json.loads(response.data.decode())['access_token']
 def test_cant_modify_no_answer_t(self):
     '''test that you can't modify non-answer'''
     response = login_user(self)
     result = json.loads(response.data)
     self.assertIn("access_token", result)
     answer = {'body': 'new_answernew_answernew_answernew_answernew_answernew_answernew_answernew'}
     response = self.client.post('/api/v1/questions/1/anwsers', data=json.dumps(answer),
                                 headers={'Authorization': f'Bearer {result["access_token"]}',
                                          'Content-Type': 'application' '/json'})
     new_answer = {'body': 'modified_answermodified_answermodified_answermodified_answermodified_answer'}
     response2 = self.client.put('/api/v1/questions/1/anwsers/4', data=json.dumps(new_answer),
                                 headers={'Authorization': f'Bearer {result["access_token"]}',
                                          'Content-Type': 'application' '/json'})
     self.assertEqual(response.status_code, 404)