Make fixture for getting service with organisation

Saves repeatedly defining the same mock.
This commit is contained in:
Chris Hill-Scott
2020-04-02 13:12:06 +01:00
parent 51a5a4b559
commit 0904ac0533
5 changed files with 36 additions and 110 deletions
@@ -1,4 +1,4 @@
from unittest.mock import ANY, Mock, PropertyMock
from unittest.mock import ANY, Mock
import pytest
from bs4 import BeautifulSoup
@@ -195,16 +195,12 @@ def test_create_new_organisation_fails_if_new_name_has_less_than_2_alphanumeric_
def test_gps_can_create_own_organisations(
client_request,
mocker,
mock_get_service_organisation,
service_one,
organisation_type,
organisation,
expected_status,
):
mocker.patch(
'app.models.service.Service.organisation_id',
new_callable=PropertyMock,
return_value=ORGANISATION_ID,
)
mocker.patch('app.organisations_client.get_organisation', return_value=organisation)
service_one['organisation_type'] = organisation_type
@@ -234,16 +230,12 @@ def test_gps_can_create_own_organisations(
def test_nhs_local_can_create_own_organisations(
client_request,
mocker,
mock_get_service_organisation,
service_one,
organisation_type,
organisation,
expected_status,
):
mocker.patch(
'app.models.service.Service.organisation_id',
new_callable=PropertyMock,
return_value=ORGANISATION_ID,
)
mocker.patch('app.organisations_client.get_organisation', return_value=organisation)
mocker.patch(
'app.models.organisation.Organisations.client_method',
@@ -1,11 +1,10 @@
import functools
from unittest.mock import PropertyMock
import pytest
from flask import url_for
from app.main.views.service_settings import PLATFORM_ADMIN_SERVICE_PERMISSIONS
from tests.conftest import ORGANISATION_ID, normalize_spaces
from tests.conftest import normalize_spaces
@pytest.fixture
@@ -79,6 +78,7 @@ def test_service_set_permission(
])
def test_service_setting_toggles_show(
mocker,
mock_get_service_organisation,
get_service_settings_page,
service_one,
service_fields,
@@ -88,11 +88,6 @@ def test_service_setting_toggles_show(
):
link_url = url_for(endpoint, **kwargs, service_id=service_one['id'])
service_one.update(service_fields)
mocker.patch(
'app.models.service.Service.organisation_id',
new_callable=PropertyMock,
return_value=ORGANISATION_ID,
)
page = get_service_settings_page()
assert normalize_spaces(page.find('a', {'href': link_url}).find_parent('tr').text.strip()) == text
+9 -44
View File
@@ -1,6 +1,6 @@
from functools import partial
from io import BytesIO
from unittest.mock import PropertyMock, call
from unittest.mock import call
import pytest
from flask import url_for
@@ -85,16 +85,12 @@ def test_show_agreement_page(
client_request,
mocker,
fake_uuid,
mock_get_service_organisation,
mock_has_jobs,
agreement_signed,
crown,
expected_links,
):
mocker.patch(
'app.models.service.Service.organisation_id',
new_callable=PropertyMock,
return_value=ORGANISATION_ID,
)
org = organisation_json(
crown=crown,
agreement_signed=agreement_signed
@@ -154,16 +150,12 @@ def test_unknown_gps_and_trusts_are_redirected(
def test_download_service_agreement(
logged_in_client,
mocker,
mock_get_service_organisation,
crown,
expected_status,
expected_file_fetched,
expected_file_served,
):
mocker.patch(
'app.models.service.Service.organisation_id',
new_callable=PropertyMock,
return_value=ORGANISATION_ID,
)
mocker.patch(
'app.models.organisation.organisations_client.get_organisation',
return_value=organisation_json(
@@ -196,13 +188,9 @@ def test_download_service_agreement(
def test_show_accept_agreement_page(
client_request,
mocker,
mock_get_service_organisation,
mock_get_organisation,
):
mocker.patch(
'app.models.service.Service.organisation_id',
new_callable=PropertyMock,
return_value=ORGANISATION_ID,
)
page = client_request.get('main.service_accept_agreement', service_id=SERVICE_ONE_ID)
assert [
@@ -258,13 +246,8 @@ def test_show_accept_agreement_page(
def test_accept_agreement_page_populates(
client_request,
mocker,
mock_get_organisation,
mock_get_service_organisation,
):
mocker.patch(
'app.models.service.Service.organisation_id',
new_callable=PropertyMock,
return_value=ORGANISATION_ID,
)
mocker.patch(
'app.models.organisation.organisations_client.get_organisation',
return_value=organisation_json(
@@ -349,15 +332,10 @@ def test_accept_agreement_page_populates(
def test_accept_agreement_page_validates(
mocker,
client_request,
mock_get_organisation,
mock_get_service_organisation,
data,
expected_errors,
):
mocker.patch(
'app.models.service.Service.organisation_id',
new_callable=PropertyMock,
return_value=ORGANISATION_ID,
)
page = client_request.post(
'main.service_accept_agreement',
service_id=SERVICE_ONE_ID,
@@ -419,16 +397,11 @@ def test_accept_agreement_page_validates(
def test_accept_agreement_page_persists(
mocker,
client_request,
mock_get_organisation,
mock_get_service_organisation,
mock_update_organisation,
data,
expected_persisted,
):
mocker.patch(
'app.models.service.Service.organisation_id',
new_callable=PropertyMock,
return_value=ORGANISATION_ID,
)
client_request.post(
'main.service_accept_agreement',
service_id=SERVICE_ONE_ID,
@@ -459,15 +432,11 @@ def test_accept_agreement_page_persists(
def test_show_confirm_agreement_page(
client_request,
mocker,
mock_get_service_organisation,
name,
email,
expected_paragraph,
):
mocker.patch(
'app.models.service.Service.organisation_id',
new_callable=PropertyMock,
return_value=ORGANISATION_ID,
)
mocker.patch(
'app.models.organisation.organisations_client.get_organisation',
return_value=organisation_json(
@@ -497,14 +466,10 @@ def test_confirm_agreement_page_403s_if_previous_step_not_taken(
def test_confirm_agreement_page_persists(
client_request,
mocker,
mock_get_service_organisation,
mock_update_organisation,
fake_uuid,
):
mocker.patch(
'app.models.service.Service.organisation_id',
new_callable=PropertyMock,
return_value=ORGANISATION_ID,
)
mocker.patch(
'app.models.organisation.organisations_client.get_organisation',
return_value=organisation_json(agreement_signed_version='1.2')
+9 -47
View File
@@ -890,7 +890,7 @@ def test_should_not_show_go_live_button_if_checklist_not_complete(
mocker,
mock_get_service_templates,
mock_get_users_by_service,
mock_get_organisation,
mock_get_service_organisation,
mock_get_invites_for_service,
single_sms_sender,
checklist_completed,
@@ -902,11 +902,6 @@ def test_should_not_show_go_live_button_if_checklist_not_complete(
new_callable=PropertyMock,
return_value=checklist_completed,
)
mocker.patch(
'app.models.service.Service.organisation_id',
new_callable=PropertyMock,
return_value=ORGANISATION_ID,
)
mocker.patch(
'app.models.organisation.Organisation.agreement_signed',
new_callable=PropertyMock,
@@ -1117,6 +1112,7 @@ def test_should_check_for_mou_on_request_to_go_live(
mocker,
agreement_signed,
mock_get_invites_for_service,
mock_get_service_organisation,
expected_item,
):
mocker.patch(
@@ -1144,11 +1140,6 @@ def test_should_check_for_mou_on_request_to_go_live(
return_value=None,
)
mocker.patch(
'app.models.service.Service.organisation_id',
new_callable=PropertyMock,
return_value=ORGANISATION_ID,
)
mocker.patch(
'app.organisations_client.get_organisation',
return_value=organisation_json(agreement_signed=agreement_signed)
@@ -1199,7 +1190,6 @@ def test_gp_without_organisation_is_shown_agreement_step(
new_callable=PropertyMock,
return_value=None,
)
mocker.patch(
'app.models.service.Service.organisation_id',
new_callable=PropertyMock,
@@ -1579,6 +1569,7 @@ def test_request_to_go_live_displays_go_live_notes_in_zendesk_ticket(
single_letter_contact_block,
mock_get_organisations_and_services_for_user,
single_sms_sender,
mock_get_service_organisation,
mock_get_service_settings_page_common,
mock_get_service_templates,
mock_get_users_by_service,
@@ -1587,11 +1578,6 @@ def test_request_to_go_live_displays_go_live_notes_in_zendesk_ticket(
):
go_live_note = 'This service is not allowed to go live'
mocker.patch(
'app.models.service.Service.organisation_id',
new_callable=PropertyMock,
return_value=ORGANISATION_ID,
)
mocker.patch(
'app.organisations_client.get_organisation',
side_effect=lambda org_id: organisation_json(
@@ -1808,6 +1794,7 @@ def test_should_be_able_to_request_to_go_live_with_no_organisation(
def test_ready_to_go_live(
client_request,
mocker,
mock_get_service_organisation,
has_team_members,
has_templates,
has_email_templates,
@@ -1822,11 +1809,6 @@ def test_ready_to_go_live(
agreement_signed,
expected_tags,
):
mocker.patch(
'app.models.service.Service.organisation_id',
new_callable=PropertyMock,
return_value=ORGANISATION_ID,
)
mocker.patch(
'app.organisations_client.get_organisation',
return_value=organisation_json(agreement_signed=agreement_signed)
@@ -4484,16 +4466,12 @@ def test_show_branding_request_page_when_no_branding_is_set_but_organisation_exi
client_request,
mock_get_email_branding,
mock_get_letter_branding_by_id,
mock_get_service_organisation,
organisation_type,
expected_options,
branding_type
):
service_one['{}_branding'.format(branding_type)] = None
mocker.patch(
'app.models.service.Service.organisation_id',
new_callable=PropertyMock,
return_value=ORGANISATION_ID,
)
mocker.patch(
'app.organisations_client.get_organisation',
return_value=organisation_json(organisation_type=organisation_type),
@@ -4532,16 +4510,12 @@ def test_show_branding_request_page_when_no_branding_is_set_but_organisation_exi
client_request,
mock_get_email_branding,
mock_get_letter_branding_by_id,
mock_get_service_organisation,
organisation_type,
expected_options,
branding_type
):
service_one['{}_branding'.format(branding_type)] = None
mocker.patch(
'app.models.service.Service.organisation_id',
new_callable=PropertyMock,
return_value=ORGANISATION_ID,
)
mocker.patch(
'app.organisations_client.get_organisation',
return_value=organisation_json(organisation_type=organisation_type),
@@ -4568,14 +4542,10 @@ def test_show_email_branding_request_page_when_email_branding_is_set(
service_one,
client_request,
mock_get_email_branding,
mock_get_service_organisation,
active_user_with_permissions,
):
service_one['email_branding'] = sample_uuid()
mocker.patch(
'app.models.service.Service.organisation_id',
new_callable=PropertyMock,
return_value=ORGANISATION_ID,
)
mocker.patch(
'app.organisations_client.get_organisation',
return_value=organisation_json(),
@@ -4603,14 +4573,10 @@ def test_show_letter_branding_request_page_when_letter_branding_is_set(
service_one,
client_request,
mock_get_letter_branding_by_id,
mock_get_service_organisation,
active_user_with_permissions,
):
service_one['letter_branding'] = sample_uuid()
mocker.patch(
'app.models.service.Service.organisation_id',
new_callable=PropertyMock,
return_value=ORGANISATION_ID,
)
mocker.patch(
'app.organisations_client.get_organisation',
return_value=organisation_json(),
@@ -4667,15 +4633,11 @@ def test_show_branding_request_page_when_branding_is_same_as_org(
client_request,
mock_get_email_branding,
mock_get_letter_branding_by_id,
mock_get_service_organisation,
active_user_with_permissions,
branding_type
):
service_one['{}_branding'.format(branding_type)] = sample_uuid()
mocker.patch(
'app.models.service.Service.organisation_id',
new_callable=PropertyMock,
return_value=ORGANISATION_ID,
)
if branding_type == 'email':
mocker.patch(
'app.organisations_client.get_organisation',