diff --git a/app/__init__.py b/app/__init__.py index fb07f88ea..dbcd7f1a7 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -140,9 +140,6 @@ def register_blueprint(application): from app.inbound_number.rest import inbound_number_blueprint from app.inbound_sms.rest import inbound_sms as inbound_sms_blueprint from app.job.rest import job_blueprint - from app.letter_branding.letter_branding_rest import ( - letter_branding_blueprint, - ) from app.letters.rest import letter_job from app.notifications.notifications_ses_callback import ( ses_callback_blueprint, @@ -253,9 +250,6 @@ def register_blueprint(application): template_folder_blueprint.before_request(requires_admin_auth) application.register_blueprint(template_folder_blueprint) - letter_branding_blueprint.before_request(requires_admin_auth) - application.register_blueprint(letter_branding_blueprint) - upload_blueprint.before_request(requires_admin_auth) application.register_blueprint(upload_blueprint) diff --git a/app/commands.py b/app/commands.py index 0b182b504..b8fd51cc9 100644 --- a/app/commands.py +++ b/app/commands.py @@ -56,7 +56,6 @@ from app.models import ( AnnualBilling, Domain, EmailBranding, - LetterBranding, Notification, Organisation, Service, @@ -331,7 +330,6 @@ def populate_organisations_from_file(file_name): # [3] argeement_signed:: TRUE | FALSE # [4] domains:: comma separated list of domains related to the organisation # [5] email branding name: name of the default email branding for the org - # [6] letter branding name: name of the default letter branding for the org # The expectation is that the organisation, organisation_to_service # and user_to_organisation will be cleared before running this command. @@ -352,19 +350,13 @@ def populate_organisations_from_file(file_name): email_branding_column = columns[5].strip() if len(email_branding_column) > 0: email_branding = EmailBranding.query.filter(EmailBranding.name == email_branding_column).one() - letter_branding = None - letter_branding_column = columns[6].strip() - if len(letter_branding_column) > 0: - letter_branding = LetterBranding.query.filter(LetterBranding.name == letter_branding_column).one() data = { 'name': columns[0], 'active': True, 'agreement_signed': boolean_or_none(columns[3]), 'crown': boolean_or_none(columns[2]), 'organisation_type': columns[1].lower(), - 'email_branding_id': email_branding.id if email_branding else None, - 'letter_branding_id': letter_branding.id if letter_branding else None - + 'email_branding_id': email_branding.id if email_branding else None } org = Organisation(**data) try: diff --git a/app/dao/letter_branding_dao.py b/app/dao/letter_branding_dao.py deleted file mode 100644 index b07106596..000000000 --- a/app/dao/letter_branding_dao.py +++ /dev/null @@ -1,29 +0,0 @@ -from app import db -from app.dao.dao_utils import autocommit -from app.models import LetterBranding - - -def dao_get_letter_branding_by_id(letter_branding_id): - return LetterBranding.query.filter(LetterBranding.id == letter_branding_id).one() - - -def dao_get_letter_branding_by_name(letter_branding_name): - return LetterBranding.query.filter_by(name=letter_branding_name).first() - - -def dao_get_all_letter_branding(): - return LetterBranding.query.order_by(LetterBranding.name).all() - - -@autocommit -def dao_create_letter_branding(letter_branding): - db.session.add(letter_branding) - - -@autocommit -def dao_update_letter_branding(letter_branding_id, **kwargs): - letter_branding = LetterBranding.query.get(letter_branding_id) - for key, value in kwargs.items(): - setattr(letter_branding, key, value or None) - db.session.add(letter_branding) - return letter_branding diff --git a/app/dao/organisation_dao.py b/app/dao/organisation_dao.py index 198f1e30a..d489a8a54 100644 --- a/app/dao/organisation_dao.py +++ b/app/dao/organisation_dao.py @@ -89,9 +89,6 @@ def dao_update_organisation(organisation_id, **kwargs): if 'email_branding_id' in kwargs: _update_organisation_services(organisation, 'email_branding') - if 'letter_branding_id' in kwargs: - _update_organisation_services(organisation, 'letter_branding') - return num_updated diff --git a/app/dao/services_dao.py b/app/dao/services_dao.py index eda383edb..c45430344 100644 --- a/app/dao/services_dao.py +++ b/app/dao/services_dao.py @@ -315,9 +315,6 @@ def dao_create_service( if organisation.email_branding: service.email_branding = organisation.email_branding - if organisation.letter_branding: - service.letter_branding = organisation.letter_branding - if organisation: service.crown = organisation.crown service.count_as_live = not user.platform_admin diff --git a/app/job/rest.py b/app/job/rest.py index 36905bb8c..1dd1eabfb 100644 --- a/app/job/rest.py +++ b/app/job/rest.py @@ -9,8 +9,6 @@ from app.dao.fact_notification_status_dao import ( fetch_notification_statuses_for_job, ) from app.dao.jobs_dao import ( - can_letter_job_be_cancelled, - dao_cancel_letter_job, dao_create_job, dao_get_future_scheduled_job_by_id_and_service_id, dao_get_job_by_service_id_and_job_id, @@ -30,7 +28,6 @@ from app.models import ( JOB_STATUS_CANCELLED, JOB_STATUS_PENDING, JOB_STATUS_SCHEDULED, - LETTER_TYPE, ) from app.schemas import ( job_schema, @@ -66,15 +63,10 @@ def cancel_job(service_id, job_id): return get_job_by_service_and_job_id(service_id, job_id) -@job_blueprint.route('//cancel-letter-job', methods=['POST']) -def cancel_letter_job(service_id, job_id): - job = dao_get_job_by_service_id_and_job_id(service_id, job_id) - can_we_cancel, errors = can_letter_job_be_cancelled(job) - if can_we_cancel: - data = dao_cancel_letter_job(job) - return jsonify(data), 200 - else: - return jsonify(message=errors), 400 +# TODO: return deprecation notice +# @job_blueprint.route('//cancel-letter-job', methods=['POST']) +# def cancel_letter_job(service_id, job_id): +# pass @job_blueprint.route('//notifications', methods=['GET']) @@ -160,9 +152,6 @@ def create_job(service_id): data['template'] = data.pop('template_id') template = dao_get_template_by_id(data['template']) - if template.template_type == LETTER_TYPE and service.restricted: - raise InvalidRequest("Create letter job is not allowed for service in trial mode ", 403) - if data.get('valid') != 'True': raise InvalidRequest("File is not valid, can't create job", 400) diff --git a/app/letter_branding/__init__.py b/app/letter_branding/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/app/letter_branding/letter_branding_rest.py b/app/letter_branding/letter_branding_rest.py deleted file mode 100644 index d1f6fb0bb..000000000 --- a/app/letter_branding/letter_branding_rest.py +++ /dev/null @@ -1,71 +0,0 @@ -from celery import current_app -from flask import Blueprint, jsonify, request -from sqlalchemy.exc import IntegrityError - -from app.dao.letter_branding_dao import ( - dao_create_letter_branding, - dao_get_all_letter_branding, - dao_get_letter_branding_by_id, - dao_update_letter_branding, -) -from app.errors import register_errors -from app.letter_branding.letter_branding_schema import ( - post_letter_branding_schema, -) -from app.models import LetterBranding -from app.schema_validation import validate - -letter_branding_blueprint = Blueprint('letter_branding', __name__, url_prefix='/letter-branding') -register_errors(letter_branding_blueprint) - - -@letter_branding_blueprint.errorhandler(IntegrityError) -def handle_integrity_error(exc): - """ - Handle integrity errors caused by the unique constraint - """ - for col in {'name', 'filename'}: - if 'letter_branding_{}_key'.format(col) in str(exc): - return jsonify( - result='error', - message={col: ["{} already in use".format(col.title())]} - ), 400 - current_app.logger.exception(exc) - return jsonify(result='error', message="Internal server error"), 500 - - -@letter_branding_blueprint.route('', methods=['GET']) -def get_all_letter_brands(): - letter_brands = dao_get_all_letter_branding() - - return jsonify([lb.serialize() for lb in letter_brands]) - - -@letter_branding_blueprint.route('/', methods=['GET']) -def get_letter_brand_by_id(letter_branding_id): - letter_branding = dao_get_letter_branding_by_id(letter_branding_id) - - return jsonify(letter_branding.serialize()), 200 - - -@letter_branding_blueprint.route('', methods=['POST']) -def create_letter_brand(): - data = request.get_json() - - validate(data, post_letter_branding_schema) - - letter_branding = LetterBranding(**data) - dao_create_letter_branding(letter_branding) - - return jsonify(letter_branding.serialize()), 201 - - -@letter_branding_blueprint.route('/', methods=['POST']) -def update_letter_branding(letter_branding_id): - data = request.get_json() - - validate(data, post_letter_branding_schema) - - letter_branding = dao_update_letter_branding(letter_branding_id, **data) - - return jsonify(letter_branding.serialize()), 201 diff --git a/app/letter_branding/letter_branding_schema.py b/app/letter_branding/letter_branding_schema.py deleted file mode 100644 index 3c7acb7b0..000000000 --- a/app/letter_branding/letter_branding_schema.py +++ /dev/null @@ -1,10 +0,0 @@ -post_letter_branding_schema = { - "$schema": "http://json-schema.org/draft-07/schema#", - "description": "POST schema for creating or updating a letter brand", - "type": "object", - "properties": { - "name": {"type": ["string", "null"]}, - "filename": {"type": ["string", "null"]}, - }, - "required": ["name", "filename"] -} diff --git a/app/models.py b/app/models.py index 6633526ad..9e2d573cd 100644 --- a/app/models.py +++ b/app/models.py @@ -408,13 +408,6 @@ class Organisation(db.Model): nullable=True, ) - letter_branding = db.relationship('LetterBranding') - letter_branding_id = db.Column( - UUID(as_uuid=True), - db.ForeignKey('letter_branding.id'), - nullable=True, - ) - notes = db.Column(db.Text, nullable=True) purchase_order_number = db.Column(db.String(255), nullable=True) billing_contact_names = db.Column(db.Text, nullable=True) @@ -441,7 +434,6 @@ class Organisation(db.Model): "active": self.active, "crown": self.crown, "organisation_type": self.organisation_type, - "letter_branding_id": self.letter_branding_id, "email_branding_id": self.email_branding_id, "agreement_signed": self.agreement_signed, "agreement_signed_at": self.agreement_signed_at, @@ -527,11 +519,6 @@ class Service(db.Model, Versioned): secondary=service_email_branding, uselist=False, backref=db.backref('services', lazy='dynamic')) - letter_branding = db.relationship( - 'LetterBranding', - secondary=service_letter_branding, - uselist=False, - backref=db.backref('services', lazy='dynamic')) @classmethod def from_json(cls, data): diff --git a/app/service/rest.py b/app/service/rest.py index 93a02e52c..3f4b5515f 100644 --- a/app/service/rest.py +++ b/app/service/rest.py @@ -97,7 +97,6 @@ from app.models import ( KEY_TYPE_NORMAL, NOTIFICATION_CANCELLED, EmailBranding, - LetterBranding, Permission, Service, ServiceContactList, @@ -265,9 +264,6 @@ def update_service(service_id): if 'email_branding' in req_json: email_branding_id = req_json['email_branding'] service.email_branding = None if not email_branding_id else EmailBranding.query.get(email_branding_id) - if 'letter_branding' in req_json: - letter_branding_id = req_json['letter_branding'] - service.letter_branding = None if not letter_branding_id else LetterBranding.query.get(letter_branding_id) dao_update_service(service) if service_going_live: diff --git a/tests/app/dao/test_fact_notification_status_dao.py b/tests/app/dao/test_fact_notification_status_dao.py index 3b5205648..ea8f8b59d 100644 --- a/tests/app/dao/test_fact_notification_status_dao.py +++ b/tests/app/dao/test_fact_notification_status_dao.py @@ -459,14 +459,12 @@ def test_fetch_monthly_template_usage_for_service_does_join_to_notifications_if_ assert results[0].template_id == template_one.id assert results[0].name == template_one.name - assert results[0].is_precompiled_letter == template_one.is_precompiled_letter assert results[0].template_type == template_one.template_type assert results[0].month == 2 assert results[0].year == 2018 assert results[0].count == 20 assert results[1].template_id == template_two.id assert results[1].name == template_two.name - assert results[1].is_precompiled_letter == template_two.is_precompiled_letter assert results[1].template_type == template_two.template_type assert results[1].month == 2 assert results[1].year == 2018 diff --git a/tests/app/dao/test_letter_branding_dao.py b/tests/app/dao/test_letter_branding_dao.py deleted file mode 100644 index 6122f2dcc..000000000 --- a/tests/app/dao/test_letter_branding_dao.py +++ /dev/null @@ -1,65 +0,0 @@ -import uuid - -import pytest -from sqlalchemy.exc import SQLAlchemyError - -from app.dao.letter_branding_dao import ( - dao_create_letter_branding, - dao_get_all_letter_branding, - dao_get_letter_branding_by_id, - dao_update_letter_branding, -) -from app.models import LetterBranding -from tests.app.db import create_letter_branding - - -def test_dao_get_letter_branding_by_id(notify_db_session): - letter_branding = create_letter_branding() - result = dao_get_letter_branding_by_id(letter_branding.id) - - assert result == letter_branding - - -def test_dao_get_letter_brand_by_id_raises_exception_if_does_not_exist(notify_db_session): - with pytest.raises(expected_exception=SQLAlchemyError): - dao_get_letter_branding_by_id(uuid.uuid4()) - - -def test_dao_get_all_letter_branding(notify_db_session): - hm_gov = create_letter_branding() - test_branding = create_letter_branding( - name='test branding', filename='test-branding', - ) - - results = dao_get_all_letter_branding() - - assert hm_gov in results - assert test_branding in results - assert len(results) == 2 - - -def test_dao_get_all_letter_branding_returns_empty_list_if_no_brands_exist(notify_db_session): - assert dao_get_all_letter_branding() == [] - - -def test_dao_create_letter_branding(notify_db_session): - data = { - 'name': 'test-logo', - 'filename': 'test-logo' - } - assert LetterBranding.query.count() == 0 - dao_create_letter_branding(LetterBranding(**data)) - - assert LetterBranding.query.count() == 1 - - new_letter_branding = LetterBranding.query.first() - assert new_letter_branding.name == data['name'] - assert new_letter_branding.filename == data['name'] - - -def test_dao_update_letter_branding(notify_db_session): - create_letter_branding(name='original') - letter_branding = LetterBranding.query.first() - assert letter_branding.name == 'original' - dao_update_letter_branding(letter_branding.id, name='new name') - assert LetterBranding.query.first().name == 'new name' diff --git a/tests/app/dao/test_organisation_dao.py b/tests/app/dao/test_organisation_dao.py index 3b7dc8ca4..100778636 100644 --- a/tests/app/dao/test_organisation_dao.py +++ b/tests/app/dao/test_organisation_dao.py @@ -20,7 +20,6 @@ from app.models import Organisation, Service from tests.app.db import ( create_domain, create_email_branding, - create_letter_branding, create_organisation, create_service, create_user, @@ -60,7 +59,6 @@ def test_update_organisation(notify_db_session): organisation = Organisation.query.one() user = create_user() email_branding = create_email_branding() - letter_branding = create_letter_branding() data = { 'name': 'new name', @@ -70,7 +68,6 @@ def test_update_organisation(notify_db_session): "agreement_signed_at": datetime.datetime.utcnow(), "agreement_signed_by_id": user.id, "agreement_signed_version": 999.99, - "letter_branding_id": letter_branding.id, "email_branding_id": email_branding.id, } @@ -122,12 +119,10 @@ def test_update_organisation_does_not_update_the_service_if_certain_attributes_n sample_organisation, ): email_branding = create_email_branding() - letter_branding = create_letter_branding() sample_service.organisation_type = 'state' sample_organisation.organisation_type = 'federal' sample_organisation.email_branding = email_branding - sample_organisation.letter_branding = letter_branding sample_organisation.services.append(sample_service) db.session.commit() @@ -144,9 +139,6 @@ def test_update_organisation_does_not_update_the_service_if_certain_attributes_n assert sample_organisation.email_branding == email_branding assert sample_service.email_branding is None - assert sample_organisation.letter_branding == letter_branding - assert sample_service.letter_branding is None - def test_update_organisation_updates_the_service_org_type_if_org_type_is_provided( sample_service, @@ -173,18 +165,14 @@ def test_update_organisation_updates_the_service_branding_if_branding_is_provide sample_organisation, ): email_branding = create_email_branding() - letter_branding = create_letter_branding() sample_organisation.services.append(sample_service) db.session.commit() dao_update_organisation(sample_organisation.id, email_branding_id=email_branding.id) - dao_update_organisation(sample_organisation.id, letter_branding_id=letter_branding.id) assert sample_organisation.email_branding == email_branding - assert sample_organisation.letter_branding == letter_branding assert sample_service.email_branding == email_branding - assert sample_service.letter_branding == letter_branding def test_update_organisation_does_not_override_service_branding( @@ -193,22 +181,16 @@ def test_update_organisation_does_not_override_service_branding( ): email_branding = create_email_branding() custom_email_branding = create_email_branding(name='custom') - letter_branding = create_letter_branding() - custom_letter_branding = create_letter_branding(name='custom', filename='custom') sample_service.email_branding = custom_email_branding - sample_service.letter_branding = custom_letter_branding sample_organisation.services.append(sample_service) db.session.commit() dao_update_organisation(sample_organisation.id, email_branding_id=email_branding.id) - dao_update_organisation(sample_organisation.id, letter_branding_id=letter_branding.id) assert sample_organisation.email_branding == email_branding - assert sample_organisation.letter_branding == letter_branding assert sample_service.email_branding == custom_email_branding - assert sample_service.letter_branding == custom_letter_branding def test_update_organisation_updates_services_with_new_crown_type( diff --git a/tests/app/dao/test_services_dao.py b/tests/app/dao/test_services_dao.py index afc5dfc38..87e11840a 100644 --- a/tests/app/dao/test_services_dao.py +++ b/tests/app/dao/test_services_dao.py @@ -73,11 +73,9 @@ from app.models import ( from tests.app.db import ( create_annual_billing, create_api_key, - create_email_branding, create_ft_billing, create_inbound_number, create_invited_user, - create_letter_branding, create_notification, create_notification_history, create_organisation, @@ -92,7 +90,6 @@ from tests.app.db import ( def test_create_service(notify_db_session): user = create_user() - create_letter_branding() assert Service.query.count() == 0 service = Service(name="service_name", email_from="email_from", @@ -112,7 +109,6 @@ def test_create_service(notify_db_session): assert user in service_db.users assert service_db.organisation_type == 'federal' assert service_db.crown is None - assert not service.letter_branding assert not service.organisation_id @@ -140,59 +136,10 @@ def test_create_service_with_organisation(notify_db_session): assert user in service_db.users assert service_db.organisation_type == 'state' assert service_db.crown is None - assert not service.letter_branding assert service.organisation_id == organisation.id assert service.organisation == organisation -@pytest.mark.parametrize('email_address, organisation_type', ( - ("test@example.gov.uk", 'nhs_central'), - ("test@example.gov.uk", 'nhs_local'), - ("test@example.gov.uk", 'nhs_gp'), - ("test@nhs.net", 'nhs_local'), - ("test@nhs.net", 'local'), - ("test@nhs.net", 'central'), - ("test@nhs.uk", 'central'), - ("test@example.nhs.uk", 'central'), - ("TEST@NHS.UK", 'central'), -)) -@pytest.mark.parametrize('branding_name_to_create, expected_branding', ( - ('NHS', True), - # Need to check that nothing breaks in environments that don’t have - # the NHS branding set up - ('SHN', False), -)) -@pytest.mark.skip(reason='Update for TTS') -def test_create_nhs_service_get_default_branding_based_on_email_address( - notify_db_session, - branding_name_to_create, - expected_branding, - email_address, - organisation_type, -): - user = create_user(email=email_address) - letter_branding = create_letter_branding(name=branding_name_to_create) - email_branding = create_email_branding(name=branding_name_to_create) - - service = Service( - name="service_name", - email_from="email_from", - message_limit=1000, - restricted=False, - organisation_type=organisation_type, - created_by=user, - ) - dao_create_service(service, user) - service_db = Service.query.one() - - if expected_branding: - assert service_db.letter_branding == letter_branding - assert service_db.email_branding == email_branding - else: - assert service_db.letter_branding is None - assert service_db.email_branding is None - - def test_cannot_create_two_services_with_same_name(notify_db_session): user = create_user() assert Service.query.count() == 0 @@ -577,7 +524,6 @@ def test_create_service_by_id_adding_and_removing_letter_returns_service_without def test_create_service_creates_a_history_record_with_current_data(notify_db_session): user = create_user() - create_letter_branding() assert Service.query.count() == 0 assert Service.get_history_model().query.count() == 0 service = Service(name="service_name", diff --git a/tests/app/db.py b/tests/app/db.py index edcfd6cd7..02207edb9 100644 --- a/tests/app/db.py +++ b/tests/app/db.py @@ -46,7 +46,6 @@ from app.models import ( InvitedOrganisationUser, InvitedUser, Job, - LetterBranding, LetterRate, Notification, NotificationHistory, @@ -931,15 +930,6 @@ def create_template_folder(service, name='foo', parent=None): return tf -def create_letter_branding(name='HM Government', filename='hm-government'): - test_domain_branding = LetterBranding(name=name, - filename=filename, - ) - db.session.add(test_domain_branding) - db.session.commit() - return test_domain_branding - - def set_up_usage_data(start_date): year = int(start_date.strftime('%Y')) one_week_earlier = start_date - timedelta(days=7) diff --git a/tests/app/job/test_rest.py b/tests/app/job/test_rest.py index 5d4e6e075..0b7041ef0 100644 --- a/tests/app/job/test_rest.py +++ b/tests/app/job/test_rest.py @@ -78,59 +78,6 @@ def test_cant_cancel_normal_job(client, sample_job, mocker): assert mock_update.call_count == 0 -@freeze_time('2019-06-13 13:00') -def test_cancel_letter_job_updates_notifications_and_job_to_cancelled(sample_letter_template, admin_request, mocker): - job = create_job(template=sample_letter_template, notification_count=1, job_status='finished') - create_notification(template=job.template, job=job, status='created') - - mock_get_job = mocker.patch('app.job.rest.dao_get_job_by_service_id_and_job_id', return_value=job) - mock_can_letter_job_be_cancelled = mocker.patch( - 'app.job.rest.can_letter_job_be_cancelled', return_value=(True, None) - ) - mock_dao_cancel_letter_job = mocker.patch('app.job.rest.dao_cancel_letter_job', return_value=1) - - response = admin_request.post( - 'job.cancel_letter_job', - service_id=job.service_id, - job_id=job.id, - ) - - mock_get_job.assert_called_once_with(job.service_id, str(job.id)) - mock_can_letter_job_be_cancelled.assert_called_once_with(job) - mock_dao_cancel_letter_job.assert_called_once_with(job) - - assert response == 1 - - -@freeze_time('2019-06-13 13:00') -def test_cancel_letter_job_does_not_call_cancel_if_can_letter_job_be_cancelled_returns_False( - sample_letter_template, admin_request, mocker -): - job = create_job(template=sample_letter_template, notification_count=2, job_status='finished') - create_notification(template=job.template, job=job, status='sending') - create_notification(template=job.template, job=job, status='created') - - mock_get_job = mocker.patch('app.job.rest.dao_get_job_by_service_id_and_job_id', return_value=job) - error_message = "Sorry, it's too late, letters have already been sent." - mock_can_letter_job_be_cancelled = mocker.patch( - 'app.job.rest.can_letter_job_be_cancelled', return_value=(False, error_message) - ) - mock_dao_cancel_letter_job = mocker.patch('app.job.rest.dao_cancel_letter_job') - - response = admin_request.post( - 'job.cancel_letter_job', - service_id=job.service_id, - job_id=job.id, - _expected_status=400 - ) - - mock_get_job.assert_called_once_with(job.service_id, str(job.id)) - mock_can_letter_job_be_cancelled.assert_called_once_with(job) - mock_dao_cancel_letter_job.assert_not_called - - assert response["message"] == "Sorry, it's too late, letters have already been sent." - - def test_create_unscheduled_job(client, sample_template, mocker, fake_uuid): mocker.patch('app.celery.tasks.process_job.apply_async') mocker.patch('app.job.rest.get_job_metadata_from_s3', return_value={ @@ -321,31 +268,6 @@ def test_create_job_returns_400_if_file_is_invalid( mock_job_dao.assert_not_called() -def test_create_job_returns_403_if_letter_template_type_and_service_in_trial( - client, fake_uuid, sample_trial_letter_template, mocker -): - mocker.patch('app.job.rest.get_job_metadata_from_s3', return_value={ - 'template_id': str(sample_trial_letter_template.id), - 'original_file_name': 'thisisatest.csv', - 'notification_count': '1', - }) - data = { - 'id': fake_uuid, - 'created_by': str(sample_trial_letter_template.created_by.id), - } - mock_job_dao = mocker.patch("app.dao.jobs_dao.dao_create_job") - auth_header = create_admin_authorization_header() - response = client.post('/service/{}/job'.format(sample_trial_letter_template.service.id), - data=json.dumps(data), - headers=[('Content-Type', 'application/json'), auth_header]) - - assert response.status_code == 403 - resp_json = json.loads(response.get_data(as_text=True)) - assert resp_json['result'] == 'error' - assert resp_json['message'] == "Create letter job is not allowed for service in trial mode " - mock_job_dao.assert_not_called() - - @freeze_time("2016-01-01 11:09:00.061258") def test_should_not_create_scheduled_job_more_then_96_hours_in_the_future(client, sample_template, mocker, fake_uuid): scheduled_date = (datetime.utcnow() + timedelta(hours=96, minutes=1)).isoformat() diff --git a/tests/app/letter_branding/__init__.py b/tests/app/letter_branding/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/app/letter_branding/test_letter_branding_rest.py b/tests/app/letter_branding/test_letter_branding_rest.py deleted file mode 100644 index 2b957aa85..000000000 --- a/tests/app/letter_branding/test_letter_branding_rest.py +++ /dev/null @@ -1,80 +0,0 @@ -import json -import uuid - -from app.models import LetterBranding -from tests import create_admin_authorization_header -from tests.app.db import create_letter_branding - - -def test_get_all_letter_brands(client, notify_db_session): - hm_gov = create_letter_branding() - test_branding = create_letter_branding( - name='test branding', filename='test-branding', - ) - response = client.get('/letter-branding', headers=[create_admin_authorization_header()]) - assert response.status_code == 200 - json_response = json.loads(response.get_data(as_text=True)) - assert len(json_response) == 2 - for brand in json_response: - if brand['id'] == str(hm_gov.id): - assert hm_gov.serialize() == brand - elif brand['id'] == str(test_branding.id): - assert test_branding.serialize() == brand - else: - raise AssertionError() - - -def test_get_letter_branding_by_id(client, notify_db_session): - hm_gov = create_letter_branding() - create_letter_branding( - name='test domain', filename='test-domain' - ) - response = client.get('/letter-branding/{}'.format(hm_gov.id), headers=[create_admin_authorization_header()]) - - assert response.status_code == 200 - assert json.loads(response.get_data(as_text=True)) == hm_gov.serialize() - - -def test_get_letter_branding_by_id_returns_404_if_does_not_exist(client, notify_db_session): - response = client.get('/letter-branding/{}'.format(uuid.uuid4()), headers=[create_admin_authorization_header()]) - assert response.status_code == 404 - - -def test_create_letter_branding(client, notify_db_session): - form = { - 'name': 'super brand', - 'filename': 'super-brand' - } - - response = client.post( - '/letter-branding', - data=json.dumps(form), - headers=[('Content-Type', 'application/json'), create_admin_authorization_header()], - ) - - assert response.status_code == 201 - json_response = json.loads(response.get_data(as_text=True)) - letter_brand = LetterBranding.query.get(json_response['id']) - assert letter_brand.name == form['name'] - assert letter_brand.filename == form['filename'] - - -def test_update_letter_branding_returns_400_when_integrity_error_is_thrown( - client, notify_db_session -): - create_letter_branding(name='duplicate', filename='duplicate') - brand_to_update = create_letter_branding(name='super brand', filename='super brand') - form = { - 'name': 'duplicate', - 'filename': 'super-brand', - } - - response = client.post( - '/letter-branding/{}'.format(brand_to_update.id), - headers=[('Content-Type', 'application/json'), create_admin_authorization_header()], - data=json.dumps(form) - ) - - assert response.status_code == 400 - json_resp = json.loads(response.get_data(as_text=True)) - assert json_resp['message'] == {"name": ["Name already in use"]} diff --git a/tests/app/organisation/test_rest.py b/tests/app/organisation/test_rest.py index dd7f24e0a..fa6b20c43 100644 --- a/tests/app/organisation/test_rest.py +++ b/tests/app/organisation/test_rest.py @@ -17,7 +17,6 @@ from tests.app.db import ( create_domain, create_email_branding, create_ft_billing, - create_letter_branding, create_organisation, create_service, create_template, @@ -76,7 +75,6 @@ def test_get_organisation_by_id(admin_request, notify_db_session): 'agreement_signed_version', 'agreement_signed_on_behalf_of_name', 'agreement_signed_on_behalf_of_email_address', - 'letter_branding_id', 'email_branding_id', 'domains', 'request_to_go_live_notes', @@ -95,7 +93,6 @@ def test_get_organisation_by_id(admin_request, notify_db_session): assert response['agreement_signed'] is None assert response['agreement_signed_by_id'] is None assert response['agreement_signed_version'] is None - assert response['letter_branding_id'] is None assert response['email_branding_id'] is None assert response['domains'] == [] assert response['request_to_go_live_notes'] is None @@ -439,23 +436,19 @@ def test_update_organisation_default_branding( org = create_organisation(name='Test Organisation') email_branding = create_email_branding() - letter_branding = create_letter_branding() assert org.email_branding is None - assert org.letter_branding is None admin_request.post( 'organisation.update_organisation', _data={ 'email_branding_id': str(email_branding.id), - 'letter_branding_id': str(letter_branding.id), }, organisation_id=org.id, _expected_status=204 ) assert org.email_branding == email_branding - assert org.letter_branding == letter_branding def test_post_update_organisation_raises_400_on_existing_org_name( diff --git a/tests/app/service/test_rest.py b/tests/app/service/test_rest.py index 11819e8dd..cccf88b13 100644 --- a/tests/app/service/test_rest.py +++ b/tests/app/service/test_rest.py @@ -52,7 +52,6 @@ from tests.app.db import ( create_ft_notification_status, create_inbound_number, create_job, - create_letter_branding, create_letter_contact, create_notification, create_notification_history, @@ -263,7 +262,6 @@ def test_get_service_by_id(admin_request, sample_service): 'go_live_user', 'id', 'inbound_api', - 'letter_branding', 'message_limit', 'name', 'notes', @@ -391,7 +389,6 @@ def test_create_service( assert json_resp['data']['name'] == 'created service' assert json_resp['data']['email_from'] == 'created.service' assert not json_resp['data']['research_mode'] - assert json_resp['data']['letter_branding'] is None assert json_resp['data']['count_as_live'] is expected_count_as_live service_db = Service.query.get(json_resp['data']['id']) @@ -507,8 +504,6 @@ def test_create_service_inherits_branding_from_organisation( org = create_organisation() email_branding = create_email_branding() org.email_branding = email_branding - letter_branding = create_letter_branding() - org.letter_branding = letter_branding create_domain('example.gov.uk', org.id) sample_user.email_address = 'test@example.gov.uk' @@ -527,7 +522,6 @@ def test_create_service_inherits_branding_from_organisation( ) assert json_resp['data']['email_branding'] == str(email_branding.id) - assert json_resp['data']['letter_branding'] == str(letter_branding.id) def test_should_not_create_service_with_missing_user_id_field(notify_api, fake_uuid): @@ -722,53 +716,6 @@ def test_cant_update_service_org_type_to_random_value(client, sample_service): assert resp.status_code == 500 -def test_update_service_letter_branding(client, notify_db_session, sample_service): - letter_branding = create_letter_branding(name='test brand', filename='test-brand') - data = { - 'letter_branding': str(letter_branding.id) - } - - auth_header = create_admin_authorization_header() - - resp = client.post( - '/service/{}'.format(sample_service.id), - data=json.dumps(data), - headers=[('Content-Type', 'application/json'), auth_header] - ) - result = resp.json - assert resp.status_code == 200 - assert result['data']['letter_branding'] == str(letter_branding.id) - - -def test_update_service_remove_letter_branding(client, notify_db_session, sample_service): - letter_branding = create_letter_branding(name='test brand', filename='test-brand') - sample_service - data = { - 'letter_branding': str(letter_branding.id) - } - - auth_header = create_admin_authorization_header() - - client.post( - '/service/{}'.format(sample_service.id), - data=json.dumps(data), - headers=[('Content-Type', 'application/json'), auth_header] - ) - - data = { - 'letter_branding': None - } - resp = client.post( - '/service/{}'.format(sample_service.id), - data=json.dumps(data), - headers=[('Content-Type', 'application/json'), auth_header] - ) - - result = resp.json - assert resp.status_code == 200 - assert result['data']['letter_branding'] is None - - def test_update_service_remove_email_branding(admin_request, notify_db_session, sample_service): brand = EmailBranding(colour='#000000', logo='justice-league.png', name='Justice League') sample_service.email_branding = brand diff --git a/tests/app/test_model.py b/tests/app/test_model.py index 8e42900d0..13d3ac5d9 100644 --- a/tests/app/test_model.py +++ b/tests/app/test_model.py @@ -15,7 +15,6 @@ from app.models import ( NOTIFICATION_STATUS_LETTER_RECEIVED, NOTIFICATION_STATUS_TYPES_FAILED, NOTIFICATION_TECHNICAL_FAILURE, - PRECOMPILED_TEMPLATE_NAME, SMS_TYPE, Notification, ServiceGuestList, @@ -316,26 +315,6 @@ def test_letter_notification_postcode_can_be_null_for_precompiled_letters(client assert json['postcode'] is None -def test_is_precompiled_letter_false(sample_letter_template): - assert not sample_letter_template.is_precompiled_letter - - -def test_is_precompiled_letter_true(sample_letter_template): - sample_letter_template.hidden = True - sample_letter_template.name = PRECOMPILED_TEMPLATE_NAME - assert sample_letter_template.is_precompiled_letter - - -def test_is_precompiled_letter_hidden_true_not_name(sample_letter_template): - sample_letter_template.hidden = True - assert not sample_letter_template.is_precompiled_letter - - -def test_is_precompiled_letter_name_correct_not_hidden(sample_letter_template): - sample_letter_template.name = PRECOMPILED_TEMPLATE_NAME - assert not sample_letter_template.is_precompiled_letter - - def test_template_folder_is_parent(sample_service): x = None folders = []