mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-19 14:08:47 -04:00
Merge branch 'main' into notify-300b
This commit is contained in:
@@ -13,7 +13,7 @@ from app.dao.api_key_dao import save_model_api_key
|
||||
from app.dao.invited_user_dao import save_invited_user
|
||||
from app.dao.jobs_dao import dao_create_job
|
||||
from app.dao.notifications_dao import dao_create_notification
|
||||
from app.dao.organisation_dao import dao_create_organisation
|
||||
from app.dao.organization_dao import dao_create_organization
|
||||
from app.dao.services_dao import dao_add_user_to_service, dao_create_service
|
||||
from app.dao.templates_dao import dao_create_template
|
||||
from app.dao.users_dao import create_secret_code, create_user_code
|
||||
@@ -31,7 +31,7 @@ from app.models import (
|
||||
Job,
|
||||
Notification,
|
||||
NotificationHistory,
|
||||
Organisation,
|
||||
Organization,
|
||||
Permission,
|
||||
ProviderDetails,
|
||||
ProviderDetailsHistory,
|
||||
@@ -94,7 +94,9 @@ def create_sample_notification(
|
||||
|
||||
if job is None and api_key is None:
|
||||
# we didn't specify in test - lets create it
|
||||
api_key = ApiKey.query.filter(ApiKey.service == template.service, ApiKey.key_type == key_type).first()
|
||||
api_key = ApiKey.query.filter(
|
||||
ApiKey.service == template.service, ApiKey.key_type == key_type
|
||||
).first()
|
||||
if not api_key:
|
||||
api_key = create_api_key(template.service, key_type=key_type)
|
||||
|
||||
@@ -126,7 +128,9 @@ def create_sample_notification(
|
||||
"api_key_id": api_key and api_key.id,
|
||||
"key_type": api_key.key_type if api_key else key_type,
|
||||
"sent_by": sent_by,
|
||||
"updated_at": created_at if status in NOTIFICATION_STATUS_TYPES_COMPLETED else None,
|
||||
"updated_at": created_at
|
||||
if status in NOTIFICATION_STATUS_TYPES_COMPLETED
|
||||
else None,
|
||||
"client_reference": client_reference,
|
||||
"rate_multiplier": rate_multiplier,
|
||||
"normalised_to": normalised_to,
|
||||
@@ -139,7 +143,7 @@ def create_sample_notification(
|
||||
return notification
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def service_factory(sample_user):
|
||||
class ServiceFactory(object):
|
||||
def get(self, service_name, user=None, template_type=None, email_from=None):
|
||||
@@ -155,7 +159,7 @@ def service_factory(sample_user):
|
||||
user=user,
|
||||
check_if_service_exists=True,
|
||||
)
|
||||
if template_type == 'email':
|
||||
if template_type == "email":
|
||||
create_template(
|
||||
service,
|
||||
template_name="Template Name",
|
||||
@@ -166,25 +170,23 @@ def service_factory(sample_user):
|
||||
create_template(
|
||||
service,
|
||||
template_name="Template Name",
|
||||
template_type='sms',
|
||||
template_type="sms",
|
||||
)
|
||||
return service
|
||||
|
||||
return ServiceFactory()
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def sample_user(notify_db_session):
|
||||
return create_user(
|
||||
email='notify@digital.cabinet-office.gov.uk'
|
||||
)
|
||||
return create_user(email="notify@digital.fake.gov")
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def notify_user(notify_db_session):
|
||||
return create_user(
|
||||
email="notify-service-user@digital.cabinet-office.gov.uk",
|
||||
id_=current_app.config['NOTIFY_USER_ID']
|
||||
email="notify-service-user@digital.fake.gov",
|
||||
id_=current_app.config["NOTIFY_USER_ID"],
|
||||
)
|
||||
|
||||
|
||||
@@ -194,25 +196,25 @@ def create_code(notify_db_session, code_type):
|
||||
return create_user_code(usr, code, code_type), code
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def sample_sms_code(notify_db_session):
|
||||
code, txt_code = create_code(notify_db_session, code_type="sms")
|
||||
code.txt_code = txt_code
|
||||
return code
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def sample_service(sample_user):
|
||||
service_name = 'Sample service'
|
||||
email_from = service_name.lower().replace(' ', '.')
|
||||
service_name = "Sample service"
|
||||
email_from = service_name.lower().replace(" ", ".")
|
||||
|
||||
data = {
|
||||
'name': service_name,
|
||||
'message_limit': 1000,
|
||||
'total_message_limit': 250000,
|
||||
'restricted': False,
|
||||
'email_from': email_from,
|
||||
'created_by': sample_user
|
||||
"name": service_name,
|
||||
"message_limit": 1000,
|
||||
"total_message_limit": 250000,
|
||||
"restricted": False,
|
||||
"email_from": email_from,
|
||||
"created_by": sample_user,
|
||||
}
|
||||
service = Service.query.filter_by(name=service_name).first()
|
||||
if not service:
|
||||
@@ -225,30 +227,32 @@ def sample_service(sample_user):
|
||||
return service
|
||||
|
||||
|
||||
@pytest.fixture(scope='function', name='sample_service_full_permissions')
|
||||
@pytest.fixture(scope="function", name="sample_service_full_permissions")
|
||||
def _sample_service_full_permissions(notify_db_session):
|
||||
service = create_service(
|
||||
service_name="sample service full permissions",
|
||||
service_permissions=set(SERVICE_PERMISSION_TYPES),
|
||||
check_if_service_exists=True,
|
||||
)
|
||||
create_inbound_number('12345', service_id=service.id)
|
||||
create_inbound_number("12345", service_id=service.id)
|
||||
return service
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def sample_template(sample_user):
|
||||
service = create_service(service_permissions=[EMAIL_TYPE, SMS_TYPE], check_if_service_exists=True)
|
||||
service = create_service(
|
||||
service_permissions=[EMAIL_TYPE, SMS_TYPE], check_if_service_exists=True
|
||||
)
|
||||
|
||||
data = {
|
||||
'name': 'Template Name',
|
||||
'template_type': 'sms',
|
||||
'content': 'This is a template:\nwith a newline',
|
||||
'service': service,
|
||||
'created_by': sample_user,
|
||||
'archived': False,
|
||||
'hidden': False,
|
||||
'process_type': 'normal'
|
||||
"name": "Template Name",
|
||||
"template_type": "sms",
|
||||
"content": "This is a template:\nwith a newline",
|
||||
"service": service,
|
||||
"created_by": sample_user,
|
||||
"archived": False,
|
||||
"hidden": False,
|
||||
"process_type": "normal",
|
||||
}
|
||||
template = Template(**data)
|
||||
dao_create_template(template)
|
||||
@@ -256,47 +260,59 @@ def sample_template(sample_user):
|
||||
return template
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def sample_template_without_sms_permission(notify_db_session):
|
||||
service = create_service(service_permissions=[EMAIL_TYPE], check_if_service_exists=True)
|
||||
service = create_service(
|
||||
service_permissions=[EMAIL_TYPE], check_if_service_exists=True
|
||||
)
|
||||
return create_template(service, template_type=SMS_TYPE)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def sample_template_with_placeholders(sample_service):
|
||||
# deliberate space and title case in placeholder
|
||||
return create_template(sample_service, content="Hello (( Name))\nYour thing is due soon")
|
||||
return create_template(
|
||||
sample_service, content="Hello (( Name))\nYour thing is due soon"
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def sample_sms_template_with_html(sample_service):
|
||||
# deliberate space and title case in placeholder
|
||||
return create_template(sample_service, content="Hello (( Name))\nHere is <em>some HTML</em> & entities")
|
||||
return create_template(
|
||||
sample_service, content="Hello (( Name))\nHere is <em>some HTML</em> & entities"
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def sample_email_template(sample_user):
|
||||
service = create_service(user=sample_user, service_permissions=[EMAIL_TYPE, SMS_TYPE], check_if_service_exists=True)
|
||||
service = create_service(
|
||||
user=sample_user,
|
||||
service_permissions=[EMAIL_TYPE, SMS_TYPE],
|
||||
check_if_service_exists=True,
|
||||
)
|
||||
data = {
|
||||
'name': 'Email Template Name',
|
||||
'template_type': EMAIL_TYPE,
|
||||
'content': 'This is a template',
|
||||
'service': service,
|
||||
'created_by': sample_user,
|
||||
'subject': 'Email Subject'
|
||||
"name": "Email Template Name",
|
||||
"template_type": EMAIL_TYPE,
|
||||
"content": "This is a template",
|
||||
"service": service,
|
||||
"created_by": sample_user,
|
||||
"subject": "Email Subject",
|
||||
}
|
||||
template = Template(**data)
|
||||
dao_create_template(template)
|
||||
return template
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def sample_template_without_email_permission(notify_db_session):
|
||||
service = create_service(service_permissions=[SMS_TYPE], check_if_service_exists=True)
|
||||
service = create_service(
|
||||
service_permissions=[SMS_TYPE], check_if_service_exists=True
|
||||
)
|
||||
return create_template(service, template_type=EMAIL_TYPE)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def sample_email_template_with_placeholders(sample_service):
|
||||
return create_template(
|
||||
sample_service,
|
||||
@@ -306,7 +322,7 @@ def sample_email_template_with_placeholders(sample_service):
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def sample_email_template_with_html(sample_service):
|
||||
return create_template(
|
||||
sample_service,
|
||||
@@ -316,79 +332,78 @@ def sample_email_template_with_html(sample_service):
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def sample_api_key(notify_db_session):
|
||||
service = create_service(check_if_service_exists=True)
|
||||
data = {'service': service, 'name': uuid.uuid4(), 'created_by': service.created_by, 'key_type': KEY_TYPE_NORMAL}
|
||||
data = {
|
||||
"service": service,
|
||||
"name": uuid.uuid4(),
|
||||
"created_by": service.created_by,
|
||||
"key_type": KEY_TYPE_NORMAL,
|
||||
}
|
||||
api_key = ApiKey(**data)
|
||||
save_model_api_key(api_key)
|
||||
return api_key
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def sample_test_api_key(sample_api_key):
|
||||
service = create_service(check_if_service_exists=True)
|
||||
|
||||
return create_api_key(
|
||||
service,
|
||||
key_type=KEY_TYPE_TEST
|
||||
)
|
||||
return create_api_key(service, key_type=KEY_TYPE_TEST)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def sample_team_api_key(sample_api_key):
|
||||
service = create_service(check_if_service_exists=True)
|
||||
|
||||
return create_api_key(
|
||||
service,
|
||||
key_type=KEY_TYPE_TEAM
|
||||
)
|
||||
return create_api_key(service, key_type=KEY_TYPE_TEAM)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def sample_job(notify_db_session):
|
||||
service = create_service(check_if_service_exists=True)
|
||||
template = create_template(service=service)
|
||||
data = {
|
||||
'id': uuid.uuid4(),
|
||||
'service_id': service.id,
|
||||
'service': service,
|
||||
'template_id': template.id,
|
||||
'template_version': template.version,
|
||||
'original_file_name': 'some.csv',
|
||||
'notification_count': 1,
|
||||
'created_at': datetime.utcnow(),
|
||||
'created_by': service.created_by,
|
||||
'job_status': 'pending',
|
||||
'scheduled_for': None,
|
||||
'processing_started': None,
|
||||
'archived': False
|
||||
"id": uuid.uuid4(),
|
||||
"service_id": service.id,
|
||||
"service": service,
|
||||
"template_id": template.id,
|
||||
"template_version": template.version,
|
||||
"original_file_name": "some.csv",
|
||||
"notification_count": 1,
|
||||
"created_at": datetime.utcnow(),
|
||||
"created_by": service.created_by,
|
||||
"job_status": "pending",
|
||||
"scheduled_for": None,
|
||||
"processing_started": None,
|
||||
"archived": False,
|
||||
}
|
||||
job = Job(**data)
|
||||
dao_create_job(job)
|
||||
return job
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def sample_job_with_placeholdered_template(
|
||||
sample_job,
|
||||
sample_template_with_placeholders,
|
||||
sample_job,
|
||||
sample_template_with_placeholders,
|
||||
):
|
||||
sample_job.template = sample_template_with_placeholders
|
||||
|
||||
return sample_job
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def sample_scheduled_job(sample_template_with_placeholders):
|
||||
return create_job(
|
||||
sample_template_with_placeholders,
|
||||
job_status='scheduled',
|
||||
scheduled_for=(datetime.utcnow() + timedelta(minutes=60)).isoformat()
|
||||
job_status="scheduled",
|
||||
scheduled_for=(datetime.utcnow() + timedelta(minutes=60)).isoformat(),
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def sample_notification_with_job(notify_db_session):
|
||||
service = create_service(check_if_service_exists=True)
|
||||
template = create_template(service=service)
|
||||
@@ -398,54 +413,56 @@ def sample_notification_with_job(notify_db_session):
|
||||
job=job,
|
||||
job_row_number=None,
|
||||
to_field=None,
|
||||
status='created',
|
||||
status="created",
|
||||
reference=None,
|
||||
created_at=None,
|
||||
sent_at=None,
|
||||
billable_units=1,
|
||||
personalisation=None,
|
||||
api_key=None,
|
||||
key_type=KEY_TYPE_NORMAL
|
||||
key_type=KEY_TYPE_NORMAL,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def sample_notification(notify_db_session):
|
||||
created_at = datetime.utcnow()
|
||||
service = create_service(check_if_service_exists=True)
|
||||
template = create_template(service=service)
|
||||
|
||||
api_key = ApiKey.query.filter(ApiKey.service == template.service, ApiKey.key_type == KEY_TYPE_NORMAL).first()
|
||||
api_key = ApiKey.query.filter(
|
||||
ApiKey.service == template.service, ApiKey.key_type == KEY_TYPE_NORMAL
|
||||
).first()
|
||||
if not api_key:
|
||||
api_key = create_api_key(template.service, key_type=KEY_TYPE_NORMAL)
|
||||
|
||||
notification_id = uuid.uuid4()
|
||||
to = '+447700900855'
|
||||
to = "+447700900855"
|
||||
|
||||
data = {
|
||||
'id': notification_id,
|
||||
'to': to,
|
||||
'job_id': None,
|
||||
'job': None,
|
||||
'service_id': service.id,
|
||||
'service': service,
|
||||
'template_id': template.id,
|
||||
'template_version': template.version,
|
||||
'status': 'created',
|
||||
'reference': None,
|
||||
'created_at': created_at,
|
||||
'sent_at': None,
|
||||
'billable_units': 1,
|
||||
'personalisation': None,
|
||||
'notification_type': template.template_type,
|
||||
'api_key': api_key,
|
||||
'api_key_id': api_key and api_key.id,
|
||||
'key_type': api_key.key_type,
|
||||
'sent_by': None,
|
||||
'updated_at': None,
|
||||
'client_reference': None,
|
||||
'rate_multiplier': 1.0,
|
||||
'normalised_to': None,
|
||||
"id": notification_id,
|
||||
"to": to,
|
||||
"job_id": None,
|
||||
"job": None,
|
||||
"service_id": service.id,
|
||||
"service": service,
|
||||
"template_id": template.id,
|
||||
"template_version": template.version,
|
||||
"status": "created",
|
||||
"reference": None,
|
||||
"created_at": created_at,
|
||||
"sent_at": None,
|
||||
"billable_units": 1,
|
||||
"personalisation": None,
|
||||
"notification_type": template.template_type,
|
||||
"api_key": api_key,
|
||||
"api_key_id": api_key and api_key.id,
|
||||
"key_type": api_key.key_type,
|
||||
"sent_by": None,
|
||||
"updated_at": None,
|
||||
"client_reference": None,
|
||||
"rate_multiplier": 1.0,
|
||||
"normalised_to": None,
|
||||
}
|
||||
|
||||
notification = Notification(**data)
|
||||
@@ -454,7 +471,7 @@ def sample_notification(notify_db_session):
|
||||
return notification
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def sample_email_notification(notify_db_session):
|
||||
created_at = datetime.utcnow()
|
||||
service = create_service(check_if_service_exists=True)
|
||||
@@ -463,33 +480,33 @@ def sample_email_notification(notify_db_session):
|
||||
|
||||
notification_id = uuid.uuid4()
|
||||
|
||||
to = 'foo@bar.com'
|
||||
to = "foo@bar.com"
|
||||
|
||||
data = {
|
||||
'id': notification_id,
|
||||
'to': to,
|
||||
'job_id': job.id,
|
||||
'job': job,
|
||||
'service_id': service.id,
|
||||
'service': service,
|
||||
'template_id': template.id,
|
||||
'template_version': template.version,
|
||||
'status': 'created',
|
||||
'reference': None,
|
||||
'created_at': created_at,
|
||||
'billable_units': 0,
|
||||
'personalisation': None,
|
||||
'notification_type': template.template_type,
|
||||
'api_key_id': None,
|
||||
'key_type': KEY_TYPE_NORMAL,
|
||||
'job_row_number': 1
|
||||
"id": notification_id,
|
||||
"to": to,
|
||||
"job_id": job.id,
|
||||
"job": job,
|
||||
"service_id": service.id,
|
||||
"service": service,
|
||||
"template_id": template.id,
|
||||
"template_version": template.version,
|
||||
"status": "created",
|
||||
"reference": None,
|
||||
"created_at": created_at,
|
||||
"billable_units": 0,
|
||||
"personalisation": None,
|
||||
"notification_type": template.template_type,
|
||||
"api_key_id": None,
|
||||
"key_type": KEY_TYPE_NORMAL,
|
||||
"job_row_number": 1,
|
||||
}
|
||||
notification = Notification(**data)
|
||||
dao_create_notification(notification)
|
||||
return notification
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def sample_notification_history(notify_db_session, sample_template):
|
||||
created_at = datetime.utcnow()
|
||||
sent_at = datetime.utcnow()
|
||||
@@ -501,13 +518,13 @@ def sample_notification_history(notify_db_session, sample_template):
|
||||
service=sample_template.service,
|
||||
template_id=sample_template.id,
|
||||
template_version=sample_template.version,
|
||||
status='created',
|
||||
status="created",
|
||||
created_at=created_at,
|
||||
notification_type=notification_type,
|
||||
key_type=KEY_TYPE_NORMAL,
|
||||
api_key=api_key,
|
||||
api_key_id=api_key and api_key.id,
|
||||
sent_at=sent_at
|
||||
sent_at=sent_at,
|
||||
)
|
||||
notify_db_session.add(notification_history)
|
||||
notify_db_session.commit()
|
||||
@@ -515,44 +532,39 @@ def sample_notification_history(notify_db_session, sample_template):
|
||||
return notification_history
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def sample_invited_user(notify_db_session):
|
||||
service = create_service(check_if_service_exists=True)
|
||||
to_email_address = 'invited_user@digital.gov.uk'
|
||||
to_email_address = "invited_user@digital.fake.gov"
|
||||
|
||||
from_user = service.users[0]
|
||||
|
||||
data = {
|
||||
'service': service,
|
||||
'email_address': to_email_address,
|
||||
'from_user': from_user,
|
||||
'permissions': 'send_messages,manage_service,manage_api_keys',
|
||||
'folder_permissions': ['folder_1_id', 'folder_2_id'],
|
||||
"service": service,
|
||||
"email_address": to_email_address,
|
||||
"from_user": from_user,
|
||||
"permissions": "send_messages,manage_service,manage_api_keys",
|
||||
"folder_permissions": ["folder_1_id", "folder_2_id"],
|
||||
}
|
||||
invited_user = InvitedUser(**data)
|
||||
save_invited_user(invited_user)
|
||||
return invited_user
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def sample_invited_org_user(sample_user, sample_organisation):
|
||||
return create_invited_org_user(sample_organisation, sample_user)
|
||||
@pytest.fixture(scope="function")
|
||||
def sample_invited_org_user(sample_user, sample_organization):
|
||||
return create_invited_org_user(sample_organization, sample_user)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def sample_user_service_permission(sample_user):
|
||||
service = create_service(user=sample_user, check_if_service_exists=True)
|
||||
permission = 'manage_settings'
|
||||
permission = "manage_settings"
|
||||
|
||||
data = {
|
||||
'user': sample_user,
|
||||
'service': service,
|
||||
'permission': permission
|
||||
}
|
||||
data = {"user": sample_user, "service": service, "permission": permission}
|
||||
p_model = Permission.query.filter_by(
|
||||
user=sample_user,
|
||||
service=service,
|
||||
permission=permission).first()
|
||||
user=sample_user, service=service, permission=permission
|
||||
).first()
|
||||
if not p_model:
|
||||
p_model = Permission(**data)
|
||||
db.session.add(p_model)
|
||||
@@ -560,146 +572,148 @@ def sample_user_service_permission(sample_user):
|
||||
return p_model
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def fake_uuid():
|
||||
return "6ce466d0-fd6a-11e5-82f5-e0accb9d11a6"
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def ses_provider():
|
||||
return ProviderDetails.query.filter_by(identifier='ses').one()
|
||||
return ProviderDetails.query.filter_by(identifier="ses").one()
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def sns_provider():
|
||||
return ProviderDetails.query.filter_by(identifier='sns').one()
|
||||
return ProviderDetails.query.filter_by(identifier="sns").one()
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def sms_code_template(notify_service):
|
||||
return create_custom_template(
|
||||
service=notify_service,
|
||||
user=notify_service.users[0],
|
||||
template_config_name='SMS_CODE_TEMPLATE_ID',
|
||||
content='((verify_code))',
|
||||
template_type='sms'
|
||||
template_config_name="SMS_CODE_TEMPLATE_ID",
|
||||
content="((verify_code))",
|
||||
template_type="sms",
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def email_2fa_code_template(notify_service):
|
||||
return create_custom_template(
|
||||
service=notify_service,
|
||||
user=notify_service.users[0],
|
||||
template_config_name='EMAIL_2FA_TEMPLATE_ID',
|
||||
template_config_name="EMAIL_2FA_TEMPLATE_ID",
|
||||
content=(
|
||||
'Hi ((name)),'
|
||||
''
|
||||
'To sign in to GOV.UK Notify please open this link:'
|
||||
'((url))'
|
||||
"Hi ((name)),"
|
||||
""
|
||||
"To sign in to GOV.UK Notify please open this link:"
|
||||
"((url))"
|
||||
),
|
||||
subject='Sign in to GOV.UK Notify',
|
||||
template_type='email'
|
||||
subject="Sign in to GOV.UK Notify",
|
||||
template_type="email",
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def email_verification_template(notify_service):
|
||||
return create_custom_template(
|
||||
service=notify_service,
|
||||
user=notify_service.users[0],
|
||||
template_config_name='NEW_USER_EMAIL_VERIFICATION_TEMPLATE_ID',
|
||||
content='((user_name)) use ((url)) to complete registration',
|
||||
template_type='email'
|
||||
template_config_name="NEW_USER_EMAIL_VERIFICATION_TEMPLATE_ID",
|
||||
content="((user_name)) use ((url)) to complete registration",
|
||||
template_type="email",
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def invitation_email_template(notify_service):
|
||||
content = '((user_name)) is invited to Notify by ((service_name)) ((url)) to complete registration',
|
||||
content = (
|
||||
"((user_name)) is invited to Notify by ((service_name)) ((url)) to complete registration",
|
||||
)
|
||||
return create_custom_template(
|
||||
service=notify_service,
|
||||
user=notify_service.users[0],
|
||||
template_config_name='INVITATION_EMAIL_TEMPLATE_ID',
|
||||
template_config_name="INVITATION_EMAIL_TEMPLATE_ID",
|
||||
content=content,
|
||||
subject='Invitation to ((service_name))',
|
||||
template_type='email'
|
||||
subject="Invitation to ((service_name))",
|
||||
template_type="email",
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def org_invite_email_template(notify_service):
|
||||
return create_custom_template(
|
||||
service=notify_service,
|
||||
user=notify_service.users[0],
|
||||
template_config_name='ORGANISATION_INVITATION_EMAIL_TEMPLATE_ID',
|
||||
content='((user_name)) ((organisation_name)) ((url))',
|
||||
subject='Invitation to ((organisation_name))',
|
||||
template_type='email'
|
||||
template_config_name="ORGANIZATION_INVITATION_EMAIL_TEMPLATE_ID",
|
||||
content="((user_name)) ((organization_name)) ((url))",
|
||||
subject="Invitation to ((organization_name))",
|
||||
template_type="email",
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def password_reset_email_template(notify_service):
|
||||
return create_custom_template(
|
||||
service=notify_service,
|
||||
user=notify_service.users[0],
|
||||
template_config_name='PASSWORD_RESET_TEMPLATE_ID',
|
||||
content='((user_name)) you can reset password by clicking ((url))',
|
||||
subject='Reset your password',
|
||||
template_type='email'
|
||||
template_config_name="PASSWORD_RESET_TEMPLATE_ID",
|
||||
content="((user_name)) you can reset password by clicking ((url))",
|
||||
subject="Reset your password",
|
||||
template_type="email",
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def verify_reply_to_address_email_template(notify_service):
|
||||
return create_custom_template(
|
||||
service=notify_service,
|
||||
user=notify_service.users[0],
|
||||
template_config_name='REPLY_TO_EMAIL_ADDRESS_VERIFICATION_TEMPLATE_ID',
|
||||
template_config_name="REPLY_TO_EMAIL_ADDRESS_VERIFICATION_TEMPLATE_ID",
|
||||
content="Hi,This address has been provided as the reply-to email address so we are verifying if it's working",
|
||||
subject='Your GOV.UK Notify reply-to email address',
|
||||
template_type='email'
|
||||
subject="Your GOV.UK Notify reply-to email address",
|
||||
template_type="email",
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def team_member_email_edit_template(notify_service):
|
||||
return create_custom_template(
|
||||
service=notify_service,
|
||||
user=notify_service.users[0],
|
||||
template_config_name='TEAM_MEMBER_EDIT_EMAIL_TEMPLATE_ID',
|
||||
content='Hi ((name)) ((servicemanagername)) changed your email to ((email address))',
|
||||
subject='Your GOV.UK Notify email address has changed',
|
||||
template_type='email'
|
||||
template_config_name="TEAM_MEMBER_EDIT_EMAIL_TEMPLATE_ID",
|
||||
content="Hi ((name)) ((servicemanagername)) changed your email to ((email address))",
|
||||
subject="Your GOV.UK Notify email address has changed",
|
||||
template_type="email",
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def team_member_mobile_edit_template(notify_service):
|
||||
return create_custom_template(
|
||||
service=notify_service,
|
||||
user=notify_service.users[0],
|
||||
template_config_name='TEAM_MEMBER_EDIT_MOBILE_TEMPLATE_ID',
|
||||
content='Your mobile number was changed by ((servicemanagername)).',
|
||||
template_type='sms'
|
||||
template_config_name="TEAM_MEMBER_EDIT_MOBILE_TEMPLATE_ID",
|
||||
content="Your mobile number was changed by ((servicemanagername)).",
|
||||
template_type="sms",
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def already_registered_template(notify_service):
|
||||
content = """Sign in here: ((signin_url)) If you’ve forgotten your password,
|
||||
you can reset it here: ((forgot_password_url)) feedback:((feedback_url))"""
|
||||
return create_custom_template(
|
||||
service=notify_service,
|
||||
user=notify_service.users[0],
|
||||
template_config_name='ALREADY_REGISTERED_EMAIL_TEMPLATE_ID',
|
||||
template_config_name="ALREADY_REGISTERED_EMAIL_TEMPLATE_ID",
|
||||
content=content,
|
||||
template_type='email'
|
||||
template_type="email",
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def change_email_confirmation_template(notify_service):
|
||||
content = """Hi ((name)),
|
||||
Click this link to confirm your new email address:
|
||||
@@ -709,52 +723,57 @@ def change_email_confirmation_template(notify_service):
|
||||
template = create_custom_template(
|
||||
service=notify_service,
|
||||
user=notify_service.users[0],
|
||||
template_config_name='CHANGE_EMAIL_CONFIRMATION_TEMPLATE_ID',
|
||||
template_config_name="CHANGE_EMAIL_CONFIRMATION_TEMPLATE_ID",
|
||||
content=content,
|
||||
template_type='email'
|
||||
template_type="email",
|
||||
)
|
||||
return template
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def mou_signed_templates(notify_service):
|
||||
import importlib
|
||||
alembic_script = importlib.import_module('migrations.versions.0298_add_mou_signed_receipt')
|
||||
|
||||
alembic_script = importlib.import_module(
|
||||
"migrations.versions.0298_add_mou_signed_receipt"
|
||||
)
|
||||
|
||||
return {
|
||||
config_name: create_custom_template(
|
||||
notify_service,
|
||||
notify_service.users[0],
|
||||
config_name,
|
||||
'email',
|
||||
content='\n'.join(
|
||||
"email",
|
||||
content="\n".join(
|
||||
next(
|
||||
x
|
||||
for x in alembic_script.templates
|
||||
if x['id'] == current_app.config[config_name]
|
||||
)['content_lines']
|
||||
if x["id"] == current_app.config[config_name]
|
||||
)["content_lines"]
|
||||
),
|
||||
)
|
||||
for config_name in [
|
||||
'MOU_SIGNER_RECEIPT_TEMPLATE_ID',
|
||||
'MOU_SIGNED_ON_BEHALF_SIGNER_RECEIPT_TEMPLATE_ID',
|
||||
'MOU_SIGNED_ON_BEHALF_ON_BEHALF_RECEIPT_TEMPLATE_ID',
|
||||
"MOU_SIGNER_RECEIPT_TEMPLATE_ID",
|
||||
"MOU_SIGNED_ON_BEHALF_SIGNER_RECEIPT_TEMPLATE_ID",
|
||||
"MOU_SIGNED_ON_BEHALF_ON_BEHALF_RECEIPT_TEMPLATE_ID",
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
def create_custom_template(service, user, template_config_name, template_type, content='', subject=None):
|
||||
def create_custom_template(
|
||||
service, user, template_config_name, template_type, content="", subject=None
|
||||
):
|
||||
template = Template.query.get(current_app.config[template_config_name])
|
||||
if not template:
|
||||
data = {
|
||||
'id': current_app.config[template_config_name],
|
||||
'name': template_config_name,
|
||||
'template_type': template_type,
|
||||
'content': content,
|
||||
'service': service,
|
||||
'created_by': user,
|
||||
'subject': subject,
|
||||
'archived': False
|
||||
"id": current_app.config[template_config_name],
|
||||
"name": template_config_name,
|
||||
"template_type": template_type,
|
||||
"content": content,
|
||||
"service": service,
|
||||
"created_by": user,
|
||||
"subject": subject,
|
||||
"archived": False,
|
||||
}
|
||||
template = Template(**data)
|
||||
db.session.add(template)
|
||||
@@ -765,26 +784,26 @@ def create_custom_template(service, user, template_config_name, template_type, c
|
||||
|
||||
@pytest.fixture
|
||||
def notify_service(notify_db_session, sample_user):
|
||||
service = Service.query.get(current_app.config['NOTIFY_SERVICE_ID'])
|
||||
service = Service.query.get(current_app.config["NOTIFY_SERVICE_ID"])
|
||||
if not service:
|
||||
service = Service(
|
||||
name='Notify Service',
|
||||
name="Notify Service",
|
||||
message_limit=1000,
|
||||
restricted=False,
|
||||
email_from='notify.service',
|
||||
email_from="notify.service",
|
||||
created_by=sample_user,
|
||||
prefix_sms=False,
|
||||
)
|
||||
dao_create_service(
|
||||
service=service,
|
||||
service_id=current_app.config['NOTIFY_SERVICE_ID'],
|
||||
user=sample_user
|
||||
service_id=current_app.config["NOTIFY_SERVICE_ID"],
|
||||
user=sample_user,
|
||||
)
|
||||
|
||||
data = {
|
||||
'service': service,
|
||||
'email_address': "notify@gov.uk",
|
||||
'is_default': True,
|
||||
"service": service,
|
||||
"email_address": "notify@gov.uk",
|
||||
"is_default": True,
|
||||
}
|
||||
reply_to = ServiceEmailReplyTo(**data)
|
||||
|
||||
@@ -794,10 +813,12 @@ def notify_service(notify_db_session, sample_user):
|
||||
return service
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def sample_service_guest_list(notify_db_session):
|
||||
service = create_service(check_if_service_exists=True)
|
||||
guest_list_user = ServiceGuestList.from_string(service.id, EMAIL_TYPE, 'guest_list_user@digital.gov.uk')
|
||||
guest_list_user = ServiceGuestList.from_string(
|
||||
service.id, EMAIL_TYPE, "guest_list_user@digital.fake.gov"
|
||||
)
|
||||
|
||||
notify_db_session.add(guest_list_user)
|
||||
notify_db_session.commit()
|
||||
@@ -806,17 +827,23 @@ def sample_service_guest_list(notify_db_session):
|
||||
|
||||
@pytest.fixture
|
||||
def sample_inbound_numbers(sample_service):
|
||||
service = create_service(service_name='sample service 2', check_if_service_exists=True)
|
||||
service = create_service(
|
||||
service_name="sample service 2", check_if_service_exists=True
|
||||
)
|
||||
inbound_numbers = list()
|
||||
inbound_numbers.append(create_inbound_number(number='1', provider='sns'))
|
||||
inbound_numbers.append(create_inbound_number(number='2', provider='sns', active=False, service_id=service.id))
|
||||
inbound_numbers.append(create_inbound_number(number="1", provider="sns"))
|
||||
inbound_numbers.append(
|
||||
create_inbound_number(
|
||||
number="2", provider="sns", active=False, service_id=service.id
|
||||
)
|
||||
)
|
||||
return inbound_numbers
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_organisation(notify_db_session):
|
||||
org = Organisation(name='sample organisation')
|
||||
dao_create_organisation(org)
|
||||
def sample_organization(notify_db_session):
|
||||
org = Organization(name="sample organization")
|
||||
dao_create_organization(org)
|
||||
return org
|
||||
|
||||
|
||||
@@ -824,12 +851,12 @@ def sample_organisation(notify_db_session):
|
||||
def nhs_email_branding(notify_db_session):
|
||||
# we wipe email_branding table in test db between the tests, so we have to recreate this branding
|
||||
# that is normally present on all environments and applied through migration
|
||||
nhs_email_branding_id = current_app.config['NHS_EMAIL_BRANDING_ID']
|
||||
nhs_email_branding_id = current_app.config["NHS_EMAIL_BRANDING_ID"]
|
||||
|
||||
return create_email_branding(
|
||||
id=nhs_email_branding_id,
|
||||
logo='1ac6f483-3105-4c9e-9017-dd7fb2752c44-nhs-blue_x2.png',
|
||||
name='NHS'
|
||||
logo="1ac6f483-3105-4c9e-9017-dd7fb2752c44-nhs-blue_x2.png",
|
||||
name="NHS",
|
||||
)
|
||||
|
||||
|
||||
@@ -864,7 +891,6 @@ def restore_provider_details(notify_db_session):
|
||||
|
||||
@pytest.fixture
|
||||
def admin_request(client):
|
||||
|
||||
class AdminRequest:
|
||||
app = client.application
|
||||
|
||||
@@ -872,7 +898,7 @@ def admin_request(client):
|
||||
def get(endpoint, _expected_status=200, **endpoint_kwargs):
|
||||
resp = client.get(
|
||||
url_for(endpoint, **(endpoint_kwargs or {})),
|
||||
headers=[create_admin_authorization_header()]
|
||||
headers=[create_admin_authorization_header()],
|
||||
)
|
||||
json_resp = resp.json
|
||||
assert resp.status_code == _expected_status
|
||||
@@ -883,7 +909,10 @@ def admin_request(client):
|
||||
resp = client.post(
|
||||
url_for(endpoint, **(endpoint_kwargs or {})),
|
||||
data=json.dumps(_data),
|
||||
headers=[('Content-Type', 'application/json'), create_admin_authorization_header()]
|
||||
headers=[
|
||||
("Content-Type", "application/json"),
|
||||
create_admin_authorization_header(),
|
||||
],
|
||||
)
|
||||
if resp.get_data():
|
||||
json_resp = resp.json
|
||||
@@ -896,7 +925,7 @@ def admin_request(client):
|
||||
def delete(endpoint, _expected_status=204, **endpoint_kwargs):
|
||||
resp = client.delete(
|
||||
url_for(endpoint, **(endpoint_kwargs or {})),
|
||||
headers=[create_admin_authorization_header()]
|
||||
headers=[create_admin_authorization_header()],
|
||||
)
|
||||
if resp.get_data():
|
||||
json_resp = resp.json
|
||||
|
||||
Reference in New Issue
Block a user