From 056c4ebb8852a356da1c7265646ede2518b23ad2 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Fri, 9 Mar 2018 14:53:04 +0000 Subject: [PATCH] Rename GovernmentDomain to AgreementInfo This better describes the data encapsulated by this class, and how we are now using it. --- app/main/views/index.py | 4 +- app/main/views/service_settings.py | 4 +- app/utils.py | 10 ++--- tests/app/test_utils.py | 70 +++++++++++++++--------------- 4 files changed, 44 insertions(+), 44 deletions(-) diff --git a/app/main/views/index.py b/app/main/views/index.py index ba77fb748..d269c4d08 100644 --- a/app/main/views/index.py +++ b/app/main/views/index.py @@ -9,7 +9,7 @@ from app import convert_to_boolean from app.main import main from app.main.forms import SearchTemplatesForm from app.main.views.sub_navigation_dictionaries import features_nav -from app.utils import GovernmentDomain +from app.utils import AgreementInfo @main.route('/') @@ -154,7 +154,7 @@ def terms(): return render_template( 'views/terms-of-use.html', navigation_links=features_nav(), - agreement_info=GovernmentDomain.from_current_user(), + agreement_info=AgreementInfo.from_current_user(), ) diff --git a/app/main/views/service_settings.py b/app/main/views/service_settings.py index 4f38482e2..dd2f558f4 100644 --- a/app/main/views/service_settings.py +++ b/app/main/views/service_settings.py @@ -44,7 +44,7 @@ from app.main.forms import ( SMSPrefixForm, ) from app.utils import ( - GovernmentDomain, + AgreementInfo, email_safe, get_cdn_domain, user_has_permissions, @@ -205,7 +205,7 @@ def submit_request_to_go_live(service_id): current_service['name'], url_for('main.service_dashboard', service_id=current_service['id'], _external=True), current_service['organisation_type'], - GovernmentDomain.from_current_user().as_human_readable, + AgreementInfo.from_current_user().as_human_readable, formatted_list(filter(None, ( 'email' if form.channel_email.data else None, 'text messages' if form.channel_sms.data else None, diff --git a/app/utils.py b/app/utils.py index b7bd27871..e5fcba1ad 100644 --- a/app/utils.py +++ b/app/utils.py @@ -443,7 +443,7 @@ def set_status_filters(filter_args): _dir_path = os.path.dirname(os.path.realpath(__file__)) -class GovernmentDomain: +class AgreementInfo: with open('{}/domains.yml'.format(_dir_path)) as domains: domains = yaml.safe_load(domains) @@ -460,7 +460,7 @@ class GovernmentDomain: self.owner, self.crown_status, self.agreement_signed - ) = self._get_details_of_domain() + ) = self._get_info() @classmethod def from_user(cls, user): @@ -507,12 +507,12 @@ class GovernmentDomain: return fn - def _get_details_of_domain(self): + def _get_info(self): details = self.domains.get(self._match) or {} if isinstance(details, str): - return GovernmentDomain(details)._get_details_of_domain() + return AgreementInfo(details)._get_info() elif isinstance(details, dict): return( @@ -526,7 +526,7 @@ class NotGovernmentEmailDomain(Exception): pass -class GovernmentEmailDomain(GovernmentDomain): +class GovernmentEmailDomain(AgreementInfo): with open('{}/email_domains.yml'.format(_dir_path)) as email_domains: domain_names = yaml.safe_load(email_domains) diff --git a/tests/app/test_utils.py b/tests/app/test_utils.py index 9e16b46c1..ac824e067 100644 --- a/tests/app/test_utils.py +++ b/tests/app/test_utils.py @@ -8,7 +8,7 @@ from freezegun import freeze_time from tests.conftest import fake_uuid from app.utils import ( - GovernmentDomain, + AgreementInfo, Spreadsheet, email_safe, generate_next_dict, @@ -382,12 +382,12 @@ def test_get_cdn_domain_on_non_localhost(client, mocker): @pytest.mark.parametrize("domain_or_email_address", ( "test@dclgdatamart.co.uk", "test@communities.gsi.gov.uk", "test@communities.gov.uk", )) -def test_get_valid_government_domain_known_details(domain_or_email_address): - government_domain = GovernmentDomain(domain_or_email_address) - assert government_domain.crown_status is None - assert government_domain.owner == "Ministry of Housing, Communities & Local Government" - assert government_domain.agreement_signed is True - assert government_domain.as_human_readable == ( +def test_get_valid_agreement_info_known_details(domain_or_email_address): + agreement_info = AgreementInfo(domain_or_email_address) + assert agreement_info.crown_status is None + assert agreement_info.owner == "Ministry of Housing, Communities & Local Government" + assert agreement_info.agreement_signed is True + assert agreement_info.as_human_readable == ( 'Yes, on behalf of Ministry of Housing, Communities & Local Government' ) @@ -395,46 +395,46 @@ def test_get_valid_government_domain_known_details(domain_or_email_address): @pytest.mark.parametrize("domain_or_email_address", ( "test@police.gov.uk", "police.gov.uk", )) -def test_get_valid_government_domain_unknown_details(domain_or_email_address): - government_domain = GovernmentDomain(domain_or_email_address) +def test_get_valid_agreement_info_unknown_details(domain_or_email_address): + government_domain = AgreementInfo(domain_or_email_address) assert government_domain.crown_status is None assert government_domain.owner is None assert government_domain.agreement_signed is None assert government_domain.as_human_readable == 'Can’t tell' -def test_get_valid_government_domain_only_org_known(): - government_domain = GovernmentDomain('nhs.net') +def test_get_valid_agreement_info_only_org_known(): + agreement_info = AgreementInfo('nhs.net') # Some parts of the NHS are Crown, some aren’t - assert government_domain.crown_status is None - assert government_domain.owner == 'NHS' - assert government_domain.agreement_signed is None - assert government_domain.as_human_readable == 'Can’t tell (organisation is NHS, crown status unknown)' + assert agreement_info.crown_status is None + assert agreement_info.owner == 'NHS' + assert agreement_info.agreement_signed is None + assert agreement_info.as_human_readable == 'Can’t tell (organisation is NHS, crown status unknown)' -def test_get_valid_government_domain_some_known_details(): - government_domain = GovernmentDomain("marinemanagement.org.uk") - assert government_domain.crown_status is None - assert government_domain.owner == "Marine Management Organisation" - assert government_domain.agreement_signed is True - assert government_domain.as_human_readable == ( +def test_get_valid_agreement_info_some_known_details(): + agreement_info = AgreementInfo("marinemanagement.org.uk") + assert agreement_info.crown_status is None + assert agreement_info.owner == "Marine Management Organisation" + assert agreement_info.agreement_signed is True + assert agreement_info.as_human_readable == ( 'Yes, on behalf of Marine Management Organisation' ) -def test_get_valid_local_government_domain_some_known_details(): - government_domain = GovernmentDomain("aberdeenshire.gov.uk") - assert government_domain.crown_status is False - assert government_domain.owner == "Aberdeenshire Council" - assert government_domain.agreement_signed is False - assert government_domain.as_human_readable == ( +def test_get_valid_local_agreement_info_some_known_details(): + agreement_info = AgreementInfo("aberdeenshire.gov.uk") + assert agreement_info.crown_status is False + assert agreement_info.owner == "Aberdeenshire Council" + assert agreement_info.agreement_signed is False + assert agreement_info.as_human_readable == ( 'No (organisation is Aberdeenshire Council, a non-crown body)' ) def test_get_valid_government_domain_gets_most_specific_first(): - generic = GovernmentDomain("gov.uk") + generic = AgreementInfo("gov.uk") assert generic.crown_status is None assert generic.owner is None assert generic.agreement_signed is None @@ -442,7 +442,7 @@ def test_get_valid_government_domain_gets_most_specific_first(): 'Can’t tell' ) - specific = GovernmentDomain("dacorum.gov.uk") + specific = AgreementInfo("dacorum.gov.uk") assert specific.crown_status is False assert specific.owner == 'Dacorum Borough Council' assert specific.agreement_signed is True @@ -453,20 +453,20 @@ def test_get_valid_government_domain_gets_most_specific_first(): def test_validate_government_domain_data(): - for domain in GovernmentDomain.domains.keys(): + for domain in AgreementInfo.domains.keys(): - government_domain = GovernmentDomain(domain) + agreement_info = AgreementInfo(domain) - assert government_domain.crown_status in { + assert agreement_info.crown_status in { True, False, None } assert ( - government_domain.owner is None + agreement_info.owner is None ) or ( - isinstance(government_domain.owner, str) + isinstance(agreement_info.owner, str) ) - assert government_domain.agreement_signed in { + assert agreement_info.agreement_signed in { True, False, None }