Skip to content

Commit d233d67

Browse files
committed
Correctly handle feet no inches and opposite
1 parent 8fa559f commit d233d67

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-6
lines changed

lung_cancer_screening/nhsuk_forms/imperial_height_form.py renamed to lung_cancer_screening/nhsuk_forms/imperial_height_field.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ def __init__(self, *args, **kwargs):
5151
"min_value": 4,
5252
"max_value": 8,
5353
"error_messages": {
54+
**error_messages,
5455
'invalid': 'Feet must be in whole numbers',
5556
'min_value': between_feet,
5657
'max_value': between_feet,
57-
**error_messages,
58+
'incomplete': between_feet,
5859
},
5960
}
6061

@@ -64,12 +65,14 @@ def __init__(self, *args, **kwargs):
6465
"min_value": 0,
6566
"max_value": 11,
6667
"error_messages": {
68+
**error_messages,
6769
'invalid': 'Inches must be in whole numbers',
6870
'min_value': between_inches,
6971
'max_value': between_inches,
70-
**error_messages,
72+
'incomplete': between_inches,
7173
},
7274
}
75+
7376
fields = (
7477
IntegerField(**feet_kwargs),
7578
IntegerField(**inches_kwargs),

lung_cancer_screening/questions/forms/imperial_height_form.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from django import forms
22

3-
from ...nhsuk_forms.imperial_height_form import ImperialHeightField
3+
from ...nhsuk_forms.imperial_height_field import ImperialHeightField
44
from ..models.response_set import ResponseSet
55

66
class ImperialHeightForm(forms.ModelForm):
@@ -16,7 +16,6 @@ def __init__(self, *args, **kwargs):
1616
require_all_fields=False,
1717
error_messages={
1818
'required': 'Enter your height',
19-
'incomplete': 'Enter your height'
2019
}
2120
)
2221

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

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def test_is_invalid_with_missing_data(self):
5353
participant=self.participant,
5454
instance=self.response_set,
5555
data={
56-
"height_imperial_0": "5",
56+
# missing feet
5757
# missing inches
5858
}
5959
)
@@ -63,6 +63,36 @@ def test_is_invalid_with_missing_data(self):
6363
["Enter your height"]
6464
)
6565

66+
def test_is_invalid_with_missing_inches(self):
67+
form = ImperialHeightForm(
68+
participant=self.participant,
69+
instance=self.response_set,
70+
data={
71+
"height_imperial_0": "5",
72+
# missing inches
73+
}
74+
)
75+
self.assertFalse(form.is_valid())
76+
self.assertEqual(
77+
form.errors["height_imperial"],
78+
["Inches must be between 0 and 11"]
79+
)
80+
81+
def test_is_invalid_with_missing_feet(self):
82+
form = ImperialHeightForm(
83+
participant=self.participant,
84+
instance=self.response_set,
85+
data={
86+
#"height_imperial_0": "5",
87+
"height_imperial_1": "5"
88+
}
89+
)
90+
self.assertFalse(form.is_valid())
91+
self.assertEqual(
92+
form.errors["height_imperial"],
93+
["Feet must be between 4 and 8"]
94+
)
95+
6696
def test_is_invalid_when_given_a_decimal_feet_value(self):
6797
form = ImperialHeightForm(
6898
participant=self.participant,

tests/features/questionnaire.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Feature: Questionnaire
1212
And I see a back link to "/date-of-birth"
1313
When I fill in and submit my height with "170"
1414
And I click "Back"
15-
And I click "Switch to imperial"
15+
And I click "Switch to feet and inches"
1616
When I fill in and submit my height with "5" feet and "7" inches
1717
Then I am on "/weight"
1818
And I see a back link to "/height"

0 commit comments

Comments
 (0)