diff --git a/app/main/views/add_service.py b/app/main/views/add_service.py index 6e816a409..d91b18dc9 100644 --- a/app/main/views/add_service.py +++ b/app/main/views/add_service.py @@ -20,7 +20,8 @@ from app.notify_client.models import InvitedUser from app import ( invite_api_client, user_api_client, - service_api_client + service_api_client, + billing_api_client ) from app.utils import ( @@ -46,15 +47,13 @@ def _create_service(service_name, organisation_type, email_from, form): service_name=service_name, organisation_type=organisation_type, message_limit=current_app.config['DEFAULT_SERVICE_LIMIT'], - free_sms_fragment_limit=free_sms_fragment_limit, restricted=True, user_id=session['user_id'], email_from=email_from, ) session['service_id'] = service_id - # TODO: Comment out until data migration - # billing_api_client.create_or_update_free_sms_fragment_limit(service_id, free_sms_fragment_limit) + billing_api_client.create_or_update_free_sms_fragment_limit(service_id, free_sms_fragment_limit) return service_id, None except HTTPError as e: diff --git a/app/main/views/service_settings.py b/app/main/views/service_settings.py index f46d068f6..80bb9d4e9 100644 --- a/app/main/views/service_settings.py +++ b/app/main/views/service_settings.py @@ -732,14 +732,7 @@ def set_free_sms_allowance(service_id): form = FreeSMSAllowance(free_sms_allowance=billing_api_client.get_free_sms_fragment_limit_for_year(service_id)) if form.validate_on_submit(): - service_api_client.update_service( - service_id, - # TODO: Retire this eventually after using annual_billing - free_sms_fragment_limit=form.free_sms_allowance.data, - ) - - # TODO: Comment out until data migration - # billing_api_client.create_or_update_free_sms_fragment_limit(service_id, form.free_sms_allowance.data) + billing_api_client.create_or_update_free_sms_fragment_limit(service_id, form.free_sms_allowance.data) return redirect(url_for('.service_settings', service_id=service_id)) diff --git a/tests/app/main/views/test_add_service.py b/tests/app/main/views/test_add_service.py index 0d4ead910..86c7fa0e6 100644 --- a/tests/app/main/views/test_add_service.py +++ b/tests/app/main/views/test_add_service.py @@ -45,7 +45,6 @@ def test_should_add_service_and_redirect_to_tour_when_no_services( 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' @@ -68,6 +67,7 @@ def test_should_add_service_and_redirect_to_tour_when_no_services( template_id="Example%20text%20message%20template", _external=True ) + mock_create_or_update_free_sms_fragment_limit.assert_called_once_with(101, 25000) @pytest.mark.parametrize('organisation_type, free_allowance', [ @@ -98,11 +98,11 @@ def test_should_add_service_and_redirect_to_dashboard_when_existing_service( 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' ) + 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 session['service_id'] == 101 assert response.status_code == 302 diff --git a/tests/app/main/views/test_dashboard.py b/tests/app/main/views/test_dashboard.py index 995cb201c..c9b7add23 100644 --- a/tests/app/main/views/test_dashboard.py +++ b/tests/app/main/views/test_dashboard.py @@ -631,7 +631,7 @@ def test_usage_page_with_year_argument( mock_get_usage, mock_get_billable_units, mock_get_free_sms_fragment_limit, - mock_create_or_update_free_sms_fragment_limit + # mock_create_or_update_free_sms_fragment_limit ): assert logged_in_client.get(url_for('main.usage', service_id=SERVICE_ONE_ID, year=2000)).status_code == 200 mock_get_billable_units.assert_called_once_with(SERVICE_ONE_ID, 2000) diff --git a/tests/app/main/views/test_service_settings.py b/tests/app/main/views/test_service_settings.py index b21f766aa..9f79cfb8d 100644 --- a/tests/app/main/views/test_service_settings.py +++ b/tests/app/main/views/test_service_settings.py @@ -1596,7 +1596,6 @@ def test_should_show_page_to_set_sms_allowance( ]) def test_should_set_sms_allowance( logged_in_platform_admin_client, - mock_update_service, given_allowance, expected_api_argument, mock_get_free_sms_fragment_limit, @@ -1615,15 +1614,10 @@ def test_should_set_sms_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( + mock_create_or_update_free_sms_fragment_limit.assert_called_with( SERVICE_ONE_ID, - free_sms_fragment_limit=expected_api_argument, + expected_api_argument ) - # Not assert until using the annual_billing end points - # mock_create_or_update_free_sms_fragment_limit.assert_called_with( - # SERVICE_ONE_ID, - # expected_api_argument - # ) def test_switch_service_enable_letters( diff --git a/tests/conftest.py b/tests/conftest.py index f2ed5f89b..004e87052 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -634,7 +634,6 @@ def mock_create_service(mocker): service_name, organisation_type, message_limit, - free_sms_fragment_limit, restricted, user_id, email_from, @@ -653,7 +652,6 @@ def mock_create_duplicate_service(mocker): service_name, organisation_type, message_limit, - free_sms_fragment_limit, restricted, user_id, email_from,