mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-04-27 04:31:11 -04:00
Add canonical domain info to agreement class
Because we alias domains (eg `foo.gsi.gov.uk` to `foo.gov.uk`, or where a local council has multiple domains) it could be hard to look up a brand (which has one domain field). Therefore we need a way of getting the canonical domain from a user’s email address, which we can later use to look up their branding.
This commit is contained in:
@@ -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,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -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",
|
||||
))
|
||||
|
||||
Reference in New Issue
Block a user