Update tests
This commit is contained in:
@@ -2,24 +2,51 @@ from webapp.models import Signup, SignupForm
|
||||
from django.utils import timezone
|
||||
from webapp.utils import month_from_now
|
||||
|
||||
import json
|
||||
ALL_QUESTION_TYPES = [{"id": "-naY2R1-h", "name": "Nimi", "type": "text", "options": []}, {"id": "5t1oN2Qev", "name": "Testi", "type": "info", "options": "teskstii"}, {"id": "MYaaAiOiU", "name": "Email", "type": "email", "options": []}, {"id": "Wb5tmyvki", "name": "Radio", "type": "radiobutton", "options": ["Yes", "no", "maybe"]}, {"id": "U41Zp9x0L", "name": "Checkbox", "type": "checkbox", "options": ["A", "B", "C"]}, {"id": "TnDqrvXKf", "name": "Numero", "type": "integer", "options": ["1", "100"]}]
|
||||
|
||||
ALL_QUESTION_TYPES = [
|
||||
{"id": "j5CeRZDvl", "name": "Asd", "type": "text", "options": []},
|
||||
{"id": "RHJhSoaLD", "name": "Asd2", "type": "radiobutton", "options": ["Yes", "no", "maybe"]},
|
||||
{"id": "i10d426d5", "name": "Asd3", "type": "checkbox", "options": ["A", "B", "C"]}
|
||||
]
|
||||
|
||||
ALL_QUESTION_TYPES_ANSWER = {"j5CeRZDvl": "Testi", "RHJhSoaLD": "maybe", "i10d426d5": ["B", "C"]}
|
||||
ALL_QUESTION_TYPES_ANSWER = {"-naY2R1-h": "Testi", "MYaaAiOiU": "test-spam@sahkoinsinoorikilta.fi", "Wb5tmyvki": "maybe", "U41Zp9x0L": ["B", "C"], "TnDqrvXKf": 5}
|
||||
|
||||
|
||||
def createSignupForm(name="Form1", start_time=timezone.now(), end_time=month_from_now(), questions=ALL_QUESTION_TYPES, visible=True):
|
||||
ALL_QUESTIONS_SCHEMA = {
|
||||
"type": "object",
|
||||
"required": ["-naY2R1-h", "MYaaAiOiU", "Wb5tmyvki", "U41Zp9x0L", "TnDqrvXKf"],
|
||||
"properties": {"-naY2R1-h": {"type": "string"}, "MYaaAiOiU": {"type": "string", "format": "email", "pattern": "^[a-zA-Z0-9.!#$%&\u2019*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$"}, "TnDqrvXKf": {"type": "number", "title": "Numero (1 -- 100)", "maximum": 100, "minimum": 1, "multipleOf": 1}, "U41Zp9x0L": {"type": "array", "items": {"type": "string", "pattern": "^A$|^B$|^C$"}, "maxItems": 3, "uniqueItems": True}, "Wb5tmyvki": {"type": "string", "pattern": "^Yes$|^no$|^maybe$"}},
|
||||
"minProperties": 5
|
||||
}
|
||||
|
||||
TEXT_SCHEMA = {
|
||||
"type": "object",
|
||||
"required": ["-naY2R1-h"],
|
||||
"properties": {
|
||||
"-naY2R1-h": ALL_QUESTIONS_SCHEMA["properties"]["-naY2R1-h"]
|
||||
},
|
||||
"minProperties": 1
|
||||
}
|
||||
RADIO_SCHEMA = {
|
||||
"type": "object",
|
||||
"required": ["Wb5tmyvki"],
|
||||
"properties": {
|
||||
"Wb5tmyvki": ALL_QUESTIONS_SCHEMA["properties"]["Wb5tmyvki"]
|
||||
},
|
||||
"minProperties": 1
|
||||
}
|
||||
CBOX_SCHEMA = {
|
||||
"type": "object",
|
||||
"required": ["U41Zp9x0L"],
|
||||
"properties": {
|
||||
"U41Zp9x0L": ALL_QUESTIONS_SCHEMA["properties"]["U41Zp9x0L"]
|
||||
},
|
||||
"minProperties": 1
|
||||
}
|
||||
|
||||
def createSignupForm(name="Form1", start_time=timezone.now(), end_time=month_from_now(), questions=ALL_QUESTION_TYPES, schema=ALL_QUESTIONS_SCHEMA, visible=True):
|
||||
return SignupForm.objects.create(
|
||||
title=name,
|
||||
start_time=start_time,
|
||||
end_time=end_time,
|
||||
questions=questions,
|
||||
visible=visible
|
||||
visible=visible,
|
||||
schema=schema
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
from django.contrib.auth.models import User
|
||||
from unittest import skip
|
||||
from rest_framework import status
|
||||
from rest_framework.test import APITestCase
|
||||
from webapp.models import Signup
|
||||
from webapp.tests.signup_fixture import createSignupForm, createSignupObject, createSignupRequest, ALL_QUESTION_TYPES, ALL_QUESTION_TYPES_ANSWER
|
||||
from webapp.tests.signup_fixture import createSignupForm, createSignupObject, createSignupRequest, ALL_QUESTION_TYPES, ALL_QUESTION_TYPES_ANSWER, TEXT_SCHEMA, RADIO_SCHEMA, CBOX_SCHEMA
|
||||
|
||||
URL = "/api/signup/"
|
||||
|
||||
@@ -10,9 +11,9 @@ URL = "/api/signup/"
|
||||
class SignupErrorTestCase(APITestCase):
|
||||
def setUp(self):
|
||||
self.signupForm = createSignupForm()
|
||||
self.signupFormText = createSignupForm(name="Form2", questions=[ALL_QUESTION_TYPES[0]])
|
||||
self.signupFormRadio = createSignupForm(name="Form3", questions=[ALL_QUESTION_TYPES[1]])
|
||||
self.signupFormCheck = createSignupForm(name="Form4", questions=[ALL_QUESTION_TYPES[2]])
|
||||
self.signupFormText = createSignupForm(name="Form2", questions=[ALL_QUESTION_TYPES[0]], schema=TEXT_SCHEMA)
|
||||
self.signupFormRadio = createSignupForm(name="Form3", questions=[ALL_QUESTION_TYPES[1]], schema=RADIO_SCHEMA)
|
||||
self.signupFormCheck = createSignupForm(name="Form4", questions=[ALL_QUESTION_TYPES[2]], schema=CBOX_SCHEMA)
|
||||
self.hiddenForm = createSignupForm(visible=False)
|
||||
|
||||
self.signup1 = createSignupObject("1", self.signupForm, ALL_QUESTION_TYPES)
|
||||
@@ -50,6 +51,7 @@ class SignupErrorTestCase(APITestCase):
|
||||
response = self.client.post(URL, createSignupRequest("", self.signupForm.id, []), format="json")
|
||||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
@skip("We allow extra signup body because of info fields")
|
||||
def test_create_extra_body(self):
|
||||
testInput = ALL_QUESTION_TYPES_ANSWER.copy()
|
||||
testInput["newId"] = "Oon extraa"
|
||||
|
||||
Reference in New Issue
Block a user