示例#1
0
 def test_missing_field(self):
     data = json.dumps({
         "title": "Why is water wet?",
         "user_name": "Harald",
         "user_email": "*****@*****.**",
     })
     request = self.factory.put('/api/v1/questions/', data=data)
     response = views.questions(request)
     self.assertEqual(response.status_code, 400)
示例#2
0
 def test_submit_question_successfully(self):
     data = json.dumps({
         "title": "Why is water wet?",
         "content": "Eerer erwerwe ewrewre",
         "user_name": "Harald",
         "user_email": "*****@*****.**",
     })
     request = self.factory.put('/api/v1/questions/', data=data)
     response = views.questions(request)
     self.assertEqual(response.status_code, 201)
示例#3
0
 def test_update_question(self):
     data = json.dumps({
         "title": "Why is water wet?",
         "content": "Some new content",
         "user_name": "Harald",
         "user_email": "*****@*****.**",
     })
     request = self.factory.put('/api/v1/questions/1/', data=data)
     response = views.questions(request, 1)
     self.assertEqual(response.status_code, 200)
     self.test_get_one_question("Some new content")
示例#4
0
 def test_unsupported_request_type(self):
     request = self.factory.delete('/api/v1/questions/')
     response = views.questions(request)
     self.assertEqual(response.status_code, 405)
示例#5
0
 def test_incorrect_json(self):
     request = self.factory.put('/api/v1/questions/')
     request.data = {'sdfsd'}
     response = views.questions(request)
     self.assertEqual(response.status_code, 400)
示例#6
0
 def test_get_non_existing_question(self):
     request = self.factory.get('/api/v1/questions/4000/')
     response = views.questions(request, 4000)
     self.assertEqual(response.status_code, 404)
示例#7
0
 def test_get_one_question(self, content_value="Some content"):
     request = self.factory.get('/api/v1/questions/1/')
     response = views.questions(request, 1)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(
         json.loads(response.content)['content'], content_value)
示例#8
0
 def test_get_all_questions(self):
     request = self.factory.get('/api/v1/questions/')
     response = views.questions(request)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(len(json.loads(response.content)), 2)