Skip to content

Commit

Permalink
🐛 [#74] Fix string representation of new model
Browse files Browse the repository at this point in the history
  • Loading branch information
sergei-maertens committed Jul 22, 2024
1 parent a9f8b8d commit e6c9c1e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 2 additions & 3 deletions digid_eherkenning/models/certificates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions tests/test_certificate_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit e6c9c1e

Please sign in to comment.