Merge branch 'master' into record-user-that-requested-to-go-live

This commit is contained in:
Chris Hill-Scott
2019-04-23 15:38:44 +01:00
committed by GitHub
51 changed files with 733 additions and 550 deletions

View File

@@ -77,8 +77,10 @@ def test_robots(client):
@pytest.mark.parametrize('view', [
'cookies', 'privacy', 'using_notify', 'pricing', 'terms', 'roadmap',
'features', 'callbacks', 'documentation', 'security'
'cookies', 'privacy', 'pricing', 'terms', 'roadmap',
'features', 'callbacks', 'documentation', 'security',
'message_status', 'features_email', 'features_sms',
'features_letters',
])
def test_static_pages(
client_request,
@@ -89,26 +91,6 @@ def test_static_pages(
assert not page.select_one('meta[name=description]')
@pytest.mark.parametrize('view, expected_anchor', [
('delivery_and_failure', 'messagedeliveryandfailure'),
('trial_mode', 'trial-mode'),
])
def test_old_static_pages_redirect_to_using_notify_with_anchor(
client_request,
view,
expected_anchor,
):
client_request.get(
'main.{}'.format(view),
_expected_status=301,
_expected_redirect=url_for(
'main.using_notify',
_anchor=expected_anchor,
_external=True
),
)
@pytest.mark.parametrize('view, expected_view', [
('information_risk_management', 'security'),
('old_integration_testing', 'integration_testing'),
@@ -117,6 +99,7 @@ def test_old_static_pages_redirect_to_using_notify_with_anchor(
('old_terms', 'terms'),
('information_security', 'using_notify'),
('old_using_notify', 'using_notify'),
('delivery_and_failure', 'message_status'),
])
def test_old_static_pages_redirect(
client,
@@ -131,6 +114,10 @@ def test_old_static_pages_redirect(
)
def test_old_using_notify_page(client_request):
client_request.get('main.using_notify', _expected_status=410)
def test_old_integration_testing_page(
client_request,
):
@@ -162,29 +149,11 @@ def test_terms_is_generic_if_user_is_not_logged_in(
)
def test_pricing_is_generic_if_user_is_not_logged_in(
client
):
response = client.get(url_for('main.pricing'))
assert response.status_code == 200
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
last_paragraph = page.select('main p')[-1]
assert normalize_spaces(last_paragraph.text) == (
'Sign in to download a copy or find out if one is already '
'in place with your organisation.'
)
assert last_paragraph.select_one('a')['href'] == url_for(
'main.sign_in',
next=url_for('main.pricing', _anchor='paying'),
)
@pytest.mark.parametrize((
'name,'
'agreement_signed,'
'expected_terms_paragraph,'
'expected_terms_link,'
'expected_pricing_paragraph'
), [
(
'Cabinet Office',
@@ -194,10 +163,6 @@ def test_pricing_is_generic_if_user_is_not_logged_in(
'the GOV.UK Notify data sharing and financial agreement.'
),
None,
(
'Download the agreement '
'(Cabinet Office has already accepted it).'
),
),
(
'Aylesbury Town Council',
@@ -211,10 +176,6 @@ def test_pricing_is_generic_if_user_is_not_logged_in(
url_for,
'main.agreement',
),
(
'Download the agreement '
'(Aylesbury Town Council hasnt accepted it yet).'
),
),
(
None,
@@ -229,10 +190,6 @@ def test_pricing_is_generic_if_user_is_not_logged_in(
url_for,
'main.agreement',
),
(
'Download the agreement or contact us to find out if '
'we already have one in place with your organisation.'
),
),
(
'Met Office',
@@ -245,10 +202,6 @@ def test_pricing_is_generic_if_user_is_not_logged_in(
url_for,
'main.agreement',
),
(
'Download the agreement (Met Office hasnt accepted it '
'yet).'
),
),
])
def test_terms_tells_logged_in_users_what_we_know_about_their_agreement(
@@ -259,7 +212,6 @@ def test_terms_tells_logged_in_users_what_we_know_about_their_agreement(
agreement_signed,
expected_terms_paragraph,
expected_terms_link,
expected_pricing_paragraph,
):
mock_get_organisation_by_domain(
mocker,
@@ -267,13 +219,12 @@ def test_terms_tells_logged_in_users_what_we_know_about_their_agreement(
agreement_signed=agreement_signed,
)
terms_page = client_request.get('main.terms')
pricing_page = client_request.get('main.pricing')
assert normalize_spaces(terms_page.select('main p')[1].text) == expected_terms_paragraph
if expected_terms_link:
assert terms_page.select_one('main p a')['href'] == expected_terms_link()
else:
assert not terms_page.select_one('main p').select('a')
assert normalize_spaces(pricing_page.select('main p')[-1].text) == expected_pricing_paragraph
def test_css_is_served_from_correct_path(client_request):

View File

@@ -360,7 +360,7 @@ def test_should_show_letter_job_with_banner_after_sending_before_1730(
assert page.select('p.bottom-gutter') == []
assert normalize_spaces(page.select('.banner-default-with-tick')[0].text) == (
'Your letter has been sent. Printing starts today at 5.30pm.'
'Your letter has been sent. Printing starts today at 5:30pm.'
)
@@ -383,7 +383,7 @@ def test_should_show_letter_job_with_banner_when_there_are_multiple_CSV_rows(
assert page.select('p.bottom-gutter') == []
assert normalize_spaces(page.select('.banner-default-with-tick')[0].text) == (
'Your letters have been sent. Printing starts today at 5.30pm.'
'Your letters have been sent. Printing starts today at 5:30pm.'
)
@@ -406,7 +406,7 @@ def test_should_show_letter_job_with_banner_after_sending_after_1730(
assert page.select('p.bottom-gutter') == []
assert normalize_spaces(page.select('.banner-default-with-tick')[0].text) == (
'Your letter has been sent. Printing starts tomorrow at 5.30pm.'
'Your letter has been sent. Printing starts tomorrow at 5:30pm.'
)

View File

@@ -167,7 +167,7 @@ def test_notification_page_shows_page_for_letter_notification(
"sample template was sent by Test User on 1 January at 1:01am"
)
assert normalize_spaces(page.select('main p:nth-of-type(2)')[0].text) == (
'Printing starts today at 5.30pm'
'Printing starts today at 5:30pm'
)
assert normalize_spaces(page.select('main p:nth-of-type(3)')[0].text) == (
'Estimated delivery date: 6 January'
@@ -416,7 +416,7 @@ def test_notification_page_shows_page_for_first_class_letter_notification(
notification_id=fake_uuid,
)
assert normalize_spaces(page.select('main p:nth-of-type(2)')[0].text) == 'Printing starts tomorrow at 5.30pm'
assert normalize_spaces(page.select('main p:nth-of-type(2)')[0].text) == 'Printing starts tomorrow at 5:30pm'
assert normalize_spaces(page.select('main p:nth-of-type(3)')[0].text) == 'Estimated delivery date: 5 January'
assert normalize_spaces(page.select_one('.letter-postage').text) == (
'Postage: first class'
@@ -716,14 +716,14 @@ def test_should_show_image_of_precompiled_letter_notification(
@pytest.mark.parametrize('created_at, current_datetime', [
('2017-07-07T12:00:00+00:00', '2017-07-07 16:29:00'), # created today, summer
('2017-12-12T12:00:00+00:00', '2017-12-12 17:29:00'), # created today, winter
('2017-12-12T21:30:00+00:00', '2017-12-13 17:29:00'), # created after 5.30 yesterday
('2017-12-12T21:30:00+00:00', '2017-12-13 17:29:00'), # created after 5:30 yesterday
('2017-03-25T17:30:00+00:00', '2017-03-26 16:29:00'), # over clock change period on 2017-03-26
])
def test_get_letter_printing_statement_when_letter_prints_today(created_at, current_datetime):
with freeze_time(current_datetime):
statement = get_letter_printing_statement('created', created_at)
assert statement == 'Printing starts today at 5.30pm'
assert statement == 'Printing starts today at 5:30pm'
@pytest.mark.parametrize('created_at, current_datetime', [
@@ -734,7 +734,7 @@ def test_get_letter_printing_statement_when_letter_prints_tomorrow(created_at, c
with freeze_time(current_datetime):
statement = get_letter_printing_statement('created', created_at)
assert statement == 'Printing starts tomorrow at 5.30pm'
assert statement == 'Printing starts tomorrow at 5:30pm'
@pytest.mark.parametrize('created_at, print_day', [

View File

@@ -643,6 +643,7 @@ def test_should_check_if_estimated_volumes_provided(
mock_get_service_templates,
mock_get_users_by_service,
mock_get_service_organisation,
mock_get_invites_for_service,
volumes,
consent_to_research,
expected_estimated_volumes_item,
@@ -675,9 +676,14 @@ def test_should_check_if_estimated_volumes_provided(
)
@pytest.mark.parametrize('count_of_users_with_manage_service, expected_user_checklist_item', [
(1, 'Add a team member who can manage settings, team and usage Not completed'),
(2, 'Add a team member who can manage settings, team and usage Completed'),
@pytest.mark.parametrize((
'count_of_users_with_manage_service,'
'count_of_invites_with_manage_service,'
'expected_user_checklist_item'
), [
(1, 0, 'Add a team member who can manage settings, team and usage Not completed'),
(2, 0, 'Add a team member who can manage settings, team and usage Completed'),
(1, 1, 'Add a team member who can manage settings, team and usage Completed'),
])
@pytest.mark.parametrize('count_of_templates, expected_templates_checklist_item', [
(0, 'Add templates with examples of the content you plan to send Not completed'),
@@ -705,6 +711,7 @@ def test_should_check_for_sending_things_right(
mock_get_service_organisation,
single_sms_sender,
count_of_users_with_manage_service,
count_of_invites_with_manage_service,
expected_user_checklist_item,
count_of_templates,
expected_templates_checklist_item,
@@ -720,9 +727,13 @@ def test_should_check_for_sending_things_right(
}.get(template_type)
mock_count_users = mocker.patch(
'app.main.views.service_settings.user_api_client.get_count_of_users_with_permission',
'app.models.service.user_api_client.get_count_of_users_with_permission',
return_value=count_of_users_with_manage_service
)
mock_count_invites = mocker.patch(
'app.models.service.invite_api_client.get_count_of_invites_with_permission',
return_value=count_of_invites_with_manage_service
)
mock_templates = mocker.patch(
'app.models.service.Service.all_templates',
@@ -760,6 +771,7 @@ def test_should_check_for_sending_things_right(
assert normalize_spaces(checklist_items[3].text) == expected_reply_to_checklist_item
mock_count_users.assert_called_once_with(SERVICE_ONE_ID, 'manage_service')
mock_count_invites.assert_called_once_with(SERVICE_ONE_ID, 'manage_service')
assert mock_templates.called is True
if count_of_email_templates:
@@ -779,6 +791,7 @@ def test_should_not_show_go_live_button_if_checklist_not_complete(
mock_get_service_templates,
mock_get_users_by_service,
mock_get_service_organisation,
mock_get_invites_for_service,
single_sms_sender,
checklist_completed,
agreement_signed,
@@ -919,6 +932,7 @@ def test_should_check_for_sms_sender_on_go_live(
service_one,
mocker,
mock_get_service_organisation,
mock_get_invites_for_service,
organisation_type,
count_of_sms_templates,
sms_senders,
@@ -997,6 +1011,7 @@ def test_should_check_for_mou_on_request_to_go_live(
service_one,
mocker,
agreement_signed,
mock_get_invites_for_service,
expected_item,
):
mocker.patch(
@@ -1041,6 +1056,7 @@ def test_should_check_for_mou_on_request_to_go_live(
def test_non_gov_user_is_told_they_cant_go_live(
client_request,
api_nongov_user_active,
mock_get_invites_for_service,
mocker,
mock_get_service_organisation,
):
@@ -1319,6 +1335,7 @@ def test_should_redirect_after_request_to_go_live(
mock_get_service_templates,
mock_get_users_by_service,
mock_update_service,
mock_get_invites_without_manage_permission,
volumes,
displayed_volumes,
formatted_displayed_volumes,
@@ -1608,6 +1625,7 @@ def test_route_permissions(
single_reply_to_email_address,
single_letter_contact_block,
mock_get_service_organisation,
mock_get_invites_for_service,
single_sms_sender,
route,
mock_get_service_settings_page_common,
@@ -1641,6 +1659,7 @@ def test_route_invalid_permissions(
service_one,
route,
mock_get_service_templates,
mock_get_invites_for_service,
):
validate_route_permission(
mocker,
@@ -1673,6 +1692,7 @@ def test_route_for_platform_admin(
route,
mock_get_service_settings_page_common,
mock_get_service_templates,
mock_get_invites_for_service,
):
validate_route_permission(mocker,
app_,

View File

@@ -2258,6 +2258,25 @@ def mock_get_invites_for_service(mocker, service_one, sample_invite):
return mocker.patch('app.invite_api_client._get_invites_for_service', side_effect=_get_invites)
@pytest.fixture(scope='function')
def mock_get_invites_without_manage_permission(mocker, service_one, sample_invite):
def _get_invites(service_id):
return [invite_json(
id_=str(sample_uuid()),
from_user=service_one['users'][0],
email_address='invited_user@test.gov.uk',
service_id=service_one['id'],
permissions='view_activity,send_messages,manage_api_keys',
created_at=str(datetime.utcnow()),
auth_type='sms_auth',
folder_permissions=[],
status='pending',
)]
return mocker.patch('app.invite_api_client._get_invites_for_service', side_effect=_get_invites)
@pytest.fixture(scope='function')
def mock_check_invite_token(mocker, sample_invite):
def _check_token(token):