Automatically associate new service with an org

This is the same thing we do in the admin app at the moment with YAML:
2f4e933b65/app/utils.py (L556-L562)
This commit is contained in:
Chris Hill-Scott
2019-02-19 12:02:18 +00:00
parent d7e03e00d3
commit c0fb9267bd
6 changed files with 131 additions and 6 deletions

View File

@@ -44,7 +44,9 @@ from tests.app.db import (
create_inbound_number,
create_service_sms_sender,
create_service_with_defined_sms_sender,
create_letter_branding
create_letter_branding,
create_organisation,
create_domain,
)
from tests.app.db import create_user
@@ -253,6 +255,51 @@ def test_create_service(admin_request, sample_user):
assert service_sms_senders[0].sms_sender == current_app.config['FROM_NUMBER']
@pytest.mark.parametrize('domain, expected_org', (
(None, False),
('', False),
('unknown.gov.uk', False),
('unknown-example.gov.uk', False),
('example.gov.uk', True),
('test.gov.uk', True),
('test.example.gov.uk', True),
))
def test_create_service_with_domain_sets_organisation(
admin_request,
sample_user,
domain,
expected_org,
):
org = create_organisation()
create_domain('example.gov.uk', org.id)
create_domain('test.gov.uk', org.id)
another_org = create_organisation(name='Another')
create_domain('cabinet-office.gov.uk', another_org.id)
create_domain('cabinetoffice.gov.uk', another_org.id)
sample_user.email_address = 'test@{}'.format(domain)
data = {
'name': 'created service',
'user_id': str(sample_user.id),
'message_limit': 1000,
'restricted': False,
'active': False,
'email_from': 'created.service',
'created_by': str(sample_user.id),
'service_domain': domain,
}
json_resp = admin_request.post('service.create_service', _data=data, _expected_status=201)
if expected_org:
assert json_resp['data']['organisation'] == str(org.id)
else:
assert json_resp['data']['organisation'] is None
def test_create_service_with_domain_sets_letter_branding(admin_request, sample_user):
letter_branding = create_letter_branding(
name='test domain', filename='test-domain', domain='test.domain'