-
Notifications
You must be signed in to change notification settings - Fork 14
/
tests.py
73 lines (64 loc) · 2.08 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from django.core.exceptions import ValidationError
from django.contrib.auth import get_user_model
from django.test import TestCase
from ..models import (
Field,
Survey,
FieldChoice,
)
User = get_user_model()
class Tests(TestCase):
def setUp(self):
self.user = User.objects.create_user("foo", password="bar")
def test_likert_field_missing_scale(self):
"""
Ensure Likert field missing choices still produces form field.
"""
survey = Survey(
name="likert test",
creator=self.user,
)
# create Likert field without associated LikertScale
field = Field(
survey=survey,
label="likert field",
field_type=Field.LIKERT_FIELD,
)
self.assertFalse(field.choices.all())
# Ensure no exception when field has no choices
self.assertTrue(field.form_field())
def test_text_field_form_field_render(self):
survey = Survey(
name="field mapping test",
creator=self.user,
)
field = Field(
survey=survey,
label="text field",
field_type=Field.TEXT_FIELD,
)
# Ensure no exception when field is instantiated
self.assertTrue(field.form_field())
def test_multiplechoice_field_choice_limit(self):
"""
Enforce maximum_choices on multiple choice fields that allow
multiple answers.
"""
survey = Survey.objects.create(
name="multiple choice test",
creator=self.user,
)
field = Field.objects.create(
survey=survey,
label="multiple choice field",
field_type=Field.CHECKBOX_FIELD,
maximum_choices=1,
ordinal=0,
)
choice_pks = []
for label in ["a", "b"]:
choice = FieldChoice.objects.create(label=label, field=field)
choice_pks.append(choice.pk)
form_field = field.form_field()
with self.assertRaises(ValidationError):
form_field.clean(choice_pks)