mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-11 02:23:19 -04:00
Pass service domain to api when adding a new service
We need to pass the domain to api when adding a service so that api can link the domain of the service with a letter brand.
This commit is contained in:
@@ -10,10 +10,9 @@ from app.utils import AgreementInfo, email_safe, user_is_gov_user
|
|||||||
|
|
||||||
def _create_service(service_name, organisation_type, email_from, form):
|
def _create_service(service_name, organisation_type, email_from, form):
|
||||||
free_sms_fragment_limit = current_app.config['DEFAULT_FREE_SMS_FRAGMENT_LIMITS'].get(organisation_type)
|
free_sms_fragment_limit = current_app.config['DEFAULT_FREE_SMS_FRAGMENT_LIMITS'].get(organisation_type)
|
||||||
email_branding = email_branding_client.get_email_branding_id_for_domain(
|
|
||||||
'nhs.uk' if organisation_type == 'nhs' else
|
domain = 'nhs.uk' if organisation_type == 'nhs' else AgreementInfo.from_current_user().canonical_domain
|
||||||
AgreementInfo.from_current_user().canonical_domain
|
email_branding = email_branding_client.get_email_branding_id_for_domain(domain)
|
||||||
)
|
|
||||||
try:
|
try:
|
||||||
service_id = service_api_client.create_service(
|
service_id = service_api_client.create_service(
|
||||||
service_name=service_name,
|
service_name=service_name,
|
||||||
@@ -22,6 +21,7 @@ def _create_service(service_name, organisation_type, email_from, form):
|
|||||||
restricted=True,
|
restricted=True,
|
||||||
user_id=session['user_id'],
|
user_id=session['user_id'],
|
||||||
email_from=email_from,
|
email_from=email_from,
|
||||||
|
service_domain=domain
|
||||||
)
|
)
|
||||||
session['service_id'] = service_id
|
session['service_id'] = service_id
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ class ServiceAPIClient(NotifyAdminAPIClient):
|
|||||||
restricted,
|
restricted,
|
||||||
user_id,
|
user_id,
|
||||||
email_from,
|
email_from,
|
||||||
|
service_domain,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Create a service and return the json.
|
Create a service and return the json.
|
||||||
@@ -24,7 +25,8 @@ class ServiceAPIClient(NotifyAdminAPIClient):
|
|||||||
"message_limit": message_limit,
|
"message_limit": message_limit,
|
||||||
"user_id": user_id,
|
"user_id": user_id,
|
||||||
"restricted": restricted,
|
"restricted": restricted,
|
||||||
"email_from": email_from
|
"email_from": email_from,
|
||||||
|
"service_domain": service_domain
|
||||||
}
|
}
|
||||||
data = _attach_current_user(data)
|
data = _attach_current_user(data)
|
||||||
return self.post("/service", data)['data']['id']
|
return self.post("/service", data)['data']['id']
|
||||||
|
|||||||
@@ -49,7 +49,8 @@ def test_should_add_service_and_redirect_to_tour_when_no_services(
|
|||||||
message_limit=app_.config['DEFAULT_SERVICE_LIMIT'],
|
message_limit=app_.config['DEFAULT_SERVICE_LIMIT'],
|
||||||
restricted=True,
|
restricted=True,
|
||||||
user_id=api_user_active.id,
|
user_id=api_user_active.id,
|
||||||
email_from='testing.the.post'
|
email_from='testing.the.post',
|
||||||
|
service_domain=None
|
||||||
)
|
)
|
||||||
mock_create_service_template.assert_called_once_with(
|
mock_create_service_template.assert_called_once_with(
|
||||||
'Example text message template',
|
'Example text message template',
|
||||||
@@ -71,10 +72,10 @@ def test_should_add_service_and_redirect_to_tour_when_no_services(
|
|||||||
mock_create_or_update_free_sms_fragment_limit.assert_called_once_with(101, 25000)
|
mock_create_or_update_free_sms_fragment_limit.assert_called_once_with(101, 25000)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('organisation_type, free_allowance', [
|
@pytest.mark.parametrize('organisation_type, free_allowance, service_domain', [
|
||||||
('central', 250 * 1000),
|
('central', 250 * 1000, None),
|
||||||
('local', 25 * 1000),
|
('local', 25 * 1000, None),
|
||||||
('nhs', 25 * 1000),
|
('nhs', 25 * 1000, 'nhs.uk'),
|
||||||
])
|
])
|
||||||
def test_should_add_service_and_redirect_to_dashboard_when_existing_service(
|
def test_should_add_service_and_redirect_to_dashboard_when_existing_service(
|
||||||
app_,
|
app_,
|
||||||
@@ -86,6 +87,7 @@ def test_should_add_service_and_redirect_to_dashboard_when_existing_service(
|
|||||||
api_user_active,
|
api_user_active,
|
||||||
organisation_type,
|
organisation_type,
|
||||||
free_allowance,
|
free_allowance,
|
||||||
|
service_domain,
|
||||||
mock_create_or_update_free_sms_fragment_limit,
|
mock_create_or_update_free_sms_fragment_limit,
|
||||||
mock_get_all_email_branding,
|
mock_get_all_email_branding,
|
||||||
):
|
):
|
||||||
@@ -103,7 +105,8 @@ def test_should_add_service_and_redirect_to_dashboard_when_existing_service(
|
|||||||
message_limit=app_.config['DEFAULT_SERVICE_LIMIT'],
|
message_limit=app_.config['DEFAULT_SERVICE_LIMIT'],
|
||||||
restricted=True,
|
restricted=True,
|
||||||
user_id=api_user_active.id,
|
user_id=api_user_active.id,
|
||||||
email_from='testing.the.post'
|
email_from='testing.the.post',
|
||||||
|
service_domain=service_domain
|
||||||
)
|
)
|
||||||
mock_create_or_update_free_sms_fragment_limit.assert_called_once_with(101, free_allowance)
|
mock_create_or_update_free_sms_fragment_limit.assert_called_once_with(101, free_allowance)
|
||||||
assert len(mock_create_service_template.call_args_list) == 0
|
assert len(mock_create_service_template.call_args_list) == 0
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ def test_client_creates_service_with_correct_data(
|
|||||||
True,
|
True,
|
||||||
fake_uuid,
|
fake_uuid,
|
||||||
'test@example.com',
|
'test@example.com',
|
||||||
|
'nhs.uk'
|
||||||
)
|
)
|
||||||
mock_post.assert_called_once_with(
|
mock_post.assert_called_once_with(
|
||||||
'/service',
|
'/service',
|
||||||
@@ -89,6 +90,7 @@ def test_client_creates_service_with_correct_data(
|
|||||||
restricted=True,
|
restricted=True,
|
||||||
user_id=fake_uuid,
|
user_id=fake_uuid,
|
||||||
email_from='test@example.com',
|
email_from='test@example.com',
|
||||||
|
service_domain='nhs.uk'
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -249,7 +249,7 @@ def test_returns_value_from_cache(
|
|||||||
(user_api_client, 'set_user_permissions', [user_id, SERVICE_ONE_ID, []], {}),
|
(user_api_client, 'set_user_permissions', [user_id, SERVICE_ONE_ID, []], {}),
|
||||||
(user_api_client, 'activate_user', [api_user_pending(sample_uuid())], {}),
|
(user_api_client, 'activate_user', [api_user_pending(sample_uuid())], {}),
|
||||||
(service_api_client, 'remove_user_from_service', [SERVICE_ONE_ID, user_id], {}),
|
(service_api_client, 'remove_user_from_service', [SERVICE_ONE_ID, user_id], {}),
|
||||||
(service_api_client, 'create_service', ['', '', 0, False, user_id, sample_uuid()], {}),
|
(service_api_client, 'create_service', ['', '', 0, False, user_id, sample_uuid(), ''], {}),
|
||||||
(invite_api_client, 'accept_invite', [SERVICE_ONE_ID, user_id], {}),
|
(invite_api_client, 'accept_invite', [SERVICE_ONE_ID, user_id], {}),
|
||||||
])
|
])
|
||||||
def test_deletes_user_cache(
|
def test_deletes_user_cache(
|
||||||
|
|||||||
@@ -625,6 +625,7 @@ def mock_create_service(mocker):
|
|||||||
restricted,
|
restricted,
|
||||||
user_id,
|
user_id,
|
||||||
email_from,
|
email_from,
|
||||||
|
service_domain,
|
||||||
):
|
):
|
||||||
service = service_json(
|
service = service_json(
|
||||||
101, service_name, [user_id], message_limit=message_limit, restricted=restricted, email_from=email_from)
|
101, service_name, [user_id], message_limit=message_limit, restricted=restricted, email_from=email_from)
|
||||||
@@ -643,6 +644,7 @@ def mock_create_duplicate_service(mocker):
|
|||||||
restricted,
|
restricted,
|
||||||
user_id,
|
user_id,
|
||||||
email_from,
|
email_from,
|
||||||
|
service_domain,
|
||||||
):
|
):
|
||||||
json_mock = Mock(return_value={'message': {'name': ["Duplicate service name '{}'".format(service_name)]}})
|
json_mock = Mock(return_value={'message': {'name': ["Duplicate service name '{}'".format(service_name)]}})
|
||||||
resp_mock = Mock(status_code=400, json=json_mock)
|
resp_mock = Mock(status_code=400, json=json_mock)
|
||||||
|
|||||||
Reference in New Issue
Block a user