From a9d1f2f80d38435c9dab791b51a05c51ff4d73d2 Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 14 Apr 2025 23:04:30 +0300 Subject: [PATCH] test(business): Add more validation tests for the detail endpoint. --- .../validations/test_detail_validation.py | 81 +++++++++++++------ 1 file changed, 57 insertions(+), 24 deletions(-) diff --git a/promo_code/business/tests/promocodes/validations/test_detail_validation.py b/promo_code/business/tests/promocodes/validations/test_detail_validation.py index 94e4485..451dd24 100644 --- a/promo_code/business/tests/promocodes/validations/test_detail_validation.py +++ b/promo_code/business/tests/promocodes/validations/test_detail_validation.py @@ -129,17 +129,16 @@ def test_edit_invalid_short_description(self): [ ( 'non_string', - {'description': 'Bonus 10000%!', 'image_url': False}, + {'image_url': False}, ), ( 'incomplete_url', - {'description': 'Bonus 10000%!', 'image_url': 'https://'}, + {'image_url': 'https://'}, ), ( 'malformed_url', - {'description': 'Bonus 10000%!', 'image_url': 'notalink'}, + {'image_url': 'notalink'}, ), - ('incorrect_type', {'image_url': 'jpeg'}), ], ) def test_edit_invalid_image_urls(self, _, patch_payload): @@ -188,29 +187,63 @@ def test_edit_invalid_target(self, _, patch_payload): rest_framework.status.HTTP_400_BAD_REQUEST, ) - def test_edit_invalid_max_count_for_unique(self): - promo_id = self.create_promo(self.company2_token, self.unique_payload) - self.client.credentials( - HTTP_AUTHORIZATION='Bearer ' + self.company2_token, - ) - url = self.promo_detail_url(promo_id) - patch_payload = { - 'max_count': 10, - } - response = self.client.patch(url, patch_payload, format='json') - self.assertEqual( - response.status_code, - rest_framework.status.HTTP_400_BAD_REQUEST, - ) + @parameterized.parameterized.expand( + [ + ( + 'unique_max_count', + 'company2_token', + 'unique_payload', + {'max_count': 10}, + ), + ( + 'negative_max_count', + 'company1_token', + 'common_payload', + {'max_count': -10}, + ), + ( + 'non_integer_max_count', + 'company1_token', + 'common_payload', + {'max_count': 'invalid'}, + ), + ( + 'zero_max_count', + 'company2_token', + 'unique_payload', + {'max_count': 0}, + ), + ( + 'max_count_is_none', + 'company1_token', + 'common_payload', + {'max_count': None}, + ), + ( + 'exceeding_max_count', + 'company1_token', + 'common_payload', + {'max_count': 100_000_001}, + ), + ], + ) + def test_edit_invalid_max_count( + self, + _, + token_attr, + payload_attr, + patch_payload, + ): + token = getattr(self, token_attr) + create_payload = getattr(self, payload_attr) - def test_edit_negative_max_count(self): - promo_id = self.create_promo(self.company1_token, self.common_payload) - self.client.credentials( - HTTP_AUTHORIZATION='Bearer ' + self.company1_token, - ) + promo_id = self.create_promo(token, create_payload) + + self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + token) url = self.promo_detail_url(promo_id) - patch_payload = {'max_count': -10} + response = self.client.patch(url, patch_payload, format='json') + self.assertEqual( response.status_code, rest_framework.status.HTTP_400_BAD_REQUEST,