@@ -137,8 +137,8 @@ def test_invalid_service_currency_length(self):
137
137
138
138
def test_service_duration_zero (self ):
139
139
"""A service cannot be created with a duration of zero."""
140
- with self . assertRaises ( ValidationError ):
141
- Service . objects . create ( name = "Test Service" , duration = timedelta (), price = 100 )
140
+ service = Service ( name = "Test Service" , duration = timedelta ( 0 ), price = 100 )
141
+ self . assertRaises ( ValidationError , service . full_clean )
142
142
143
143
def test_price_and_down_payment_same (self ):
144
144
"""A service can be created with a price and down payment of the same value."""
@@ -148,30 +148,31 @@ def test_price_and_down_payment_same(self):
148
148
def test_service_with_no_name (self ):
149
149
"""A service cannot be created with no name."""
150
150
with self .assertRaises (ValidationError ):
151
- Service .objects .create (name = "" , duration = timedelta (hours = 1 ), price = 100 )
151
+ Service .objects .create (name = "" , duration = timedelta (hours = 1 ), price = 100 ). full_clean ()
152
152
153
153
def test_service_with_invalid_duration (self ):
154
154
"""Service should not be created with a negative or zero duration."""
155
- with self . assertRaises ( ValidationError ):
156
- Service . objects . create ( name = "Invalid Duration Service" , duration = timedelta ( seconds = - 1 ), price = 50 )
157
- with self . assertRaises ( ValidationError ):
158
- Service . objects . create ( name = "Zero Duration Service" , duration = timedelta ( seconds = 0 ), price = 50 )
155
+ service = Service ( name = "Invalid Duration Service" , duration = timedelta ( seconds = - 1 ), price = 50 )
156
+ self . assertRaises ( ValidationError , service . full_clean )
157
+ service = Service ( name = "Zero Duration Service" , duration = timedelta ( seconds = 0 ), price = 50 )
158
+ self . assertRaises ( ValidationError , service . full_clean )
159
159
160
160
def test_service_with_empty_name (self ):
161
161
"""Service should not be created with an empty name."""
162
- with self . assertRaises ( ValidationError ):
163
- Service . objects . create ( name = "" , duration = timedelta ( hours = 1 ), price = 50 )
162
+ service = Service . objects . create ( name = "" , duration = timedelta ( hours = 1 ), price = 50 )
163
+ self . assertRaises ( ValidationError , service . full_clean )
164
164
165
165
def test_service_with_negative_price (self ):
166
166
"""Service should not be created with a negative price."""
167
- with self . assertRaises ( ValidationError ):
168
- Service . objects . create ( name = "Negative Price Service" , duration = timedelta ( hours = 1 ), price = - 1 )
167
+ service = Service ( name = "Negative Price Service" , duration = timedelta ( hours = 1 ), price = - 1 )
168
+ self . assertRaises ( ValidationError , service . full_clean )
169
169
170
170
def test_service_with_negative_down_payment (self ):
171
171
"""Service should not have a negative down payment."""
172
172
with self .assertRaises (ValidationError ):
173
- Service . objects . create (name = "Service with Negative Down Payment" , duration = timedelta (hours = 1 ), price = 50 ,
173
+ service = Service (name = "Service with Negative Down Payment" , duration = timedelta (hours = 1 ), price = 50 ,
174
174
down_payment = - 1 )
175
+ service .full_clean ()
175
176
176
177
def test_service_auto_generate_background_color (self ):
177
178
"""Service should auto-generate a background color if none is provided."""
0 commit comments