From e6c9c1e4f6b2c9dd9fe54c690680020b9d13c76f Mon Sep 17 00:00:00 2001 From: Sergei Maertens Date: Mon, 22 Jul 2024 15:30:00 +0200 Subject: [PATCH] :bug: [#74] Fix string representation of new model --- digid_eherkenning/models/certificates.py | 5 ++--- tests/test_certificate_models.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/digid_eherkenning/models/certificates.py b/digid_eherkenning/models/certificates.py index 76b351a..af6df00 100644 --- a/digid_eherkenning/models/certificates.py +++ b/digid_eherkenning/models/certificates.py @@ -152,9 +152,8 @@ class Meta: def __str__(self): config_type = self.get_config_type_display() # type: ignore - certificate = ( - str(cert) if (cert := self.certificate) else _("(no certificate selected)") - ) + _cert = self.certificate if self.certificate_id else None # type: ignore + certificate = str(_cert) if _cert else _("(no certificate selected)") return f"{config_type}: {certificate}" def _meets_requirements_to_be_used_for_saml(self) -> bool: diff --git a/tests/test_certificate_models.py b/tests/test_certificate_models.py index 3c3c50b..3bb226d 100644 --- a/tests/test_certificate_models.py +++ b/tests/test_certificate_models.py @@ -99,6 +99,18 @@ def test_private_key_missing(temp_private_root, digid_certificate, path): assert not config_certificate.is_ready_for_authn_requests +def test_string_representation(settings, digid_certificate): + settings.LANGUAGE_CODE = "en" + digid_certificate.label = "SAML" + cc1 = ConfigCertificate( + config_type=ConfigTypes.digid, certificate=digid_certificate + ) + assert str(cc1) == "DigiD: SAML" + + cc2 = ConfigCertificate(config_type=ConfigTypes.eherkenning, certificate=None) + assert str(cc2) == "eHerkenning: (no certificate selected)" + + # Helpers for multiple certificates - can't call fixtures multiple times to get # different outcomes.