Skip to content

Commit a9e557e

Browse files
jamiefalcusThemitchell
authored andcommitted
Feet and inches between expected values
1 parent 4b7e076 commit a9e557e

File tree

3 files changed

+73
-1
lines changed

3 files changed

+73
-1
lines changed

lung_cancer_screening/nhsuk_forms/imperial_height_form.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,28 @@ class ImperialHeightField(forms.MultiValueField):
4545
def __init__(self, *args, **kwargs):
4646
error_messages = kwargs.get("error_messages", {})
4747

48+
between_feet="Feet must be between 4 and 8"
49+
4850
feet_kwargs = {
51+
"min_value": 4,
52+
"max_value": 8,
4953
"error_messages": {
5054
'invalid': 'Feet must be in whole numbers',
55+
'min_value': between_feet,
56+
'max_value': between_feet,
5157
**error_messages,
5258
},
5359
}
60+
61+
between_inches = "Inches must be between 0 and 11"
62+
5463
inches_kwargs = {
64+
"min_value": 0,
65+
"max_value": 11,
5566
"error_messages": {
5667
'invalid': 'Inches must be in whole numbers',
68+
'min_value': between_inches,
69+
'max_value': between_inches,
5770
**error_messages,
5871
},
5972
}

lung_cancer_screening/nhsuk_forms/tests/unit/test_decimal_field.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class TestForm(Form):
2121
def test_renders_nhs_input_with_suffix(self):
2222
class TestForm(Form):
2323
field = DecimalField(label="Abc", initial=1, max_value=10, suffix="cm")
24-
print(TestForm()["field"].as_field_group())
2524
self.assertHTMLEqual(
2625
TestForm()["field"].as_field_group(),
2726
"""

lung_cancer_screening/questions/tests/unit/forms/test_imperial_height_form.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,63 @@ def test_is_invalid_when_given_a_decimal_feet_value(self):
7777
form.errors["height_imperial"],
7878
["Feet must be in whole numbers"]
7979
)
80+
81+
def test_is_invalid_when_inches_under_11(self):
82+
form = ImperialHeightForm(
83+
participant=self.participant,
84+
instance=self.response_set,
85+
data={
86+
"height_imperial_0": "5",
87+
"height_imperial_1": "12"
88+
}
89+
)
90+
self.assertFalse(form.is_valid())
91+
self.assertEqual(
92+
form.errors["height_imperial"],
93+
["Inches must be between 0 and 11"]
94+
)
95+
96+
def test_is_invalid_when_inches_over_0(self):
97+
form = ImperialHeightForm(
98+
participant=self.participant,
99+
instance=self.response_set,
100+
data={
101+
"height_imperial_0": "5",
102+
"height_imperial_1": "-1"
103+
}
104+
)
105+
self.assertFalse(form.is_valid())
106+
self.assertEqual(
107+
form.errors["height_imperial"],
108+
["Inches must be between 0 and 11"]
109+
)
110+
111+
def test_is_invalid_when_feet_over_4(self):
112+
form = ImperialHeightForm(
113+
participant=self.participant,
114+
instance=self.response_set,
115+
data={
116+
"height_imperial_0": "3",
117+
"height_imperial_1": "10"
118+
}
119+
)
120+
self.assertFalse(form.is_valid())
121+
self.assertEqual(
122+
form.errors["height_imperial"],
123+
["Feet must be between 4 and 8"]
124+
)
125+
126+
def test_is_invalid_when_feet_under_8(self):
127+
form = ImperialHeightForm(
128+
participant=self.participant,
129+
instance=self.response_set,
130+
data={
131+
"height_imperial_0": "9",
132+
"height_imperial_1": "0"
133+
}
134+
)
135+
self.assertFalse(form.is_valid())
136+
self.assertEqual(
137+
form.errors["height_imperial"],
138+
["Feet must be between 4 and 8"]
139+
)

0 commit comments

Comments
 (0)