From 20ce4c2363e47275bbebd557b7ccb76dd3d53b13 Mon Sep 17 00:00:00 2001 From: Kegan Maher Date: Fri, 3 May 2024 15:03:56 +0000 Subject: [PATCH 1/2] fix(models): allow SecretNameField to be blank since it is not a required field on many models overriding blank=False made it so a model could not be saved in the Admin without providing a value --- benefits/core/models.py | 2 -- tests/pytest/core/test_models.py | 7 +++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/benefits/core/models.py b/benefits/core/models.py index 959c94451..d04ff9a12 100644 --- a/benefits/core/models.py +++ b/benefits/core/models.py @@ -37,8 +37,6 @@ def __init__(self, *args, **kwargs): # although the validator also checks for a max length of 127 # this setting enforces the length at the database column level as well kwargs["max_length"] = 127 - # similar to max_length, enforce at the field (form) validation level to not allow blanks - kwargs["blank"] = False # the default is False, but this is more explicit kwargs["allow_unicode"] = False super().__init__(*args, **kwargs) diff --git a/tests/pytest/core/test_models.py b/tests/pytest/core/test_models.py index 1cb359fc4..3ed267e93 100644 --- a/tests/pytest/core/test_models.py +++ b/tests/pytest/core/test_models.py @@ -25,6 +25,13 @@ def test_SecretNameField_init(): assert field.description != "" +def test_SecretNameField_init_null_blank(): + field = SecretNameField(blank=True, null=True) + + assert field.blank is True + assert field.null is True + + @pytest.mark.django_db def test_PemData_str(model_PemData): assert str(model_PemData) == model_PemData.label From 9915910f54d38e49b6687554fcd8a800ccbc099d Mon Sep 17 00:00:00 2001 From: Kegan Maher Date: Fri, 3 May 2024 15:07:01 +0000 Subject: [PATCH 2/2] fix(models): override display string for AuthProvider so it gets a more normal label in Admin screens --- benefits/core/models.py | 3 +++ tests/pytest/core/test_models.py | 1 + 2 files changed, 4 insertions(+) diff --git a/benefits/core/models.py b/benefits/core/models.py index d04ff9a12..22abac492 100644 --- a/benefits/core/models.py +++ b/benefits/core/models.py @@ -100,6 +100,9 @@ def supports_sign_out(self): def client_id(self): return get_secret_by_name(self.client_id_secret_name) + def __str__(self) -> str: + return self.client_name + class EligibilityType(models.Model): """A single conditional eligibility type.""" diff --git a/tests/pytest/core/test_models.py b/tests/pytest/core/test_models.py index 3ed267e93..0d2b8cf6d 100644 --- a/tests/pytest/core/test_models.py +++ b/tests/pytest/core/test_models.py @@ -96,6 +96,7 @@ def test_PemData_data_text_secret_name_and_remote__uses_remote( def test_model_AuthProvider(model_AuthProvider): assert not model_AuthProvider.supports_claims_verification assert model_AuthProvider.supports_sign_out + assert str(model_AuthProvider) == model_AuthProvider.client_name @pytest.mark.django_db