From c9d4716d192fafc4cf43ec182affc27adf02beab Mon Sep 17 00:00:00 2001 From: Kegan Maher Date: Wed, 1 May 2024 19:28:25 +0000 Subject: [PATCH] fix(models): renenrollment error template required if expiration supported --- benefits/core/models.py | 3 +++ tests/pytest/core/test_models.py | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/benefits/core/models.py b/benefits/core/models.py index ed5f6122e..959c94451 100644 --- a/benefits/core/models.py +++ b/benefits/core/models.py @@ -142,6 +142,7 @@ def clean(self): supports_expiration = self.supports_expiration expiration_days = self.expiration_days expiration_reenrollment_days = self.expiration_reenrollment_days + reenrollment_error_template = self.reenrollment_error_template if supports_expiration: errors = {} @@ -150,6 +151,8 @@ def clean(self): errors.update(expiration_days=ValidationError(message)) if expiration_reenrollment_days is None or expiration_reenrollment_days <= 0: errors.update(expiration_reenrollment_days=ValidationError(message)) + if reenrollment_error_template is None: + errors.update(reenrollment_error_template=ValidationError("Required when supports expiration is True.")) if errors: raise ValidationError(errors) diff --git a/tests/pytest/core/test_models.py b/tests/pytest/core/test_models.py index 798dfeb8b..1cb359fc4 100644 --- a/tests/pytest/core/test_models.py +++ b/tests/pytest/core/test_models.py @@ -210,6 +210,19 @@ def test_EligibilityType_zero_expiration_reenrollment_days(model_EligibilityType ) +@pytest.mark.django_db +def test_EligibilityType_missing_reenrollment_template(model_EligibilityType_supports_expiration): + model_EligibilityType_supports_expiration.reenrollment_error_template = None + model_EligibilityType_supports_expiration.save() + + with pytest.raises(ValidationError) as exception_info: + model_EligibilityType_supports_expiration.full_clean() + + error_dict = exception_info.value.error_dict + assert len(error_dict["reenrollment_error_template"]) == 1 + assert error_dict["reenrollment_error_template"][0].message == "Required when supports expiration is True." + + @pytest.mark.django_db def test_EligibilityType_supports_expiration(model_EligibilityType_supports_expiration): # test will fail if any error is raised