2019-02-26 17:57:55 +00:00
|
|
|
import random
|
persist_letter saves address correctly to database
the `to` field stores either the phone number or the email address
of the recipient - it's a bit more complicated for letters, since
there are address lines 1 through 6, and a postcode. In utils, they're
stored alongside the personalisation, and we have to ensure that when
we persist to the database we keep as much parity with utils to make
our work easier. Aside from sending, the `to` field is also used to
show recipients on the front end report pages - we've decided that the
best thing to store here is address_line_1 - which is probably going to
be either a person's name, company name, or PO box number
Also, a lot of tests and test cleanup - I added create_template and
create_notification functions in db.py, so if you're creating new
fixtures you can use these functions, and you won't need to pass
notify_db and notify_db_session around, huzzah!
also removed create param from sample_notification since it's not used
anywhere
2017-01-19 12:10:32 +00:00
|
|
|
import uuid
|
2023-03-02 20:20:31 -05:00
|
|
|
from datetime import datetime, timedelta
|
persist_letter saves address correctly to database
the `to` field stores either the phone number or the email address
of the recipient - it's a bit more complicated for letters, since
there are address lines 1 through 6, and a postcode. In utils, they're
stored alongside the personalisation, and we have to ensure that when
we persist to the database we keep as much parity with utils to make
our work easier. Aside from sending, the `to` field is also used to
show recipients on the front end report pages - we've decided that the
best thing to store here is address_line_1 - which is probably going to
be either a person's name, company name, or PO box number
Also, a lot of tests and test cleanup - I added create_template and
create_notification functions in db.py, so if you're creating new
fixtures you can use these functions, and you won't need to pass
notify_db and notify_db_session around, huzzah!
also removed create param from sample_notification since it's not used
anywhere
2017-01-19 12:10:32 +00:00
|
|
|
|
2017-10-06 17:08:06 +01:00
|
|
|
from app import db
|
2021-03-10 11:12:29 +00:00
|
|
|
from app.dao import fact_processing_time_dao
|
2018-09-18 15:22:08 +01:00
|
|
|
from app.dao.email_branding_dao import dao_create_email_branding
|
|
|
|
|
from app.dao.inbound_sms_dao import dao_create_inbound_sms
|
|
|
|
|
from app.dao.invited_org_user_dao import save_invited_org_user
|
2018-09-17 15:45:29 +01:00
|
|
|
from app.dao.invited_user_dao import save_invited_user
|
2017-03-15 15:26:58 +00:00
|
|
|
from app.dao.jobs_dao import dao_create_job
|
2021-03-10 13:55:06 +00:00
|
|
|
from app.dao.notifications_dao import dao_create_notification
|
2023-07-10 11:06:29 -07:00
|
|
|
from app.dao.organization_dao import (
|
|
|
|
|
dao_add_service_to_organization,
|
|
|
|
|
dao_create_organization,
|
2018-09-18 15:22:08 +01:00
|
|
|
)
|
2019-05-21 15:51:37 +01:00
|
|
|
from app.dao.permissions_dao import permission_dao
|
2018-09-18 15:22:08 +01:00
|
|
|
from app.dao.service_callback_api_dao import save_service_callback_api
|
2018-07-11 17:02:49 +01:00
|
|
|
from app.dao.service_data_retention_dao import insert_service_data_retention
|
2017-06-15 11:32:51 +01:00
|
|
|
from app.dao.service_inbound_api_dao import save_service_inbound_api
|
2018-09-18 15:22:08 +01:00
|
|
|
from app.dao.service_permissions_dao import dao_add_service_permission
|
2021-03-10 13:55:06 +00:00
|
|
|
from app.dao.service_sms_sender_dao import (
|
|
|
|
|
dao_update_service_sms_sender,
|
|
|
|
|
update_existing_sms_sender_with_inbound_number,
|
|
|
|
|
)
|
|
|
|
|
from app.dao.services_dao import dao_add_user_to_service, dao_create_service
|
2018-11-08 16:44:57 +00:00
|
|
|
from app.dao.templates_dao import dao_create_template, dao_update_template
|
2018-09-18 15:22:08 +01:00
|
|
|
from app.dao.users_dao import save_model_user
|
2017-05-24 14:24:57 +01:00
|
|
|
from app.models import (
|
2021-03-10 13:55:06 +00:00
|
|
|
EMAIL_TYPE,
|
|
|
|
|
KEY_TYPE_NORMAL,
|
|
|
|
|
MOBILE_TYPE,
|
|
|
|
|
SMS_TYPE,
|
|
|
|
|
AnnualBilling,
|
2017-08-02 11:14:05 +01:00
|
|
|
ApiKey,
|
2021-03-10 13:55:06 +00:00
|
|
|
Complaint,
|
|
|
|
|
Domain,
|
|
|
|
|
EmailBranding,
|
|
|
|
|
FactBilling,
|
|
|
|
|
FactNotificationStatus,
|
|
|
|
|
FactProcessingTime,
|
2017-10-06 17:08:06 +01:00
|
|
|
InboundNumber,
|
2021-03-10 13:55:06 +00:00
|
|
|
InboundSms,
|
2023-07-10 11:06:29 -07:00
|
|
|
InvitedOrganizationUser,
|
2021-03-10 13:55:06 +00:00
|
|
|
InvitedUser,
|
2017-10-06 17:08:06 +01:00
|
|
|
Job,
|
2021-03-10 13:55:06 +00:00
|
|
|
Notification,
|
|
|
|
|
NotificationHistory,
|
2023-07-10 11:06:29 -07:00
|
|
|
Organization,
|
2019-05-21 15:51:37 +01:00
|
|
|
Permission,
|
2017-10-06 17:08:06 +01:00
|
|
|
Rate,
|
|
|
|
|
Service,
|
2021-03-10 13:55:06 +00:00
|
|
|
ServiceCallbackApi,
|
2017-10-06 17:08:06 +01:00
|
|
|
ServiceEmailReplyTo,
|
2021-03-10 13:55:06 +00:00
|
|
|
ServiceGuestList,
|
2017-10-06 17:08:06 +01:00
|
|
|
ServiceInboundApi,
|
2017-05-24 14:24:57 +01:00
|
|
|
ServicePermission,
|
2017-10-06 17:08:06 +01:00
|
|
|
ServiceSmsSender,
|
|
|
|
|
Template,
|
2018-10-30 16:26:25 +00:00
|
|
|
TemplateFolder,
|
2021-03-10 13:55:06 +00:00
|
|
|
User,
|
2021-05-10 22:09:07 +01:00
|
|
|
WebauthnCredential,
|
2017-10-06 17:08:06 +01:00
|
|
|
)
|
2016-12-28 12:30:21 +00:00
|
|
|
|
|
|
|
|
|
2019-02-26 16:25:04 +00:00
|
|
|
def create_user(
|
2020-07-15 16:23:53 +01:00
|
|
|
*,
|
2023-01-04 16:35:25 -05:00
|
|
|
mobile_number="+12028675309",
|
2021-09-08 11:16:46 +01:00
|
|
|
email=None,
|
2023-08-29 14:54:30 -07:00
|
|
|
state="active",
|
2019-02-26 16:25:04 +00:00
|
|
|
id_=None,
|
2023-08-29 14:54:30 -07:00
|
|
|
name="Test User",
|
2019-02-26 16:25:04 +00:00
|
|
|
):
|
2016-12-28 12:30:21 +00:00
|
|
|
data = {
|
2023-08-29 14:54:30 -07:00
|
|
|
"id": id_ or uuid.uuid4(),
|
|
|
|
|
"name": name,
|
|
|
|
|
"email_address": email or f"{uuid.uuid4()}@digital.cabinet-office.gov.uk",
|
|
|
|
|
"password": "password",
|
|
|
|
|
"mobile_number": mobile_number,
|
|
|
|
|
"state": state,
|
2016-12-28 12:30:21 +00:00
|
|
|
}
|
2017-01-10 15:00:10 +00:00
|
|
|
user = User.query.filter_by(email_address=email).first()
|
|
|
|
|
if not user:
|
|
|
|
|
user = User(**data)
|
2020-01-24 15:18:39 +00:00
|
|
|
save_model_user(user, validated_email_access=True)
|
2017-01-10 15:00:10 +00:00
|
|
|
return user
|
persist_letter saves address correctly to database
the `to` field stores either the phone number or the email address
of the recipient - it's a bit more complicated for letters, since
there are address lines 1 through 6, and a postcode. In utils, they're
stored alongside the personalisation, and we have to ensure that when
we persist to the database we keep as much parity with utils to make
our work easier. Aside from sending, the `to` field is also used to
show recipients on the front end report pages - we've decided that the
best thing to store here is address_line_1 - which is probably going to
be either a person's name, company name, or PO box number
Also, a lot of tests and test cleanup - I added create_template and
create_notification functions in db.py, so if you're creating new
fixtures you can use these functions, and you won't need to pass
notify_db and notify_db_session around, huzzah!
also removed create param from sample_notification since it's not used
anywhere
2017-01-19 12:10:32 +00:00
|
|
|
|
|
|
|
|
|
2019-05-21 15:51:37 +01:00
|
|
|
def create_permissions(user, service, *permissions):
|
|
|
|
|
permissions = [
|
|
|
|
|
Permission(service_id=service.id, user_id=user.id, permission=p)
|
|
|
|
|
for p in permissions
|
|
|
|
|
]
|
|
|
|
|
|
2019-10-31 15:01:18 +00:00
|
|
|
permission_dao.set_user_service_permission(user, service, permissions, _commit=True)
|
2019-05-21 15:51:37 +01:00
|
|
|
|
|
|
|
|
|
2017-05-17 14:09:18 +01:00
|
|
|
def create_service(
|
2023-08-29 14:54:30 -07:00
|
|
|
user=None,
|
|
|
|
|
service_name="Sample service",
|
|
|
|
|
service_id=None,
|
|
|
|
|
restricted=False,
|
|
|
|
|
count_as_live=True,
|
|
|
|
|
service_permissions=None,
|
|
|
|
|
research_mode=False,
|
|
|
|
|
active=True,
|
|
|
|
|
email_from=None,
|
|
|
|
|
prefix_sms=True,
|
|
|
|
|
message_limit=1000,
|
2023-08-31 10:28:44 -04:00
|
|
|
total_message_limit=250000,
|
2023-08-29 14:54:30 -07:00
|
|
|
organization_type="federal",
|
|
|
|
|
check_if_service_exists=False,
|
|
|
|
|
go_live_user=None,
|
|
|
|
|
go_live_at=None,
|
|
|
|
|
organization=None,
|
|
|
|
|
purchase_order_number=None,
|
|
|
|
|
billing_contact_names=None,
|
|
|
|
|
billing_contact_email_addresses=None,
|
|
|
|
|
billing_reference=None,
|
2023-10-15 16:28:25 -06:00
|
|
|
create_default_sms_sender=True,
|
2017-05-22 11:26:47 +01:00
|
|
|
):
|
2019-01-02 17:15:27 +00:00
|
|
|
if check_if_service_exists:
|
|
|
|
|
service = Service.query.filter_by(name=service_name).first()
|
|
|
|
|
if (not check_if_service_exists) or (check_if_service_exists and not service):
|
2018-12-31 13:01:24 +00:00
|
|
|
service = Service(
|
|
|
|
|
name=service_name,
|
|
|
|
|
message_limit=message_limit,
|
2023-04-28 12:37:06 -07:00
|
|
|
total_message_limit=total_message_limit,
|
2018-12-31 13:01:24 +00:00
|
|
|
restricted=restricted,
|
2023-08-29 14:54:30 -07:00
|
|
|
email_from=email_from
|
|
|
|
|
if email_from
|
|
|
|
|
else service_name.lower().replace(" ", "."),
|
|
|
|
|
created_by=user
|
|
|
|
|
if user
|
|
|
|
|
else create_user(
|
|
|
|
|
email="{}@digital.cabinet-office.gov.uk".format(uuid.uuid4())
|
|
|
|
|
),
|
2018-12-31 13:01:24 +00:00
|
|
|
prefix_sms=prefix_sms,
|
2023-07-10 11:06:29 -07:00
|
|
|
organization_type=organization_type,
|
|
|
|
|
organization=organization,
|
2019-04-16 12:33:07 +01:00
|
|
|
go_live_user=go_live_user,
|
2019-07-10 18:17:33 +01:00
|
|
|
go_live_at=go_live_at,
|
2021-02-23 18:37:05 +00:00
|
|
|
purchase_order_number=purchase_order_number,
|
|
|
|
|
billing_contact_names=billing_contact_names,
|
|
|
|
|
billing_contact_email_addresses=billing_contact_email_addresses,
|
|
|
|
|
billing_reference=billing_reference,
|
2018-12-31 13:01:24 +00:00
|
|
|
)
|
2020-12-22 15:46:31 +00:00
|
|
|
dao_create_service(
|
|
|
|
|
service,
|
|
|
|
|
service.created_by,
|
|
|
|
|
service_id,
|
|
|
|
|
service_permissions=service_permissions,
|
2023-10-15 16:28:25 -06:00
|
|
|
create_default_sms_sender=create_default_sms_sender,
|
2020-12-22 15:46:31 +00:00
|
|
|
)
|
2017-08-23 11:09:54 +01:00
|
|
|
|
2018-12-31 13:01:24 +00:00
|
|
|
service.active = active
|
|
|
|
|
service.research_mode = research_mode
|
2019-04-11 13:38:21 +01:00
|
|
|
service.count_as_live = count_as_live
|
2018-12-31 14:34:02 +00:00
|
|
|
else:
|
2018-12-31 15:16:00 +00:00
|
|
|
if user and user not in service.users:
|
2018-12-31 14:34:02 +00:00
|
|
|
dao_add_user_to_service(service, user)
|
2017-11-07 14:26:18 +00:00
|
|
|
|
|
|
|
|
return service
|
|
|
|
|
|
|
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
def create_service_with_inbound_number(inbound_number="1234567", *args, **kwargs):
|
2017-11-15 11:00:56 +00:00
|
|
|
service = create_service(*args, **kwargs)
|
2017-07-31 18:28:00 +01:00
|
|
|
|
2017-11-07 14:26:18 +00:00
|
|
|
sms_sender = ServiceSmsSender.query.filter_by(service_id=service.id).first()
|
|
|
|
|
inbound = create_inbound_number(number=inbound_number, service_id=service.id)
|
2023-08-29 14:54:30 -07:00
|
|
|
update_existing_sms_sender_with_inbound_number(
|
|
|
|
|
service_sms_sender=sms_sender,
|
|
|
|
|
sms_sender=inbound_number,
|
|
|
|
|
inbound_number_id=inbound.id,
|
|
|
|
|
)
|
2017-11-07 14:26:18 +00:00
|
|
|
|
|
|
|
|
return service
|
|
|
|
|
|
|
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
def create_service_with_defined_sms_sender(sms_sender_value="1234567", *args, **kwargs):
|
2017-11-15 11:04:33 +00:00
|
|
|
service = create_service(*args, **kwargs)
|
2017-11-07 14:26:18 +00:00
|
|
|
|
|
|
|
|
sms_sender = ServiceSmsSender.query.filter_by(service_id=service.id).first()
|
2023-08-29 14:54:30 -07:00
|
|
|
dao_update_service_sms_sender(
|
|
|
|
|
service_id=service.id,
|
|
|
|
|
service_sms_sender_id=sms_sender.id,
|
|
|
|
|
is_default=True,
|
|
|
|
|
sms_sender=sms_sender_value,
|
|
|
|
|
)
|
2017-11-07 14:26:18 +00:00
|
|
|
|
2017-02-16 11:55:52 +00:00
|
|
|
return service
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_template(
|
2023-08-29 14:54:30 -07:00
|
|
|
service,
|
|
|
|
|
template_type=SMS_TYPE,
|
|
|
|
|
template_name=None,
|
|
|
|
|
subject="Template subject",
|
|
|
|
|
content="Dear Sir/Madam, Hello. Yours Truly, The Government.",
|
|
|
|
|
reply_to=None,
|
|
|
|
|
hidden=False,
|
|
|
|
|
archived=False,
|
|
|
|
|
folder=None,
|
|
|
|
|
process_type="normal",
|
|
|
|
|
contact_block_id=None,
|
2017-02-16 11:55:52 +00:00
|
|
|
):
|
persist_letter saves address correctly to database
the `to` field stores either the phone number or the email address
of the recipient - it's a bit more complicated for letters, since
there are address lines 1 through 6, and a postcode. In utils, they're
stored alongside the personalisation, and we have to ensure that when
we persist to the database we keep as much parity with utils to make
our work easier. Aside from sending, the `to` field is also used to
show recipients on the front end report pages - we've decided that the
best thing to store here is address_line_1 - which is probably going to
be either a person's name, company name, or PO box number
Also, a lot of tests and test cleanup - I added create_template and
create_notification functions in db.py, so if you're creating new
fixtures you can use these functions, and you won't need to pass
notify_db and notify_db_session around, huzzah!
also removed create param from sample_notification since it's not used
anywhere
2017-01-19 12:10:32 +00:00
|
|
|
data = {
|
2023-08-29 14:54:30 -07:00
|
|
|
"name": template_name or "{} Template Name".format(template_type),
|
|
|
|
|
"template_type": template_type,
|
|
|
|
|
"content": content,
|
|
|
|
|
"service": service,
|
|
|
|
|
"created_by": service.created_by,
|
|
|
|
|
"reply_to": reply_to,
|
|
|
|
|
"hidden": hidden,
|
|
|
|
|
"folder": folder,
|
|
|
|
|
"process_type": process_type,
|
persist_letter saves address correctly to database
the `to` field stores either the phone number or the email address
of the recipient - it's a bit more complicated for letters, since
there are address lines 1 through 6, and a postcode. In utils, they're
stored alongside the personalisation, and we have to ensure that when
we persist to the database we keep as much parity with utils to make
our work easier. Aside from sending, the `to` field is also used to
show recipients on the front end report pages - we've decided that the
best thing to store here is address_line_1 - which is probably going to
be either a person's name, company name, or PO box number
Also, a lot of tests and test cleanup - I added create_template and
create_notification functions in db.py, so if you're creating new
fixtures you can use these functions, and you won't need to pass
notify_db and notify_db_session around, huzzah!
also removed create param from sample_notification since it's not used
anywhere
2017-01-19 12:10:32 +00:00
|
|
|
}
|
|
|
|
|
if template_type != SMS_TYPE:
|
2023-08-29 14:54:30 -07:00
|
|
|
data["subject"] = subject
|
persist_letter saves address correctly to database
the `to` field stores either the phone number or the email address
of the recipient - it's a bit more complicated for letters, since
there are address lines 1 through 6, and a postcode. In utils, they're
stored alongside the personalisation, and we have to ensure that when
we persist to the database we keep as much parity with utils to make
our work easier. Aside from sending, the `to` field is also used to
show recipients on the front end report pages - we've decided that the
best thing to store here is address_line_1 - which is probably going to
be either a person's name, company name, or PO box number
Also, a lot of tests and test cleanup - I added create_template and
create_notification functions in db.py, so if you're creating new
fixtures you can use these functions, and you won't need to pass
notify_db and notify_db_session around, huzzah!
also removed create param from sample_notification since it's not used
anywhere
2017-01-19 12:10:32 +00:00
|
|
|
template = Template(**data)
|
2017-03-08 13:03:44 +00:00
|
|
|
dao_create_template(template)
|
2018-11-08 16:44:57 +00:00
|
|
|
|
|
|
|
|
if archived:
|
|
|
|
|
template.archived = archived
|
|
|
|
|
dao_update_template(template)
|
|
|
|
|
|
persist_letter saves address correctly to database
the `to` field stores either the phone number or the email address
of the recipient - it's a bit more complicated for letters, since
there are address lines 1 through 6, and a postcode. In utils, they're
stored alongside the personalisation, and we have to ensure that when
we persist to the database we keep as much parity with utils to make
our work easier. Aside from sending, the `to` field is also used to
show recipients on the front end report pages - we've decided that the
best thing to store here is address_line_1 - which is probably going to
be either a person's name, company name, or PO box number
Also, a lot of tests and test cleanup - I added create_template and
create_notification functions in db.py, so if you're creating new
fixtures you can use these functions, and you won't need to pass
notify_db and notify_db_session around, huzzah!
also removed create param from sample_notification since it's not used
anywhere
2017-01-19 12:10:32 +00:00
|
|
|
return template
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_notification(
|
2023-08-29 14:54:30 -07:00
|
|
|
template=None,
|
|
|
|
|
job=None,
|
|
|
|
|
job_row_number=None,
|
|
|
|
|
to_field=None,
|
|
|
|
|
status="created",
|
|
|
|
|
reference=None,
|
|
|
|
|
created_at=None,
|
|
|
|
|
sent_at=None,
|
|
|
|
|
updated_at=None,
|
|
|
|
|
billable_units=1,
|
|
|
|
|
personalisation=None,
|
|
|
|
|
api_key=None,
|
|
|
|
|
key_type=KEY_TYPE_NORMAL,
|
|
|
|
|
sent_by=None,
|
|
|
|
|
client_reference=None,
|
|
|
|
|
rate_multiplier=None,
|
|
|
|
|
international=False,
|
|
|
|
|
phone_prefix=None,
|
|
|
|
|
normalised_to=None,
|
|
|
|
|
one_off=False,
|
|
|
|
|
reply_to_text=None,
|
|
|
|
|
created_by_id=None,
|
|
|
|
|
document_download_count=None,
|
persist_letter saves address correctly to database
the `to` field stores either the phone number or the email address
of the recipient - it's a bit more complicated for letters, since
there are address lines 1 through 6, and a postcode. In utils, they're
stored alongside the personalisation, and we have to ensure that when
we persist to the database we keep as much parity with utils to make
our work easier. Aside from sending, the `to` field is also used to
show recipients on the front end report pages - we've decided that the
best thing to store here is address_line_1 - which is probably going to
be either a person's name, company name, or PO box number
Also, a lot of tests and test cleanup - I added create_template and
create_notification functions in db.py, so if you're creating new
fixtures you can use these functions, and you won't need to pass
notify_db and notify_db_session around, huzzah!
also removed create param from sample_notification since it's not used
anywhere
2017-01-19 12:10:32 +00:00
|
|
|
):
|
2018-12-12 12:57:04 +00:00
|
|
|
assert job or template
|
|
|
|
|
if job:
|
|
|
|
|
template = job.template
|
|
|
|
|
|
persist_letter saves address correctly to database
the `to` field stores either the phone number or the email address
of the recipient - it's a bit more complicated for letters, since
there are address lines 1 through 6, and a postcode. In utils, they're
stored alongside the personalisation, and we have to ensure that when
we persist to the database we keep as much parity with utils to make
our work easier. Aside from sending, the `to` field is also used to
show recipients on the front end report pages - we've decided that the
best thing to store here is address_line_1 - which is probably going to
be either a person's name, company name, or PO box number
Also, a lot of tests and test cleanup - I added create_template and
create_notification functions in db.py, so if you're creating new
fixtures you can use these functions, and you won't need to pass
notify_db and notify_db_session around, huzzah!
also removed create param from sample_notification since it's not used
anywhere
2017-01-19 12:10:32 +00:00
|
|
|
if created_at is None:
|
|
|
|
|
created_at = datetime.utcnow()
|
2017-02-24 13:39:58 +00:00
|
|
|
|
2017-10-16 17:29:45 +01:00
|
|
|
if to_field is None:
|
2023-08-29 14:54:30 -07:00
|
|
|
to_field = (
|
|
|
|
|
"+447700900855"
|
|
|
|
|
if template.template_type == SMS_TYPE
|
|
|
|
|
else "test@example.com"
|
|
|
|
|
)
|
2017-10-16 17:29:45 +01:00
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
if status not in (
|
|
|
|
|
"created",
|
|
|
|
|
"validation-failed",
|
|
|
|
|
"virus-scan-failed",
|
|
|
|
|
"pending-virus-check",
|
|
|
|
|
):
|
2017-02-27 13:16:48 +00:00
|
|
|
sent_at = sent_at or datetime.utcnow()
|
|
|
|
|
updated_at = updated_at or datetime.utcnow()
|
2017-02-24 13:39:58 +00:00
|
|
|
|
2017-08-29 16:26:55 +01:00
|
|
|
if not one_off and (job is None and api_key is None):
|
2020-01-16 12:11:56 +00:00
|
|
|
# we did not specify in test - lets create it
|
2023-08-29 14:54:30 -07:00
|
|
|
api_key = ApiKey.query.filter(
|
|
|
|
|
ApiKey.service == template.service, ApiKey.key_type == key_type
|
|
|
|
|
).first()
|
2017-08-02 15:35:56 +01:00
|
|
|
if not api_key:
|
|
|
|
|
api_key = create_api_key(template.service, key_type=key_type)
|
2017-08-02 11:14:05 +01:00
|
|
|
|
persist_letter saves address correctly to database
the `to` field stores either the phone number or the email address
of the recipient - it's a bit more complicated for letters, since
there are address lines 1 through 6, and a postcode. In utils, they're
stored alongside the personalisation, and we have to ensure that when
we persist to the database we keep as much parity with utils to make
our work easier. Aside from sending, the `to` field is also used to
show recipients on the front end report pages - we've decided that the
best thing to store here is address_line_1 - which is probably going to
be either a person's name, company name, or PO box number
Also, a lot of tests and test cleanup - I added create_template and
create_notification functions in db.py, so if you're creating new
fixtures you can use these functions, and you won't need to pass
notify_db and notify_db_session around, huzzah!
also removed create param from sample_notification since it's not used
anywhere
2017-01-19 12:10:32 +00:00
|
|
|
data = {
|
2023-08-29 14:54:30 -07:00
|
|
|
"id": uuid.uuid4(),
|
|
|
|
|
"to": to_field,
|
|
|
|
|
"job_id": job and job.id,
|
|
|
|
|
"job": job,
|
|
|
|
|
"service_id": template.service.id,
|
|
|
|
|
"service": template.service,
|
|
|
|
|
"template_id": template.id,
|
|
|
|
|
"template_version": template.version,
|
|
|
|
|
"status": status,
|
|
|
|
|
"reference": reference,
|
|
|
|
|
"created_at": created_at,
|
|
|
|
|
"sent_at": sent_at,
|
|
|
|
|
"billable_units": billable_units,
|
|
|
|
|
"personalisation": personalisation,
|
|
|
|
|
"notification_type": template.template_type,
|
|
|
|
|
"api_key": api_key,
|
|
|
|
|
"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": updated_at,
|
|
|
|
|
"client_reference": client_reference,
|
|
|
|
|
"job_row_number": job_row_number,
|
|
|
|
|
"rate_multiplier": rate_multiplier,
|
|
|
|
|
"international": international,
|
|
|
|
|
"phone_prefix": phone_prefix,
|
|
|
|
|
"normalised_to": normalised_to,
|
|
|
|
|
"reply_to_text": reply_to_text,
|
|
|
|
|
"created_by_id": created_by_id,
|
|
|
|
|
"document_download_count": document_download_count,
|
persist_letter saves address correctly to database
the `to` field stores either the phone number or the email address
of the recipient - it's a bit more complicated for letters, since
there are address lines 1 through 6, and a postcode. In utils, they're
stored alongside the personalisation, and we have to ensure that when
we persist to the database we keep as much parity with utils to make
our work easier. Aside from sending, the `to` field is also used to
show recipients on the front end report pages - we've decided that the
best thing to store here is address_line_1 - which is probably going to
be either a person's name, company name, or PO box number
Also, a lot of tests and test cleanup - I added create_template and
create_notification functions in db.py, so if you're creating new
fixtures you can use these functions, and you won't need to pass
notify_db and notify_db_session around, huzzah!
also removed create param from sample_notification since it's not used
anywhere
2017-01-19 12:10:32 +00:00
|
|
|
}
|
|
|
|
|
notification = Notification(**data)
|
|
|
|
|
dao_create_notification(notification)
|
|
|
|
|
return notification
|
2017-03-15 15:26:58 +00:00
|
|
|
|
|
|
|
|
|
2019-05-30 10:37:57 +01:00
|
|
|
def create_notification_history(
|
2023-08-29 14:54:30 -07:00
|
|
|
template=None,
|
|
|
|
|
job=None,
|
|
|
|
|
job_row_number=None,
|
|
|
|
|
status="created",
|
|
|
|
|
reference=None,
|
|
|
|
|
created_at=None,
|
|
|
|
|
sent_at=None,
|
|
|
|
|
updated_at=None,
|
|
|
|
|
billable_units=1,
|
|
|
|
|
api_key=None,
|
|
|
|
|
key_type=KEY_TYPE_NORMAL,
|
|
|
|
|
sent_by=None,
|
|
|
|
|
client_reference=None,
|
|
|
|
|
rate_multiplier=None,
|
|
|
|
|
international=False,
|
|
|
|
|
phone_prefix=None,
|
|
|
|
|
created_by_id=None,
|
|
|
|
|
id=None,
|
2019-05-30 10:37:57 +01:00
|
|
|
):
|
|
|
|
|
assert job or template
|
|
|
|
|
if job:
|
|
|
|
|
template = job.template
|
|
|
|
|
|
|
|
|
|
if created_at is None:
|
|
|
|
|
created_at = datetime.utcnow()
|
|
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
if status != "created":
|
2019-05-30 10:37:57 +01:00
|
|
|
sent_at = sent_at or datetime.utcnow()
|
|
|
|
|
updated_at = updated_at or datetime.utcnow()
|
|
|
|
|
|
|
|
|
|
data = {
|
2023-08-29 14:54:30 -07:00
|
|
|
"id": id or uuid.uuid4(),
|
|
|
|
|
"job_id": job and job.id,
|
|
|
|
|
"job": job,
|
|
|
|
|
"service_id": template.service.id,
|
|
|
|
|
"service": template.service,
|
|
|
|
|
"template_id": template.id,
|
|
|
|
|
"template_version": template.version,
|
|
|
|
|
"status": status,
|
|
|
|
|
"reference": reference,
|
|
|
|
|
"created_at": created_at,
|
|
|
|
|
"sent_at": sent_at,
|
|
|
|
|
"billable_units": billable_units,
|
|
|
|
|
"notification_type": template.template_type,
|
|
|
|
|
"api_key": api_key,
|
|
|
|
|
"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": updated_at,
|
|
|
|
|
"client_reference": client_reference,
|
|
|
|
|
"job_row_number": job_row_number,
|
|
|
|
|
"rate_multiplier": rate_multiplier,
|
|
|
|
|
"international": international,
|
|
|
|
|
"phone_prefix": phone_prefix,
|
|
|
|
|
"created_by_id": created_by_id,
|
2019-05-30 10:37:57 +01:00
|
|
|
}
|
|
|
|
|
notification_history = NotificationHistory(**data)
|
|
|
|
|
db.session.add(notification_history)
|
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
|
|
return notification_history
|
|
|
|
|
|
|
|
|
|
|
2017-06-02 12:21:12 +01:00
|
|
|
def create_job(
|
2023-08-29 14:54:30 -07:00
|
|
|
template,
|
|
|
|
|
notification_count=1,
|
|
|
|
|
created_at=None,
|
|
|
|
|
job_status="pending",
|
|
|
|
|
scheduled_for=None,
|
|
|
|
|
processing_started=None,
|
|
|
|
|
processing_finished=None,
|
|
|
|
|
original_file_name="some.csv",
|
|
|
|
|
archived=False,
|
2017-06-02 12:21:12 +01:00
|
|
|
):
|
2017-03-15 15:26:58 +00:00
|
|
|
data = {
|
2023-08-29 14:54:30 -07:00
|
|
|
"id": uuid.uuid4(),
|
|
|
|
|
"service_id": template.service_id,
|
|
|
|
|
"service": template.service,
|
|
|
|
|
"template_id": template.id,
|
|
|
|
|
"template_version": template.version,
|
|
|
|
|
"original_file_name": original_file_name,
|
|
|
|
|
"notification_count": notification_count,
|
|
|
|
|
"created_at": created_at or datetime.utcnow(),
|
|
|
|
|
"created_by": template.created_by,
|
|
|
|
|
"job_status": job_status,
|
|
|
|
|
"scheduled_for": scheduled_for,
|
|
|
|
|
"processing_started": processing_started,
|
|
|
|
|
"processing_finished": processing_finished,
|
|
|
|
|
"archived": archived,
|
2017-03-15 15:26:58 +00:00
|
|
|
}
|
|
|
|
|
job = Job(**data)
|
|
|
|
|
dao_create_job(job)
|
|
|
|
|
return job
|
2017-05-11 15:22:58 +01:00
|
|
|
|
|
|
|
|
|
2017-05-16 10:57:57 +01:00
|
|
|
def create_service_permission(service_id, permission=EMAIL_TYPE):
|
2017-05-17 14:09:18 +01:00
|
|
|
dao_add_service_permission(
|
2023-08-29 14:54:30 -07:00
|
|
|
service_id if service_id else create_service().id, permission
|
|
|
|
|
)
|
2017-05-11 15:22:58 +01:00
|
|
|
|
|
|
|
|
service_permissions = ServicePermission.query.all()
|
|
|
|
|
|
|
|
|
|
return service_permissions
|
2017-05-31 14:49:14 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_inbound_sms(
|
2023-08-29 14:54:30 -07:00
|
|
|
service,
|
|
|
|
|
notify_number=None,
|
|
|
|
|
user_number="12025550104",
|
|
|
|
|
provider_date=None,
|
|
|
|
|
provider_reference=None,
|
|
|
|
|
content="Hello",
|
|
|
|
|
provider="sns",
|
|
|
|
|
created_at=None,
|
2017-05-31 14:49:14 +01:00
|
|
|
):
|
2019-02-26 17:57:55 +00:00
|
|
|
if not service.inbound_number:
|
|
|
|
|
create_inbound_number(
|
|
|
|
|
# create random inbound number
|
2023-08-29 14:54:30 -07:00
|
|
|
notify_number or "1" + str(random.randint(1001001000, 9999999999)),
|
2019-02-26 17:57:55 +00:00
|
|
|
provider=provider,
|
2023-08-29 14:54:30 -07:00
|
|
|
service_id=service.id,
|
2019-02-26 17:57:55 +00:00
|
|
|
)
|
|
|
|
|
|
2017-05-31 14:49:14 +01:00
|
|
|
inbound = InboundSms(
|
|
|
|
|
service=service,
|
2017-06-02 12:21:12 +01:00
|
|
|
created_at=created_at or datetime.utcnow(),
|
2019-02-26 17:57:55 +00:00
|
|
|
notify_number=service.get_inbound_number(),
|
2017-05-31 14:49:14 +01:00
|
|
|
user_number=user_number,
|
|
|
|
|
provider_date=provider_date or datetime.utcnow(),
|
2023-08-29 14:54:30 -07:00
|
|
|
provider_reference=provider_reference or "foo",
|
2017-05-31 14:49:14 +01:00
|
|
|
content=content,
|
2023-08-29 14:54:30 -07:00
|
|
|
provider=provider,
|
2017-05-31 14:49:14 +01:00
|
|
|
)
|
|
|
|
|
dao_create_inbound_sms(inbound)
|
|
|
|
|
return inbound
|
2017-06-15 11:32:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_service_inbound_api(
|
2023-08-29 14:54:30 -07:00
|
|
|
service,
|
|
|
|
|
url="https://something.com",
|
|
|
|
|
bearer_token="some_super_secret",
|
2017-06-15 11:32:51 +01:00
|
|
|
):
|
2023-08-29 14:54:30 -07:00
|
|
|
service_inbound_api = ServiceInboundApi(
|
|
|
|
|
service_id=service.id,
|
|
|
|
|
url=url,
|
|
|
|
|
bearer_token=bearer_token,
|
|
|
|
|
updated_by_id=service.users[0].id,
|
|
|
|
|
)
|
2017-06-15 11:32:51 +01:00
|
|
|
save_service_inbound_api(service_inbound_api)
|
|
|
|
|
return service_inbound_api
|
2017-07-04 17:02:28 +01:00
|
|
|
|
|
|
|
|
|
2017-11-29 15:58:11 +00:00
|
|
|
def create_service_callback_api(
|
2023-08-29 14:54:30 -07:00
|
|
|
service,
|
|
|
|
|
url="https://something.com",
|
|
|
|
|
bearer_token="some_super_secret",
|
|
|
|
|
callback_type="delivery_status",
|
2017-11-29 15:58:11 +00:00
|
|
|
):
|
2023-08-29 14:54:30 -07:00
|
|
|
service_callback_api = ServiceCallbackApi(
|
|
|
|
|
service_id=service.id,
|
|
|
|
|
url=url,
|
|
|
|
|
bearer_token=bearer_token,
|
|
|
|
|
updated_by_id=service.users[0].id,
|
|
|
|
|
callback_type=callback_type,
|
|
|
|
|
)
|
2017-11-29 15:58:11 +00:00
|
|
|
save_service_callback_api(service_callback_api)
|
|
|
|
|
return service_callback_api
|
|
|
|
|
|
|
|
|
|
|
2022-04-08 17:39:55 +01:00
|
|
|
def create_email_branding(
|
2023-08-29 14:54:30 -07:00
|
|
|
id=None, colour="blue", logo="test_x2.png", name="test_org_1", text="DisplayName"
|
2022-04-08 17:39:55 +01:00
|
|
|
):
|
2017-07-04 17:02:28 +01:00
|
|
|
data = {
|
2023-08-29 14:54:30 -07:00
|
|
|
"colour": colour,
|
|
|
|
|
"logo": logo,
|
|
|
|
|
"name": name,
|
|
|
|
|
"text": text,
|
2017-07-04 17:02:28 +01:00
|
|
|
}
|
2022-04-08 17:39:55 +01:00
|
|
|
if id:
|
2023-08-29 14:54:30 -07:00
|
|
|
data["id"] = id
|
2018-02-05 12:02:35 +00:00
|
|
|
email_branding = EmailBranding(**data)
|
|
|
|
|
dao_create_email_branding(email_branding)
|
2017-07-04 17:02:28 +01:00
|
|
|
|
2018-02-05 12:02:35 +00:00
|
|
|
return email_branding
|
2017-07-18 18:21:35 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_rate(start_date, value, notification_type):
|
2017-08-10 16:37:30 +01:00
|
|
|
rate = Rate(
|
|
|
|
|
id=uuid.uuid4(),
|
|
|
|
|
valid_from=start_date,
|
|
|
|
|
rate=value,
|
2023-08-29 14:54:30 -07:00
|
|
|
notification_type=notification_type,
|
2017-08-10 16:37:30 +01:00
|
|
|
)
|
2017-07-25 11:43:41 +01:00
|
|
|
db.session.add(rate)
|
|
|
|
|
db.session.commit()
|
2017-07-18 18:21:35 +01:00
|
|
|
return rate
|
2017-08-02 11:14:05 +01:00
|
|
|
|
|
|
|
|
|
2019-09-13 13:26:46 +01:00
|
|
|
def create_api_key(service, key_type=KEY_TYPE_NORMAL, key_name=None):
|
2017-08-02 15:35:56 +01:00
|
|
|
id_ = uuid.uuid4()
|
2019-09-13 13:26:46 +01:00
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
name = key_name if key_name else "{} api key {}".format(key_type, id_)
|
2019-09-13 13:26:46 +01:00
|
|
|
|
2017-08-02 11:14:05 +01:00
|
|
|
api_key = ApiKey(
|
|
|
|
|
service=service,
|
2019-09-13 13:26:46 +01:00
|
|
|
name=name,
|
2017-08-02 11:14:05 +01:00
|
|
|
created_by=service.created_by,
|
|
|
|
|
key_type=key_type,
|
2017-08-02 15:35:56 +01:00
|
|
|
id=id_,
|
2023-08-29 14:54:30 -07:00
|
|
|
secret=uuid.uuid4(),
|
2017-08-02 11:14:05 +01:00
|
|
|
)
|
|
|
|
|
db.session.add(api_key)
|
|
|
|
|
db.session.commit()
|
|
|
|
|
return api_key
|
2017-08-03 14:05:13 +01:00
|
|
|
|
|
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
def create_inbound_number(number, provider="sns", active=True, service_id=None):
|
2017-08-03 14:05:13 +01:00
|
|
|
inbound_number = InboundNumber(
|
2017-08-04 19:19:43 +01:00
|
|
|
id=uuid.uuid4(),
|
|
|
|
|
number=number,
|
|
|
|
|
provider=provider,
|
|
|
|
|
active=active,
|
2023-08-29 14:54:30 -07:00
|
|
|
service_id=service_id,
|
2017-08-03 14:05:13 +01:00
|
|
|
)
|
|
|
|
|
db.session.add(inbound_number)
|
|
|
|
|
db.session.commit()
|
|
|
|
|
return inbound_number
|
2017-08-10 16:37:30 +01:00
|
|
|
|
|
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
def create_reply_to_email(service, email_address, is_default=True, archived=False):
|
2017-09-08 11:14:26 +01:00
|
|
|
data = {
|
2023-08-29 14:54:30 -07:00
|
|
|
"service": service,
|
|
|
|
|
"email_address": email_address,
|
|
|
|
|
"is_default": is_default,
|
|
|
|
|
"archived": archived,
|
2017-09-08 11:14:26 +01:00
|
|
|
}
|
|
|
|
|
reply_to = ServiceEmailReplyTo(**data)
|
|
|
|
|
|
|
|
|
|
db.session.add(reply_to)
|
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
|
|
return reply_to
|
2017-09-21 16:08:49 +01:00
|
|
|
|
|
|
|
|
|
2017-09-21 16:41:10 +01:00
|
|
|
def create_service_sms_sender(
|
2023-08-29 14:54:30 -07:00
|
|
|
service, sms_sender, is_default=True, inbound_number_id=None, archived=False
|
2017-09-21 16:41:10 +01:00
|
|
|
):
|
|
|
|
|
data = {
|
2023-08-29 14:54:30 -07:00
|
|
|
"service_id": service.id,
|
|
|
|
|
"sms_sender": sms_sender,
|
|
|
|
|
"is_default": is_default,
|
|
|
|
|
"inbound_number_id": inbound_number_id,
|
|
|
|
|
"archived": archived,
|
2017-09-21 16:41:10 +01:00
|
|
|
}
|
|
|
|
|
service_sms_sender = ServiceSmsSender(**data)
|
|
|
|
|
|
|
|
|
|
db.session.add(service_sms_sender)
|
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
|
|
return service_sms_sender
|
|
|
|
|
|
|
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
def create_annual_billing(service_id, free_sms_fragment_limit, financial_year_start):
|
2017-11-02 12:19:17 +00:00
|
|
|
annual_billing = AnnualBilling(
|
|
|
|
|
service_id=service_id,
|
|
|
|
|
free_sms_fragment_limit=free_sms_fragment_limit,
|
2023-08-29 14:54:30 -07:00
|
|
|
financial_year_start=financial_year_start,
|
2017-11-02 12:19:17 +00:00
|
|
|
)
|
|
|
|
|
db.session.add(annual_billing)
|
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
|
|
return annual_billing
|
2017-12-11 16:55:23 +00:00
|
|
|
|
|
|
|
|
|
2023-07-10 11:06:29 -07:00
|
|
|
def create_domain(domain, organization_id):
|
|
|
|
|
domain = Domain(domain=domain, organization_id=organization_id)
|
2019-02-19 12:02:18 +00:00
|
|
|
|
|
|
|
|
db.session.add(domain)
|
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
|
|
return domain
|
|
|
|
|
|
|
|
|
|
|
2023-07-10 11:06:29 -07:00
|
|
|
def create_organization(
|
2023-08-29 14:54:30 -07:00
|
|
|
name="test_org_1",
|
2021-02-23 18:37:05 +00:00
|
|
|
active=True,
|
2023-07-10 11:06:29 -07:00
|
|
|
organization_type=None,
|
2021-02-23 18:37:05 +00:00
|
|
|
domains=None,
|
2023-07-10 11:06:29 -07:00
|
|
|
organization_id=None,
|
2021-02-23 18:37:05 +00:00
|
|
|
purchase_order_number=None,
|
|
|
|
|
billing_contact_names=None,
|
|
|
|
|
billing_contact_email_addresses=None,
|
|
|
|
|
billing_reference=None,
|
2022-04-12 17:18:57 +01:00
|
|
|
email_branding_id=None,
|
2021-02-23 18:37:05 +00:00
|
|
|
):
|
2018-02-07 14:43:09 +00:00
|
|
|
data = {
|
2023-08-29 14:54:30 -07:00
|
|
|
"id": organization_id,
|
|
|
|
|
"name": name,
|
|
|
|
|
"active": active,
|
|
|
|
|
"organization_type": organization_type,
|
|
|
|
|
"purchase_order_number": purchase_order_number,
|
|
|
|
|
"billing_contact_names": billing_contact_names,
|
|
|
|
|
"billing_contact_email_addresses": billing_contact_email_addresses,
|
|
|
|
|
"billing_reference": billing_reference,
|
|
|
|
|
"email_branding_id": email_branding_id,
|
2018-02-07 14:43:09 +00:00
|
|
|
}
|
2023-07-10 11:06:29 -07:00
|
|
|
organization = Organization(**data)
|
|
|
|
|
dao_create_organization(organization)
|
2018-02-07 14:43:09 +00:00
|
|
|
|
2019-06-13 15:54:57 +01:00
|
|
|
for domain in domains or []:
|
2023-07-10 11:06:29 -07:00
|
|
|
create_domain(domain, organization.id)
|
2019-06-13 15:54:57 +01:00
|
|
|
|
2023-07-10 11:06:29 -07:00
|
|
|
return organization
|
2018-02-19 17:14:01 +00:00
|
|
|
|
|
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
def create_invited_org_user(
|
|
|
|
|
organization, invited_by, email_address="invite@example.com"
|
|
|
|
|
):
|
2023-07-10 11:06:29 -07:00
|
|
|
invited_org_user = InvitedOrganizationUser(
|
2018-02-19 17:14:01 +00:00
|
|
|
email_address=email_address,
|
|
|
|
|
invited_by=invited_by,
|
2023-07-10 11:06:29 -07:00
|
|
|
organization=organization,
|
2018-02-19 17:14:01 +00:00
|
|
|
)
|
|
|
|
|
save_invited_org_user(invited_org_user)
|
|
|
|
|
return invited_org_user
|
2018-02-19 14:00:33 +00:00
|
|
|
|
|
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
def create_ft_billing(
|
|
|
|
|
local_date,
|
|
|
|
|
template,
|
|
|
|
|
*,
|
|
|
|
|
provider="test",
|
|
|
|
|
rate_multiplier=1,
|
|
|
|
|
international=False,
|
|
|
|
|
rate=0,
|
|
|
|
|
billable_unit=1,
|
|
|
|
|
notifications_sent=1,
|
|
|
|
|
):
|
|
|
|
|
data = FactBilling(
|
|
|
|
|
local_date=local_date,
|
|
|
|
|
service_id=template.service_id,
|
|
|
|
|
template_id=template.id,
|
|
|
|
|
notification_type=template.template_type,
|
|
|
|
|
provider=provider,
|
|
|
|
|
rate_multiplier=rate_multiplier,
|
|
|
|
|
international=international,
|
|
|
|
|
rate=rate,
|
|
|
|
|
billable_units=billable_unit,
|
|
|
|
|
notifications_sent=notifications_sent,
|
|
|
|
|
)
|
2018-04-06 11:55:49 +01:00
|
|
|
db.session.add(data)
|
|
|
|
|
db.session.commit()
|
|
|
|
|
return data
|
2018-06-04 17:29:58 +01:00
|
|
|
|
|
|
|
|
|
2018-06-29 16:40:24 +01:00
|
|
|
def create_ft_notification_status(
|
2022-11-21 11:49:59 -05:00
|
|
|
local_date,
|
2023-08-29 14:54:30 -07:00
|
|
|
notification_type="sms",
|
2018-06-29 16:40:24 +01:00
|
|
|
service=None,
|
|
|
|
|
template=None,
|
|
|
|
|
job=None,
|
2023-08-29 14:54:30 -07:00
|
|
|
key_type="normal",
|
|
|
|
|
notification_status="delivered",
|
|
|
|
|
count=1,
|
2018-06-29 16:40:24 +01:00
|
|
|
):
|
2018-12-12 12:57:04 +00:00
|
|
|
if job:
|
|
|
|
|
template = job.template
|
2018-07-03 14:36:53 +01:00
|
|
|
if template:
|
|
|
|
|
service = template.service
|
|
|
|
|
notification_type = template.template_type
|
|
|
|
|
else:
|
|
|
|
|
if not service:
|
|
|
|
|
service = create_service()
|
2018-06-29 16:40:24 +01:00
|
|
|
template = create_template(service=service, template_type=notification_type)
|
|
|
|
|
|
|
|
|
|
data = FactNotificationStatus(
|
2022-11-21 11:49:59 -05:00
|
|
|
local_date=local_date,
|
2018-06-29 16:40:24 +01:00
|
|
|
template_id=template.id,
|
|
|
|
|
service_id=service.id,
|
|
|
|
|
job_id=job.id if job else uuid.UUID(int=0),
|
|
|
|
|
notification_type=notification_type,
|
|
|
|
|
key_type=key_type,
|
|
|
|
|
notification_status=notification_status,
|
2023-08-29 14:54:30 -07:00
|
|
|
notification_count=count,
|
2018-06-29 16:40:24 +01:00
|
|
|
)
|
|
|
|
|
db.session.add(data)
|
|
|
|
|
db.session.commit()
|
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
def create_process_time(
|
|
|
|
|
local_date="2021-03-01", messages_total=35, messages_within_10_secs=34
|
|
|
|
|
):
|
2021-03-10 11:12:29 +00:00
|
|
|
data = FactProcessingTime(
|
2022-11-21 11:49:59 -05:00
|
|
|
local_date=local_date,
|
2021-03-10 11:12:29 +00:00
|
|
|
messages_total=messages_total,
|
2023-08-29 14:54:30 -07:00
|
|
|
messages_within_10_secs=messages_within_10_secs,
|
2021-03-10 11:12:29 +00:00
|
|
|
)
|
|
|
|
|
fact_processing_time_dao.insert_update_processing_time(data)
|
|
|
|
|
|
|
|
|
|
|
2020-07-28 11:22:19 +01:00
|
|
|
def create_service_guest_list(service, email_address=None, mobile_number=None):
|
2019-10-31 15:01:18 +00:00
|
|
|
if email_address:
|
2023-08-29 14:54:30 -07:00
|
|
|
guest_list_user = ServiceGuestList.from_string(
|
|
|
|
|
service.id, EMAIL_TYPE, email_address
|
|
|
|
|
)
|
2019-10-31 15:01:18 +00:00
|
|
|
elif mobile_number:
|
2023-08-29 14:54:30 -07:00
|
|
|
guest_list_user = ServiceGuestList.from_string(
|
|
|
|
|
service.id, MOBILE_TYPE, mobile_number
|
|
|
|
|
)
|
2019-10-31 15:01:18 +00:00
|
|
|
else:
|
2023-08-29 14:54:30 -07:00
|
|
|
guest_list_user = ServiceGuestList.from_string(
|
|
|
|
|
service.id, EMAIL_TYPE, "guest_list_user@digital.fake.gov"
|
|
|
|
|
)
|
2019-10-31 15:01:18 +00:00
|
|
|
|
2020-07-28 11:22:19 +01:00
|
|
|
db.session.add(guest_list_user)
|
2019-10-31 15:01:18 +00:00
|
|
|
db.session.commit()
|
2020-07-28 11:22:19 +01:00
|
|
|
return guest_list_user
|
2019-10-31 15:01:18 +00:00
|
|
|
|
|
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
def create_complaint(service=None, notification=None, created_at=None):
|
2018-06-05 14:25:24 +01:00
|
|
|
if not service:
|
2018-06-05 17:23:24 +01:00
|
|
|
service = create_service()
|
2018-06-05 14:25:24 +01:00
|
|
|
if not notification:
|
2023-08-29 14:54:30 -07:00
|
|
|
template = create_template(service=service, template_type="email")
|
2018-06-05 14:25:24 +01:00
|
|
|
notification = create_notification(template=template)
|
|
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
complaint = Complaint(
|
|
|
|
|
notification_id=notification.id,
|
|
|
|
|
service_id=service.id,
|
|
|
|
|
ses_feedback_id=str(uuid.uuid4()),
|
|
|
|
|
complaint_type="abuse",
|
|
|
|
|
complaint_date=datetime.utcnow(),
|
|
|
|
|
created_at=created_at if created_at else datetime.now(),
|
|
|
|
|
)
|
2018-06-05 14:25:24 +01:00
|
|
|
db.session.add(complaint)
|
|
|
|
|
db.session.commit()
|
|
|
|
|
return complaint
|
|
|
|
|
|
|
|
|
|
|
2018-06-04 17:29:58 +01:00
|
|
|
def ses_complaint_callback_malformed_message_id():
|
2018-06-05 17:23:24 +01:00
|
|
|
return {
|
2023-08-29 14:54:30 -07:00
|
|
|
"Signature": "bb",
|
|
|
|
|
"SignatureVersion": "1",
|
|
|
|
|
"MessageAttributes": {},
|
|
|
|
|
"MessageId": "98c6e927-af5d-5f3b-9522-bab736f2cbde",
|
|
|
|
|
"UnsubscribeUrl": "https://sns.test-region.amazonaws.com",
|
|
|
|
|
"TopicArn": "arn:ses_notifications",
|
|
|
|
|
"Type": "Notification",
|
|
|
|
|
"Timestamp": "2018-06-05T14:00:15.952Z",
|
|
|
|
|
"Subject": None,
|
|
|
|
|
"Message": '{"notificationType":"Complaint","complaint":{"complainedRecipients":[{"emailAddress":"recipient1@example.com"}],"timestamp":"2018-06-05T13:59:58.000Z","feedbackId":"ses_feedback_id"},"mail":{"timestamp":"2018-06-05T14:00:15.950Z","source":"\\"Some Service\\" <someservicenotifications.service.gov.uk>","sourceArn":"arn:identity/notifications.service.gov.uk","sourceIp":"52.208.24.161","sendingAccountId":"888450439860","badMessageId":"ref1","destination":["recipient1@example.com"]}}', # noqa
|
|
|
|
|
"SigningCertUrl": "https://sns.pem",
|
2018-06-05 17:23:24 +01:00
|
|
|
}
|
2018-06-04 17:29:58 +01:00
|
|
|
|
2018-06-06 10:37:31 +01:00
|
|
|
|
2018-06-04 17:29:58 +01:00
|
|
|
def ses_complaint_callback_with_missing_complaint_type():
|
|
|
|
|
"""
|
|
|
|
|
https://docs.aws.amazon.com/ses/latest/DeveloperGuide/notification-contents.html#complaint-object
|
|
|
|
|
"""
|
2018-06-05 17:23:24 +01:00
|
|
|
return {
|
2023-08-29 14:54:30 -07:00
|
|
|
"Signature": "bb",
|
|
|
|
|
"SignatureVersion": "1",
|
|
|
|
|
"MessageAttributes": {},
|
|
|
|
|
"MessageId": "98c6e927-af5d-5f3b-9522-bab736f2cbde",
|
|
|
|
|
"UnsubscribeUrl": "https://sns.test-region.amazonaws.com",
|
|
|
|
|
"TopicArn": "arn:ses_notifications",
|
|
|
|
|
"Type": "Notification",
|
|
|
|
|
"Timestamp": "2018-06-05T14:00:15.952Z",
|
|
|
|
|
"Subject": None,
|
|
|
|
|
"Message": '{"notificationType":"Complaint","complaint":{"complainedRecipients":[{"emailAddress":"recipient1@example.com"}],"timestamp":"2018-06-05T13:59:58.000Z","feedbackId":"ses_feedback_id"},"mail":{"timestamp":"2018-06-05T14:00:15.950Z","source":"\\"Some Service\\" <someservicenotifications.service.gov.uk>","sourceArn":"arn:identity/notifications.service.gov.uk","sourceIp":"52.208.24.161","sendingAccountId":"888450439860","messageId":"ref1","destination":["recipient1@example.com"]}}', # noqa
|
|
|
|
|
"SigningCertUrl": "https://sns.pem",
|
2018-06-05 17:23:24 +01:00
|
|
|
}
|
2018-06-04 17:29:58 +01:00
|
|
|
|
2018-06-06 10:37:31 +01:00
|
|
|
|
2018-06-04 17:29:58 +01:00
|
|
|
def ses_complaint_callback():
|
|
|
|
|
"""
|
|
|
|
|
https://docs.aws.amazon.com/ses/latest/DeveloperGuide/notification-contents.html#complaint-object
|
|
|
|
|
"""
|
2018-06-05 17:23:24 +01:00
|
|
|
return {
|
2023-08-29 14:54:30 -07:00
|
|
|
"Signature": "bb",
|
|
|
|
|
"SignatureVersion": "1",
|
|
|
|
|
"MessageAttributes": {},
|
|
|
|
|
"MessageId": "98c6e927-af5d-5f3b-9522-bab736f2cbde",
|
|
|
|
|
"UnsubscribeUrl": "https://sns.test-region.amazonaws.com",
|
|
|
|
|
"TopicArn": "arn:ses_notifications",
|
|
|
|
|
"Type": "Notification",
|
|
|
|
|
"Timestamp": "2018-06-05T14:00:15.952Z",
|
|
|
|
|
"Subject": None,
|
|
|
|
|
"Message": '{"notificationType":"Complaint","complaint":{"complaintFeedbackType": "abuse", "complainedRecipients":[{"emailAddress":"recipient1@example.com"}],"timestamp":"2018-06-05T13:59:58.000Z","feedbackId":"ses_feedback_id"},"mail":{"timestamp":"2018-06-05T14:00:15.950Z","source":"\\"Some Service\\" <someservicenotifications.service.gov.uk>","sourceArn":"arn:identity/notifications.service.gov.uk","sourceIp":"52.208.24.161","sendingAccountId":"888450439860","messageId":"ref1","destination":["recipient1@example.com"]}}', # noqa
|
|
|
|
|
"SigningCertUrl": "https://sns.pem",
|
2018-06-05 17:23:24 +01:00
|
|
|
}
|
2018-06-04 17:29:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def ses_notification_callback():
|
2023-08-29 14:54:30 -07:00
|
|
|
return (
|
|
|
|
|
'{\n "Type" : "Notification",\n "MessageId" : "ref1",'
|
|
|
|
|
'\n "TopicArn" : "arn:aws:sns:test-region:123456789012:testing",'
|
|
|
|
|
'\n "Message" : "{\\"notificationType\\":\\"Delivery\\",'
|
|
|
|
|
'\\"mail\\":{\\"timestamp\\":\\"2016-03-14T12:35:25.909Z\\",'
|
|
|
|
|
'\\"source\\":\\"test@test-domain.com\\",'
|
|
|
|
|
'\\"sourceArn\\":\\"arn:aws:ses:test-region:123456789012:identity/testing-notify\\",'
|
|
|
|
|
'\\"sendingAccountId\\":\\"123456789012\\",'
|
|
|
|
|
'\\"messageId\\":\\"ref1\\",'
|
|
|
|
|
'\\"destination\\":[\\"testing@testing.gov\\"]},'
|
|
|
|
|
'\\"delivery\\":{\\"timestamp\\":\\"2016-03-14T12:35:26.567Z\\",'
|
|
|
|
|
'\\"processingTimeMillis\\":658,'
|
|
|
|
|
'\\"recipients\\":[\\"testing@testing.gov\\"],'
|
|
|
|
|
'\\"smtpResponse\\":\\"250 2.0.0 OK 1457958926 uo5si26480932wjc.221 - gsmtp\\",'
|
|
|
|
|
'\\"reportingMTA\\":\\"a6-238.smtp-out.test-region.amazonses.com\\"}}",'
|
|
|
|
|
'\n "Timestamp" : "2016-03-14T12:35:26.665Z",\n "SignatureVersion" : "1",'
|
|
|
|
|
'\n "Signature" : "asdfasdfhsdhfkljashdfklashdfklhaskldfjh",'
|
|
|
|
|
'\n "SigningCertURL" : "https://sns.test-region.amazonaws.com/",'
|
|
|
|
|
'\n "UnsubscribeURL" : "https://sns.test-region.amazonaws.com/"\n}'
|
|
|
|
|
)
|
2018-07-11 17:02:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_service_data_retention(
|
2023-08-29 14:54:30 -07:00
|
|
|
service, notification_type="sms", days_of_retention=3
|
2018-07-11 17:02:49 +01:00
|
|
|
):
|
|
|
|
|
data_retention = insert_service_data_retention(
|
2019-06-03 17:27:08 +01:00
|
|
|
service_id=service.id,
|
2018-07-11 17:02:49 +01:00
|
|
|
notification_type=notification_type,
|
2023-08-29 14:54:30 -07:00
|
|
|
days_of_retention=days_of_retention,
|
2018-07-11 17:02:49 +01:00
|
|
|
)
|
|
|
|
|
return data_retention
|
2018-09-17 15:45:29 +01:00
|
|
|
|
|
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
def create_invited_user(service=None, to_email_address=None):
|
2018-09-17 15:45:29 +01:00
|
|
|
if service is None:
|
|
|
|
|
service = create_service()
|
|
|
|
|
if to_email_address is None:
|
2023-08-29 14:54:30 -07:00
|
|
|
to_email_address = "invited_user@digital.fake.gov"
|
2018-09-17 15:45:29 +01:00
|
|
|
|
|
|
|
|
from_user = service.users[0]
|
|
|
|
|
|
|
|
|
|
data = {
|
2023-08-29 14:54:30 -07:00
|
|
|
"service": service,
|
|
|
|
|
"email_address": to_email_address,
|
|
|
|
|
"from_user": from_user,
|
|
|
|
|
"permissions": "send_messages,manage_service,manage_api_keys",
|
|
|
|
|
"folder_permissions": [str(uuid.uuid4()), str(uuid.uuid4())],
|
2018-09-17 15:45:29 +01:00
|
|
|
}
|
|
|
|
|
invited_user = InvitedUser(**data)
|
|
|
|
|
save_invited_user(invited_user)
|
|
|
|
|
return invited_user
|
2018-10-30 16:26:25 +00:00
|
|
|
|
|
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
def create_template_folder(service, name="foo", parent=None):
|
2018-10-30 16:26:25 +00:00
|
|
|
tf = TemplateFolder(name=name, service=service, parent=parent)
|
|
|
|
|
db.session.add(tf)
|
|
|
|
|
db.session.commit()
|
|
|
|
|
return tf
|
2019-01-22 17:27:00 +00:00
|
|
|
|
|
|
|
|
|
2019-08-22 17:48:24 +01:00
|
|
|
def set_up_usage_data(start_date):
|
2023-08-29 14:54:30 -07:00
|
|
|
year = int(start_date.strftime("%Y"))
|
2019-08-22 17:48:24 +01:00
|
|
|
one_week_earlier = start_date - timedelta(days=7)
|
|
|
|
|
two_days_later = start_date + timedelta(days=2)
|
|
|
|
|
one_week_later = start_date + timedelta(days=7)
|
2023-03-02 20:20:31 -05:00
|
|
|
# one_month_later = start_date + timedelta(days=31)
|
2019-08-22 17:48:24 +01:00
|
|
|
|
2021-03-10 17:00:26 +00:00
|
|
|
# service with sms and letters:
|
2021-03-08 17:44:26 +00:00
|
|
|
service_1_sms_and_letter = create_service(
|
2023-08-29 14:54:30 -07:00
|
|
|
service_name="a - with sms and letter",
|
2021-02-23 18:37:05 +00:00
|
|
|
purchase_order_number="service purchase order number",
|
|
|
|
|
billing_contact_names="service billing contact names",
|
|
|
|
|
billing_contact_email_addresses="service@billing.contact email@addresses.gov.uk",
|
2023-08-29 14:54:30 -07:00
|
|
|
billing_reference="service billing reference",
|
|
|
|
|
)
|
|
|
|
|
sms_template_1 = create_template(
|
|
|
|
|
service=service_1_sms_and_letter, template_type="sms"
|
2021-02-23 18:37:05 +00:00
|
|
|
)
|
2021-03-08 17:44:26 +00:00
|
|
|
create_annual_billing(
|
2023-08-29 14:54:30 -07:00
|
|
|
service_id=service_1_sms_and_letter.id,
|
|
|
|
|
free_sms_fragment_limit=10,
|
|
|
|
|
financial_year_start=year,
|
2021-03-08 17:44:26 +00:00
|
|
|
)
|
2023-07-10 11:06:29 -07:00
|
|
|
org_1 = create_organization(
|
2021-03-08 17:44:26 +00:00
|
|
|
name="Org for {}".format(service_1_sms_and_letter.name),
|
2021-02-23 18:37:05 +00:00
|
|
|
purchase_order_number="org1 purchase order number",
|
|
|
|
|
billing_contact_names="org1 billing contact names",
|
|
|
|
|
billing_contact_email_addresses="org1@billing.contact email@addresses.gov.uk",
|
2023-08-29 14:54:30 -07:00
|
|
|
billing_reference="org1 billing reference",
|
2021-02-23 18:37:05 +00:00
|
|
|
)
|
2023-07-10 11:06:29 -07:00
|
|
|
dao_add_service_to_organization(
|
2023-08-29 14:54:30 -07:00
|
|
|
service=service_1_sms_and_letter, organization_id=org_1.id
|
2021-03-08 17:44:26 +00:00
|
|
|
)
|
2019-08-22 17:48:24 +01:00
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
create_ft_billing(
|
|
|
|
|
local_date=one_week_earlier, template=sms_template_1, billable_unit=2, rate=0.11
|
|
|
|
|
)
|
|
|
|
|
create_ft_billing(
|
|
|
|
|
local_date=start_date, template=sms_template_1, billable_unit=2, rate=0.11
|
|
|
|
|
)
|
|
|
|
|
create_ft_billing(
|
|
|
|
|
local_date=two_days_later, template=sms_template_1, billable_unit=1, rate=0.11
|
|
|
|
|
)
|
2021-03-10 18:05:35 +00:00
|
|
|
|
2021-03-10 17:00:26 +00:00
|
|
|
# service with emails only:
|
2023-08-29 14:54:30 -07:00
|
|
|
service_with_emails = create_service(service_name="b - emails")
|
|
|
|
|
email_template = create_template(service=service_with_emails, template_type="email")
|
2023-07-10 11:06:29 -07:00
|
|
|
org_2 = create_organization(
|
2023-08-29 14:54:30 -07:00
|
|
|
name="Org for {}".format(service_with_emails.name),
|
|
|
|
|
)
|
|
|
|
|
dao_add_service_to_organization(
|
|
|
|
|
service=service_with_emails, organization_id=org_2.id
|
|
|
|
|
)
|
|
|
|
|
create_annual_billing(
|
|
|
|
|
service_id=service_with_emails.id,
|
|
|
|
|
free_sms_fragment_limit=0,
|
|
|
|
|
financial_year_start=year,
|
2021-02-23 18:37:05 +00:00
|
|
|
)
|
2020-02-17 16:34:17 +00:00
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
create_ft_billing(
|
|
|
|
|
local_date=start_date, template=email_template, notifications_sent=10
|
|
|
|
|
)
|
2021-03-10 18:05:35 +00:00
|
|
|
|
2023-07-10 11:06:29 -07:00
|
|
|
# service with chargeable SMS, without an organization
|
2021-03-08 17:44:26 +00:00
|
|
|
service_with_sms_without_org = create_service(
|
2023-08-29 14:54:30 -07:00
|
|
|
service_name="b - chargeable sms",
|
2021-02-23 18:37:05 +00:00
|
|
|
purchase_order_number="sms purchase order number",
|
|
|
|
|
billing_contact_names="sms billing contact names",
|
|
|
|
|
billing_contact_email_addresses="sms@billing.contact email@addresses.gov.uk",
|
2023-08-29 14:54:30 -07:00
|
|
|
billing_reference="sms billing reference",
|
|
|
|
|
)
|
|
|
|
|
sms_template = create_template(
|
|
|
|
|
service=service_with_sms_without_org, template_type="sms"
|
2021-02-23 18:37:05 +00:00
|
|
|
)
|
2021-03-08 17:44:26 +00:00
|
|
|
create_annual_billing(
|
2023-08-29 14:54:30 -07:00
|
|
|
service_id=service_with_sms_without_org.id,
|
|
|
|
|
free_sms_fragment_limit=10,
|
|
|
|
|
financial_year_start=year,
|
|
|
|
|
)
|
|
|
|
|
create_ft_billing(
|
|
|
|
|
local_date=one_week_earlier, template=sms_template, rate=0.11, billable_unit=12
|
2021-03-08 17:44:26 +00:00
|
|
|
)
|
2022-11-21 11:49:59 -05:00
|
|
|
create_ft_billing(local_date=two_days_later, template=sms_template, rate=0.11)
|
2023-08-29 14:54:30 -07:00
|
|
|
create_ft_billing(
|
|
|
|
|
local_date=one_week_later, template=sms_template, billable_unit=2, rate=0.11
|
|
|
|
|
)
|
2019-08-22 17:48:24 +01:00
|
|
|
|
2021-03-10 17:00:26 +00:00
|
|
|
# service with SMS within free allowance
|
|
|
|
|
service_with_sms_within_allowance = create_service(
|
2023-08-29 14:54:30 -07:00
|
|
|
service_name="e - sms within allowance"
|
|
|
|
|
)
|
|
|
|
|
sms_template_2 = create_template(
|
|
|
|
|
service=service_with_sms_within_allowance, template_type="sms"
|
2021-03-10 17:00:26 +00:00
|
|
|
)
|
|
|
|
|
create_annual_billing(
|
2023-08-29 14:54:30 -07:00
|
|
|
service_id=service_with_sms_within_allowance.id,
|
|
|
|
|
free_sms_fragment_limit=10,
|
|
|
|
|
financial_year_start=year,
|
|
|
|
|
)
|
|
|
|
|
create_ft_billing(
|
|
|
|
|
local_date=one_week_later, template=sms_template_2, billable_unit=2, rate=0.11
|
2021-03-10 17:00:26 +00:00
|
|
|
)
|
|
|
|
|
|
2022-01-11 08:46:46 +00:00
|
|
|
# service without ft_billing this year
|
|
|
|
|
service_with_out_ft_billing_this_year = create_service(
|
2023-08-29 14:54:30 -07:00
|
|
|
service_name="f - without ft_billing",
|
2022-01-11 08:46:46 +00:00
|
|
|
purchase_order_number="sms purchase order number",
|
|
|
|
|
billing_contact_names="sms billing contact names",
|
|
|
|
|
billing_contact_email_addresses="sms@billing.contact email@addresses.gov.uk",
|
2023-08-29 14:54:30 -07:00
|
|
|
billing_reference="sms billing reference",
|
2022-01-11 08:46:46 +00:00
|
|
|
)
|
|
|
|
|
create_annual_billing(
|
2023-08-29 14:54:30 -07:00
|
|
|
service_id=service_with_out_ft_billing_this_year.id,
|
|
|
|
|
free_sms_fragment_limit=10,
|
|
|
|
|
financial_year_start=year,
|
|
|
|
|
)
|
|
|
|
|
dao_add_service_to_organization(
|
|
|
|
|
service=service_with_out_ft_billing_this_year, organization_id=org_1.id
|
2022-01-11 08:46:46 +00:00
|
|
|
)
|
|
|
|
|
|
2021-03-10 18:05:35 +00:00
|
|
|
# dictionary with services and orgs to return
|
2021-03-08 17:44:26 +00:00
|
|
|
return {
|
|
|
|
|
"org_1": org_1,
|
|
|
|
|
"service_1_sms_and_letter": service_1_sms_and_letter,
|
|
|
|
|
"org_2": org_2,
|
|
|
|
|
"service_with_emails": service_with_emails,
|
2021-03-10 18:05:35 +00:00
|
|
|
"service_with_sms_without_org": service_with_sms_without_org,
|
|
|
|
|
"service_with_sms_within_allowance": service_with_sms_within_allowance,
|
2022-01-11 08:46:46 +00:00
|
|
|
"service_with_out_ft_billing_this_year": service_with_out_ft_billing_this_year,
|
2021-03-08 17:44:26 +00:00
|
|
|
}
|
2019-12-09 17:27:18 +00:00
|
|
|
|
|
|
|
|
|
2021-05-10 22:09:07 +01:00
|
|
|
def create_webauthn_credential(
|
|
|
|
|
user,
|
2023-08-29 14:54:30 -07:00
|
|
|
name="my key",
|
2021-05-10 22:09:07 +01:00
|
|
|
*,
|
2023-08-29 14:54:30 -07:00
|
|
|
credential_data="ABC123",
|
|
|
|
|
registration_response="DEF456",
|
2021-05-10 22:09:07 +01:00
|
|
|
):
|
|
|
|
|
webauthn_credential = WebauthnCredential(
|
|
|
|
|
user=user,
|
|
|
|
|
name=name,
|
|
|
|
|
credential_data=credential_data,
|
2023-08-29 14:54:30 -07:00
|
|
|
registration_response=registration_response,
|
2021-05-10 22:09:07 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
db.session.add(webauthn_credential)
|
|
|
|
|
db.session.commit()
|
|
|
|
|
return webauthn_credential
|