Пример #1
0
 def test_missing_field(self):
     data = json.dumps({
         "user_name": "Harald",
         "user_email": "*****@*****.**",
     })
     request = self.factory.put('/api/v1/questions/1/answers/', data=data)
     response = views.answers(request, 1)
     self.assertEqual(response.status_code, 400)
Пример #2
0
 def test_submit_answer_successfully(self):
     data = json.dumps({
         "content": "Lorem ipsum dolor sit amet",
         "user_name": "Harald",
         "user_email": "*****@*****.**",
     })
     request = self.factory.put('/api/v1/questions/1/answers/', data=data)
     response = views.answers(request, 1)
     self.assertEqual(response.status_code, 201)
Пример #3
0
 def test_non_string_data(self):
     data = json.dumps({
         "content": ["Lorem ipsum dolor sit amet"],
         "user_name": "Harald",
         "user_email": "*****@*****.**",
     })
     request = self.factory.put('/api/v1/questions/1/answers/', data=data)
     response = views.answers(request, 1)
     self.assertEqual(response.status_code, 400)
Пример #4
0
 def test_update_answer(self):
     data = json.dumps({
         "content": "Some new content",
         "user_name": "Harald",
         "user_email": "*****@*****.**",
     })
     request = self.factory.put('/api/v1/questions/1/answers/2/', data=data)
     response = views.answers(request, 1, 2)
     self.assertEqual(response.status_code, 200)
     self.test_get_one_answer("Harald")
Пример #5
0
 def test_unsupported_request_type(self):
     request = self.factory.delete('/api/v1/questions/1/answers/')
     response = views.answers(request, 1)
     self.assertEqual(response.status_code, 405)
Пример #6
0
 def test_incorrect_json(self):
     request = self.factory.put('/api/v1/questions/1/answers/')
     request.data = {'sdfsd'}
     response = views.answers(request, 1)
     self.assertEqual(response.status_code, 400)
Пример #7
0
 def test_get_non_existing_answer(self):
     request = self.factory.get('/api/v1/questions/1/answers/8000/')
     response = views.answers(request, 1, 8000)
     self.assertEqual(response.status_code, 404)
Пример #8
0
 def test_get_empty_answers_for_question(self):
     request = self.factory.get('/api/v1/questions/2/answers/')
     response = views.answers(request, 2)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(json.loads(response.content), [])
Пример #9
0
 def test_get_one_answer(self, user_value="Harry"):
     request = self.factory.get('/api/v1/questions/1/answers/2/')
     response = views.answers(request, 1, 2)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(json.loads(response.content)['user_name'], user_value)
Пример #10
0
 def test_get_all_answers_for_question(self):
     request = self.factory.get('/api/v1/questions/1/answers/')
     response = views.answers(request, 1)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(len(json.loads(response.content)), 2)