diff --git a/app/utils.py b/app/utils.py index 0590dd585..7b4dd5ca3 100644 --- a/app/utils.py +++ b/app/utils.py @@ -445,7 +445,8 @@ class AgreementInfo: ( self.owner, self.crown_status, - self.agreement_signed + self.agreement_signed, + self.canonical_domain, ) = self._get_info() @classmethod @@ -584,13 +585,16 @@ class AgreementInfo: details = self.domains.get(self._match) or {} if isinstance(details, str): + self.is_canonical = False return AgreementInfo(details)._get_info() elif isinstance(details, dict): + self.is_canonical = bool(details) return( details.get("owner"), details.get("crown"), details.get("agreement_signed"), + self._match, ) diff --git a/tests/app/test_utils.py b/tests/app/test_utils.py index 2e2594f8d..663fea524 100644 --- a/tests/app/test_utils.py +++ b/tests/app/test_utils.py @@ -395,6 +395,21 @@ def test_get_valid_agreement_info_known_details(domain_or_email_address): ) +@pytest.mark.parametrize("domain_or_email_address, is_canonical", ( + ("test@dclgdatamart.co.uk", False), + ("test@communities.gsi.gov.uk", False), + ("test@communities.gov.uk", True), +)) +def test_get_canonical_domain(domain_or_email_address, is_canonical): + assert AgreementInfo(domain_or_email_address).canonical_domain == 'communities.gov.uk' + assert AgreementInfo(domain_or_email_address).is_canonical == is_canonical + + +def test_get_canonical_domain_passes_through_unknown_domain(): + assert AgreementInfo('example.com').canonical_domain is None + assert AgreementInfo('example.com').is_canonical is False + + @pytest.mark.parametrize("domain_or_email_address", ( "test@police.gov.uk", "police.gov.uk", ))