From 00cc67f8133f150cb6d5624c2eff6f1b29ca605c Mon Sep 17 00:00:00 2001 From: Ben Thorner Date: Mon, 15 Feb 2021 11:41:26 +0000 Subject: [PATCH] Inline duplicate service fixture with test Similarly to the previous commit, this fixture is only used once, so can benefit from being inline with its test. --- tests/app/main/views/test_add_service.py | 14 +++++++++++++- tests/conftest.py | 19 ------------------- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/tests/app/main/views/test_add_service.py b/tests/app/main/views/test_add_service.py index 5c4e24e25..11ef3dc0a 100644 --- a/tests/app/main/views/test_add_service.py +++ b/tests/app/main/views/test_add_service.py @@ -1,5 +1,6 @@ import pytest from flask import session, url_for +from notifications_python_client.errors import HTTPError from app.utils import is_gov_user from tests import organisation_json @@ -309,9 +310,20 @@ def test_add_service_fails_if_service_name_fails_validation( def test_should_return_form_errors_with_duplicate_service_name_regardless_of_case( client_request, - mock_create_duplicate_service, mock_get_organisation_by_domain, + mocker, ): + def _create(**_kwargs): + json_mock = mocker.Mock(return_value={'message': {'name': ["Duplicate service name"]}}) + resp_mock = mocker.Mock(status_code=400, json=json_mock) + http_error = HTTPError(response=resp_mock, message="Default message") + raise http_error + + mocker.patch( + 'app.service_api_client.create_service', + side_effect=_create + ) + page = client_request.post( 'main.add_service', _data={ diff --git a/tests/conftest.py b/tests/conftest.py index 98e2a551e..ae7fb8ab3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -587,25 +587,6 @@ def mock_create_service(mocker): 'app.service_api_client.create_service', side_effect=_create) -@pytest.fixture(scope='function') -def mock_create_duplicate_service(mocker): - def _create( - service_name, - organisation_type, - message_limit, - restricted, - user_id, - email_from, - ): - json_mock = Mock(return_value={'message': {'name': ["Duplicate service name '{}'".format(service_name)]}}) - resp_mock = Mock(status_code=400, json=json_mock) - http_error = HTTPError(response=resp_mock, message="Default message") - raise http_error - - return mocker.patch( - 'app.service_api_client.create_service', side_effect=_create) - - @pytest.fixture(scope='function') def mock_update_service(mocker): def _update(service_id, **kwargs):