HTTP responses
This commit is contained in:
@@ -30,8 +30,8 @@ def createSignupObject(form, answer):
|
||||
)
|
||||
|
||||
|
||||
def createSignupJSON(form_id, answer):
|
||||
def createSignupRequest(form_id, answer):
|
||||
return {
|
||||
"signupForm_id": form_id,
|
||||
"answer": json.dumps(answer)
|
||||
"answer": answer
|
||||
}
|
||||
|
||||
+15
-15
@@ -7,7 +7,7 @@ from rest_framework.test import APITestCase, force_authenticate
|
||||
from webapp.serializers import SignupSerializer, SignupFormSerializer
|
||||
from webapp.models import Signup
|
||||
from webapp.tests.event_fixture import createEventObject
|
||||
from webapp.tests.signup_fixture import createSignupForm, createSignupObject, createSignupJSON, ALL_QUESTION_TYPES, ALL_QUESTION_TYPES_ANSWER
|
||||
from webapp.tests.signup_fixture import createSignupForm, createSignupObject, createSignupRequest, ALL_QUESTION_TYPES, ALL_QUESTION_TYPES_ANSWER
|
||||
|
||||
|
||||
URL = "/api/signup/"
|
||||
@@ -59,20 +59,20 @@ class SignupTestCase(APITestCase):
|
||||
self.assertEqual(response.data, expected.data)
|
||||
|
||||
def test_create_signup(self):
|
||||
new = createSignupJSON(self.signupForm.id, ALL_QUESTION_TYPES_ANSWER)
|
||||
new = createSignupRequest(self.signupForm.id, ALL_QUESTION_TYPES_ANSWER)
|
||||
response = self.client.post(URL, new, format="json")
|
||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||
self.assertEqual(Signup.objects.count(), 3)
|
||||
|
||||
def test_create_signup_404_or_hidden(self):
|
||||
new = createSignupJSON(3001, ALL_QUESTION_TYPES_ANSWER)
|
||||
new = createSignupRequest(3001, ALL_QUESTION_TYPES_ANSWER)
|
||||
response = self.client.post(URL, new, format="json")
|
||||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
|
||||
self.assertEqual(Signup.objects.count(), 2)
|
||||
|
||||
new = createSignupJSON(self.hiddenForm.id, ALL_QUESTION_TYPES_ANSWER)
|
||||
new = createSignupRequest(self.hiddenForm.id, ALL_QUESTION_TYPES_ANSWER)
|
||||
response = self.client.post(URL, new, format="json")
|
||||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
|
||||
self.assertEqual(Signup.objects.count(), 2)
|
||||
|
||||
@skip("NotImplemented")
|
||||
@@ -81,47 +81,47 @@ class SignupTestCase(APITestCase):
|
||||
|
||||
def test_create_malformed_answer(self):
|
||||
# Empty body
|
||||
response = self.client.post(URL, createSignupJSON(self.signupForm.id, {}), format="json")
|
||||
response = self.client.post(URL, createSignupRequest(self.signupForm.id, {}), format="json")
|
||||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
# Array
|
||||
response = self.client.post(URL, createSignupJSON(self.signupForm.id, []), format="json")
|
||||
response = self.client.post(URL, createSignupRequest(self.signupForm.id, []), format="json")
|
||||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
# Extra ids
|
||||
testInput = ALL_QUESTION_TYPES_ANSWER.copy()
|
||||
testInput["newId"] = "Oon extraa"
|
||||
response = self.client.post(URL, createSignupJSON(self.signupForm.id, testInput), format="json")
|
||||
response = self.client.post(URL, createSignupRequest(self.signupForm.id, testInput), format="json")
|
||||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
# Bad id
|
||||
response = self.client.post(URL, createSignupJSON(self.signupFormText.id, { "malformed": "Tekstiä" }), format="json")
|
||||
response = self.client.post(URL, createSignupRequest(self.signupFormText.id, { "malformed": "Tekstiä" }), format="json")
|
||||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
# Wrong data type for text
|
||||
response = self.client.post(URL, createSignupJSON(self.signupFormText.id, {"j5CeRZDvl": 123}), format="json")
|
||||
response = self.client.post(URL, createSignupRequest(self.signupFormText.id, {"j5CeRZDvl": 123}), format="json")
|
||||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
# Wrong data for checkbox
|
||||
response = self.client.post(URL, createSignupJSON(self.signupFormCheck.id, {
|
||||
response = self.client.post(URL, createSignupRequest(self.signupFormCheck.id, {
|
||||
"i10d426d5": ["D"]
|
||||
}), format="json")
|
||||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
# Wrong data type for checkbox
|
||||
response = self.client.post(URL, createSignupJSON(self.signupFormCheck.id, {
|
||||
response = self.client.post(URL, createSignupRequest(self.signupFormCheck.id, {
|
||||
"i10d426d5": {"j5CeRZDvl": { "asd": "123" }}
|
||||
}), format="json")
|
||||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
# Wrong data for radiobutton
|
||||
response = self.client.post(URL, createSignupJSON(self.signupFormRadio.id, {
|
||||
response = self.client.post(URL, createSignupRequest(self.signupFormRadio.id, {
|
||||
"RHJhSoaLD": []
|
||||
}), format="json")
|
||||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
# Wrong data type for radiobutton
|
||||
response = self.client.post(URL, createSignupJSON(self.signupFormRadio.id, {
|
||||
response = self.client.post(URL, createSignupRequest(self.signupFormRadio.id, {
|
||||
"RHJhSoaLD": { "asd": "123" }
|
||||
}), format="json")
|
||||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
Reference in New Issue
Block a user