@@ -47,21 +47,19 @@ def test_setting_weight_imperial_clears_weight_metric(self):
4747 form .save ()
4848 self .assertEqual (self .response_set .weight_metric , None )
4949
50- def test_is_invalid_with_missing_data (self ):
50+ def test_is_invalid_with_no_values_set (self ):
5151 form = ImperialWeightForm (
5252 participant = self .participant ,
5353 instance = self .response_set ,
54- data = {
55- "weight_imperial_0" : "5" ,
56- # missing pounds
57- }
54+ data = {}
5855 )
5956 self .assertFalse (form .is_valid ())
6057 self .assertEqual (
6158 form .errors ["weight_imperial" ],
6259 ["Enter your weight" ]
6360 )
6461
62+
6563 def test_is_invalid_when_given_a_decimal_stone_value (self ):
6664 form = ImperialWeightForm (
6765 participant = self .participant ,
@@ -76,3 +74,93 @@ def test_is_invalid_when_given_a_decimal_stone_value(self):
7674 form .errors ["weight_imperial" ],
7775 ["Stone must be in whole numbers" ]
7876 )
77+
78+ def test_is_invalid_with_missing_pounds (self ):
79+ form = ImperialWeightForm (
80+ participant = self .participant ,
81+ instance = self .response_set ,
82+ data = {
83+ "weight_imperial_0" : "5" ,
84+ # missing pounds
85+ }
86+ )
87+ self .assertFalse (form .is_valid ())
88+ self .assertEqual (
89+ form .errors ["weight_imperial" ],
90+ ["Pounds must be between 0 and 13" ]
91+ )
92+
93+ def test_is_invalid_with_missing_stone (self ):
94+ form = ImperialWeightForm (
95+ participant = self .participant ,
96+ instance = self .response_set ,
97+ data = {
98+ # missing stone
99+ "weight_imperial_1" : "5"
100+ }
101+ )
102+ self .assertFalse (form .is_valid ())
103+ self .assertEqual (
104+ form .errors ["weight_imperial" ],
105+ ["Stone must be between 4 and 50" ]
106+ )
107+
108+ def test_is_invalid_when_pounds_under_0 (self ):
109+ form = ImperialWeightForm (
110+ participant = self .participant ,
111+ instance = self .response_set ,
112+ data = {
113+ "weight_imperial_0" : "5" ,
114+ "weight_imperial_1" : "-1"
115+ }
116+ )
117+ self .assertFalse (form .is_valid ())
118+ self .assertEqual (
119+ form .errors ["weight_imperial" ],
120+ ["Pounds must be between 0 and 13" ]
121+ )
122+
123+ def test_is_invalid_when_pounds_over_13 (self ):
124+ form = ImperialWeightForm (
125+ participant = self .participant ,
126+ instance = self .response_set ,
127+ data = {
128+ "weight_imperial_0" : "5" ,
129+ "weight_imperial_1" : "14"
130+ }
131+ )
132+ self .assertFalse (form .is_valid ())
133+ self .assertEqual (
134+ form .errors ["weight_imperial" ],
135+ ["Pounds must be between 0 and 13" ]
136+ )
137+
138+ def test_is_invalid_when_stone_under_4 (self ):
139+ form = ImperialWeightForm (
140+ participant = self .participant ,
141+ instance = self .response_set ,
142+ data = {
143+ "weight_imperial_0" : "3" ,
144+ "weight_imperial_1" : "10"
145+ }
146+ )
147+ self .assertFalse (form .is_valid ())
148+ self .assertEqual (
149+ form .errors ["weight_imperial" ],
150+ ["Weight must be between 4 stone and 50 stone" ]
151+ )
152+
153+ def test_is_invalid_when_stone_over_50 (self ):
154+ form = ImperialWeightForm (
155+ participant = self .participant ,
156+ instance = self .response_set ,
157+ data = {
158+ "weight_imperial_0" : "51" ,
159+ "weight_imperial_1" : "0"
160+ }
161+ )
162+ self .assertFalse (form .is_valid ())
163+ self .assertEqual (
164+ form .errors ["weight_imperial" ],
165+ ["Weight must be between 4 stone and 50 stone" ]
166+ )
0 commit comments