mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-02 12:48:32 -04:00
When a service is created add the default annual billing for the service.
This will need to be merged before https://github.com/alphagov/notifications-admin/pull/3855, it will be that until the admin PR is merged the annual billing will be set twice, but that's not an issue.
This commit is contained in:
@@ -585,7 +585,7 @@ def test_post_link_service_to_organisation_missing_payload(
|
||||
def test_link_service_to_organisation_updates_service_if_annual_billing_update_fails(
|
||||
mocker, admin_request, sample_service, sample_organisation
|
||||
):
|
||||
mocker.patch('app.dao.annual_billing_dao.set_default_free_allowance_for_service', raises=SQLAlchemyError)
|
||||
mocker.patch('app.organisation.rest.set_default_free_allowance_for_service', raises=SQLAlchemyError)
|
||||
data = {
|
||||
'service_id': str(sample_service.id)
|
||||
}
|
||||
@@ -596,6 +596,7 @@ def test_link_service_to_organisation_updates_service_if_annual_billing_update_f
|
||||
_expected_status=204
|
||||
)
|
||||
assert sample_service.organisation_id == sample_organisation.id
|
||||
assert len(AnnualBilling.query.all()) == 0
|
||||
|
||||
|
||||
def test_rest_get_organisation_services(
|
||||
|
||||
@@ -6,6 +6,7 @@ from unittest.mock import ANY
|
||||
import pytest
|
||||
from flask import current_app, url_for
|
||||
from freezegun import freeze_time
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
|
||||
from app.dao.organisation_dao import dao_add_service_to_organisation
|
||||
from app.dao.service_sms_sender_dao import dao_get_sms_senders_by_service_id
|
||||
@@ -31,6 +32,7 @@ from app.models import (
|
||||
SERVICE_PERMISSION_TYPES,
|
||||
SMS_TYPE,
|
||||
UPLOAD_LETTERS,
|
||||
AnnualBilling,
|
||||
EmailBranding,
|
||||
InboundNumber,
|
||||
Notification,
|
||||
@@ -482,6 +484,46 @@ def test_create_service_with_domain_sets_organisation(
|
||||
assert json_resp['data']['organisation'] is None
|
||||
|
||||
|
||||
def test_create_service_should_create_annual_billing_for_service(
|
||||
admin_request, sample_user
|
||||
):
|
||||
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)
|
||||
}
|
||||
assert len(AnnualBilling.query.all()) == 0
|
||||
admin_request.post('service.create_service', _data=data, _expected_status=201)
|
||||
|
||||
annual_billing = AnnualBilling.query.all()
|
||||
assert len(annual_billing) == 1
|
||||
|
||||
|
||||
def test_create_service_should_create_service_if_annual_billing_query_fails(
|
||||
admin_request, sample_user, mocker
|
||||
):
|
||||
mocker.patch('app.service.rest.set_default_free_allowance_for_service', raises=SQLAlchemyError)
|
||||
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)
|
||||
}
|
||||
assert len(AnnualBilling.query.all()) == 0
|
||||
admin_request.post('service.create_service', _data=data, _expected_status=201)
|
||||
|
||||
annual_billing = AnnualBilling.query.all()
|
||||
assert len(annual_billing) == 0
|
||||
assert len(Service.query.filter(Service.name == 'created service').all()) == 1
|
||||
|
||||
|
||||
def test_create_service_inherits_branding_from_organisation(
|
||||
admin_request,
|
||||
sample_user,
|
||||
|
||||
Reference in New Issue
Block a user