finish template question API

This commit is contained in:
Aarni Halinen
2021-08-24 02:50:46 +03:00
parent 9d05cd8290
commit b8342ba66a
6 changed files with 59 additions and 13 deletions
+8 -7
View File
@@ -14,11 +14,11 @@ class TemplateQuestionCase(APITestCase):
self.questions = [
TemplateQuestion.objects.create(
name="Testi1",
question=ALL_QUESTION_TYPES
questions=ALL_QUESTION_TYPES
),
TemplateQuestion.objects.create(
name="Testi2",
question=ALL_QUESTION_TYPES
questions=ALL_QUESTION_TYPES
)
]
@@ -36,7 +36,7 @@ class TemplateQuestionCase(APITestCase):
def test_post(self):
new = {
"name": "testi3",
"question": json.dumps(ALL_QUESTION_TYPES)
"questions": json.dumps(ALL_QUESTION_TYPES)
}
response = self.client.post("/api/questions/", new, format="json")
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
@@ -51,7 +51,7 @@ class TemplateQuestionCase(APITestCase):
def test_update(self):
new = {
"name": "uusi testi2",
"question": json.dumps({})
"questions": json.dumps({})
}
response = self.client.put(f"/api/questions/{self.questions[0].id}/", new, format="json")
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
@@ -69,12 +69,13 @@ class TemplateQuestionCase(APITestCase):
)
def test_delete(self):
response = self.client.delete(f"/api/questions/{self.questions[0].id}/", format="json")
id = self.questions[0].id
response = self.client.delete(f"/api/questions/{id}/", format="json")
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(TemplateQuestion.objects.count(), 2)
# Authenticate
self.client.force_authenticate(user=self.authClient)
response = self.client.delete(f"/api/questions/{self.questions[0].id}/", format="json")
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
self.assertEqual(TemplateQuestion.objects.count(), 1)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(TemplateQuestion.objects.get(id=id).deleted, True)