Skip to content

Commit

Permalink
fix(models): renenrollment error template required if expiration supp…
Browse files Browse the repository at this point in the history
…orted
  • Loading branch information
thekaveman committed May 1, 2024
1 parent 1bbc20c commit c9d4716
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions benefits/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand All @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions tests/pytest/core/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c9d4716

Please sign in to comment.