@@ -139,6 +139,14 @@ def test_edit_invalid_short_description(self):
139139 'malformed_url' ,
140140 {'image_url' : 'notalink' },
141141 ),
142+ (
143+ 'empty_url' ,
144+ {'image_url' : '' },
145+ ),
146+ (
147+ 'invalid_url_with_spaces' ,
148+ {'image_url' : 'https://example.com/image with spaces.jpg' },
149+ ),
142150 ],
143151 )
144152 def test_edit_invalid_image_urls (self , _ , patch_payload ):
@@ -158,21 +166,43 @@ def test_edit_invalid_image_urls(self, _, patch_payload):
158166 (
159167 'age_range_invalid' ,
160168 {
161- 'description' : 'Bonus 10000%!' ,
162169 'target' : {'age_from' : 19 , 'age_until' : 17 },
163170 },
164171 ),
172+ ('age_from_too_high' , {'target' : {'age_from' : 200 }}),
173+ ('age_until_too_high' , {'target' : {'age_until' : 200 }}),
174+ ('age_from_too_low' , {'target' : {'age_from' : - 1 }}),
175+ ('age_until_too_low' , {'target' : {'age_until' : - 1 }}),
176+ (
177+ 'invalid_target_country_format' ,
178+ {'target' : {'country' : 'USA' }},
179+ ),
165180 (
166- 'incomplete_target' ,
167- {'description' : 'Bonus 10000%!' , 'target' : {'country' : 'USA' }},
181+ 'invalid_target_country_too_short' ,
182+ {'target' : {'country' : 'U' }},
183+ ),
184+ (
185+ 'invalid_target_country_does_not_exist' ,
186+ {'target' : {'country' : 'XX' }},
168187 ),
169188 (
170189 'empty_category' ,
171190 {
172- 'description' : 'Bonus 10000%!' ,
173191 'target' : {'categories' : ['' ]},
174192 },
175193 ),
194+ (
195+ 'non_string_category' ,
196+ {
197+ 'target' : {'categories' : [1 , 2 , 3 ]},
198+ },
199+ ),
200+ (
201+ 'non_dict_target' ,
202+ {
203+ 'target' : ['not' , 'a' , 'dict' ],
204+ },
205+ ),
176206 ],
177207 )
178208 def test_edit_invalid_target (self , _ , patch_payload ):
@@ -225,6 +255,36 @@ def test_edit_invalid_target(self, _, patch_payload):
225255 'common_payload' ,
226256 {'max_count' : 100_000_001 },
227257 ),
258+ (
259+ 'non_integer_max_count_float' ,
260+ 'company1_token' ,
261+ 'common_payload' ,
262+ {'max_count' : 10.5 },
263+ ),
264+ (
265+ 'max_count_is_empty_string' ,
266+ 'company1_token' ,
267+ 'common_payload' ,
268+ {'max_count' : '' },
269+ ),
270+ (
271+ 'max_count_is_list' ,
272+ 'company1_token' ,
273+ 'common_payload' ,
274+ {'max_count' : [1 , 2 , 3 ]},
275+ ),
276+ (
277+ 'max_count_is_dict' ,
278+ 'company1_token' ,
279+ 'common_payload' ,
280+ {'max_count' : {'key' : 'value' }},
281+ ),
282+ (
283+ 'max_count_is_boolean' ,
284+ 'company1_token' ,
285+ 'common_payload' ,
286+ {'max_count' : True },
287+ ),
228288 ],
229289 )
230290 def test_edit_invalid_max_count (
@@ -268,6 +328,18 @@ def test_get_promo_verify_fields_unchanged(self):
268328 HTTP_AUTHORIZATION = 'Bearer ' + self .company2_token ,
269329 )
270330 url = self .promo_detail_url (promo_id )
331+ patch_payload = {
332+ 'active_from' : '2024-12-28 12:00:00' ,
333+ 'max_count' : 100 ,
334+ 'description' : 'short' ,
335+ 'target' : {'age_from' : 26 , 'country' : 'fr' },
336+ }
337+ response = self .client .patch (url , patch_payload , format = 'json' )
338+ self .assertEqual (
339+ response .status_code ,
340+ rest_framework .status .HTTP_400_BAD_REQUEST ,
341+ )
342+
271343 response = self .client .get (url , format = 'json' )
272344 self .assertEqual (
273345 response .status_code ,
0 commit comments