mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-23 15:57:23 -04:00
Merge pull request #1534 from alphagov/collect-service-type
Collect organisation type when user creates a service and use it to calculate text message allowance
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import pytest
|
||||
from flask import url_for, session
|
||||
|
||||
from app.utils import is_gov_user
|
||||
@@ -20,7 +21,7 @@ def test_get_should_render_add_service_template(
|
||||
):
|
||||
response = logged_in_client.get(url_for('main.add_service'))
|
||||
assert response.status_code == 200
|
||||
assert 'Which service do you want to set up notifications for?' in response.get_data(as_text=True)
|
||||
assert 'About your service' in response.get_data(as_text=True)
|
||||
|
||||
|
||||
def test_should_add_service_and_redirect_to_tour_when_no_services(
|
||||
@@ -33,11 +34,17 @@ def test_should_add_service_and_redirect_to_tour_when_no_services(
|
||||
):
|
||||
response = logged_in_client.post(
|
||||
url_for('main.add_service'),
|
||||
data={'name': 'testing the post'})
|
||||
data={
|
||||
'name': 'testing the post',
|
||||
'organisation_type': 'local',
|
||||
}
|
||||
)
|
||||
assert mock_get_services_with_no_services.called
|
||||
mock_create_service.assert_called_once_with(
|
||||
service_name='testing the post',
|
||||
organisation_type='local',
|
||||
message_limit=app_.config['DEFAULT_SERVICE_LIMIT'],
|
||||
free_sms_fragment_limit=25000,
|
||||
restricted=True,
|
||||
user_id=api_user_active.id,
|
||||
email_from='testing.the.post'
|
||||
@@ -62,6 +69,11 @@ def test_should_add_service_and_redirect_to_tour_when_no_services(
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('organisation_type, free_allowance', [
|
||||
('central', 250 * 1000),
|
||||
('local', 25 * 1000),
|
||||
('nhs', 25 * 1000),
|
||||
])
|
||||
def test_should_add_service_and_redirect_to_dashboard_when_existing_service(
|
||||
app_,
|
||||
logged_in_client,
|
||||
@@ -69,14 +81,22 @@ def test_should_add_service_and_redirect_to_dashboard_when_existing_service(
|
||||
mock_create_service_template,
|
||||
mock_get_services,
|
||||
api_user_active,
|
||||
organisation_type,
|
||||
free_allowance,
|
||||
):
|
||||
response = logged_in_client.post(
|
||||
url_for('main.add_service'),
|
||||
data={'name': 'testing the post'})
|
||||
data={
|
||||
'name': 'testing the post',
|
||||
'organisation_type': organisation_type,
|
||||
}
|
||||
)
|
||||
assert mock_get_services.called
|
||||
mock_create_service.assert_called_once_with(
|
||||
service_name='testing the post',
|
||||
organisation_type=organisation_type,
|
||||
message_limit=app_.config['DEFAULT_SERVICE_LIMIT'],
|
||||
free_sms_fragment_limit=free_allowance,
|
||||
restricted=True,
|
||||
user_id=api_user_active.id,
|
||||
email_from='testing.the.post'
|
||||
@@ -99,7 +119,13 @@ def test_should_return_form_errors_with_duplicate_service_name_regardless_of_cas
|
||||
logged_in_client,
|
||||
mock_create_duplicate_service,
|
||||
):
|
||||
response = logged_in_client.post(url_for('main.add_service'), data={'name': 'SERVICE ONE'})
|
||||
response = logged_in_client.post(
|
||||
url_for('main.add_service'),
|
||||
data={
|
||||
'name': 'SERVICE ONE',
|
||||
'organisation_type': 'central',
|
||||
},
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert 'This service name is already in use' in response.get_data(as_text=True)
|
||||
|
||||
@@ -22,7 +22,7 @@ from tests.conftest import (
|
||||
get_non_default_reply_to_email_address,
|
||||
get_default_letter_contact_block,
|
||||
get_non_default_letter_contact_block,
|
||||
SERVICE_ONE_ID
|
||||
SERVICE_ONE_ID,
|
||||
)
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ from tests.conftest import (
|
||||
|
||||
'Label Value Action',
|
||||
'Send emails On Change',
|
||||
'Email reply to addresses None Change',
|
||||
'Email reply to addresses Not set Change',
|
||||
|
||||
'Label Value Action',
|
||||
'Send text messages On Change',
|
||||
@@ -53,7 +53,7 @@ from tests.conftest import (
|
||||
|
||||
'Label Value Action',
|
||||
'Send emails On Change',
|
||||
'Email reply to addresses None Change',
|
||||
'Email reply to addresses Not set Change',
|
||||
|
||||
'Label Value Action',
|
||||
'Send text messages On Change',
|
||||
@@ -65,6 +65,8 @@ from tests.conftest import (
|
||||
'Send letters Off Change',
|
||||
|
||||
'Label Value Action',
|
||||
'Organisation type Central Change',
|
||||
'Free text message allowance 250,000 Change',
|
||||
'Email branding GOV.UK Change',
|
||||
'Letter branding HM Government Change',
|
||||
|
||||
@@ -113,7 +115,7 @@ def test_should_show_overview(
|
||||
'Text message sender 0781239871',
|
||||
'International text messages On Change',
|
||||
'Receive text messages On Change',
|
||||
'API endpoint for received text messages None Change',
|
||||
'API endpoint for received text messages Not set Change',
|
||||
|
||||
'Label Value Action',
|
||||
'Send letters Off Change',
|
||||
@@ -250,7 +252,7 @@ def test_letter_contact_block_shows_none_if_not_set(
|
||||
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
div = page.find_all('tr')[8].find_all('td')[1].div
|
||||
assert div.text.strip() == 'None'
|
||||
assert div.text.strip() == 'Not set'
|
||||
assert 'default' in div.attrs['class'][0]
|
||||
|
||||
|
||||
@@ -1360,6 +1362,121 @@ def test_should_set_branding_and_organisations(
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('method', ['get', 'post'])
|
||||
@pytest.mark.parametrize('endpoint', [
|
||||
'main.set_organisation_type',
|
||||
'main.set_free_sms_allowance',
|
||||
])
|
||||
def test_organisation_type_pages_are_platform_admin_only(
|
||||
client_request,
|
||||
method,
|
||||
endpoint,
|
||||
):
|
||||
getattr(client_request, method)(
|
||||
endpoint,
|
||||
service_id=SERVICE_ONE_ID,
|
||||
_expected_status=403,
|
||||
_test_page_title=False,
|
||||
)
|
||||
|
||||
|
||||
def test_should_show_page_to_set_organisation_type(
|
||||
logged_in_platform_admin_client,
|
||||
):
|
||||
response = logged_in_platform_admin_client.get(url_for(
|
||||
'main.set_organisation_type',
|
||||
service_id=SERVICE_ONE_ID
|
||||
))
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
|
||||
labels = page.select('label')
|
||||
checked_radio_buttons = page.select('input[checked]')
|
||||
|
||||
assert len(checked_radio_buttons) == 1
|
||||
assert checked_radio_buttons[0]['value'] == 'central'
|
||||
|
||||
assert len(labels) == 3
|
||||
for index, expected in enumerate((
|
||||
'Central government',
|
||||
'Local government',
|
||||
'NHS',
|
||||
)):
|
||||
assert normalize_spaces(labels[index].text) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize('organisation_type', [
|
||||
'central',
|
||||
'local',
|
||||
'nhs',
|
||||
pytest.mark.xfail('private sector'),
|
||||
])
|
||||
def test_should_set_organisation_type(
|
||||
logged_in_platform_admin_client,
|
||||
mock_update_service,
|
||||
organisation_type,
|
||||
):
|
||||
response = logged_in_platform_admin_client.post(
|
||||
url_for(
|
||||
'main.set_organisation_type',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
),
|
||||
data={
|
||||
'organisation_type': organisation_type,
|
||||
'organisation': 'organisation-id'
|
||||
},
|
||||
)
|
||||
assert response.status_code == 302
|
||||
assert response.location == url_for('main.service_settings', service_id=SERVICE_ONE_ID, _external=True)
|
||||
|
||||
mock_update_service.assert_called_once_with(
|
||||
SERVICE_ONE_ID,
|
||||
organisation_type=organisation_type,
|
||||
)
|
||||
|
||||
|
||||
def test_should_show_page_to_set_sms_allowance(
|
||||
logged_in_platform_admin_client,
|
||||
):
|
||||
response = logged_in_platform_admin_client.get(url_for(
|
||||
'main.set_free_sms_allowance',
|
||||
service_id=SERVICE_ONE_ID
|
||||
))
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
|
||||
assert normalize_spaces(page.select_one('label').text) == 'Numbers of text message fragments per year'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('given_allowance, expected_api_argument', [
|
||||
('1', 1),
|
||||
('250000', 250000),
|
||||
pytest.mark.xfail(('foo', 'foo')),
|
||||
])
|
||||
def test_should_set_sms_allowance(
|
||||
logged_in_platform_admin_client,
|
||||
mock_update_service,
|
||||
given_allowance,
|
||||
expected_api_argument,
|
||||
):
|
||||
response = logged_in_platform_admin_client.post(
|
||||
url_for(
|
||||
'main.set_free_sms_allowance',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
),
|
||||
data={
|
||||
'free_sms_allowance': given_allowance,
|
||||
},
|
||||
)
|
||||
assert response.status_code == 302
|
||||
assert response.location == url_for('main.service_settings', service_id=SERVICE_ONE_ID, _external=True)
|
||||
|
||||
mock_update_service.assert_called_once_with(
|
||||
SERVICE_ONE_ID,
|
||||
free_sms_fragment_limit=expected_api_argument,
|
||||
)
|
||||
|
||||
|
||||
def test_switch_service_enable_letters(
|
||||
logged_in_platform_admin_client,
|
||||
service_one,
|
||||
|
||||
Reference in New Issue
Block a user