mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-30 06:21:50 -05:00
add tests for letter api notifications
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import uuid
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from flask import current_app
|
||||
@@ -108,6 +109,8 @@ def dao_get_future_scheduled_job_by_id_and_service_id(job_id, service_id):
|
||||
|
||||
|
||||
def dao_create_job(job):
|
||||
if not job.id:
|
||||
job.id = uuid.uuid4()
|
||||
job_stats = JobStatistics(
|
||||
job_id=job.id,
|
||||
updated_at=datetime.utcnow()
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
from app import create_random_identifier
|
||||
from app.models import LETTER_TYPE, JOB_STATUS_READY_TO_SEND
|
||||
from app.models import LETTER_TYPE, JOB_STATUS_READY_TO_SEND, Job
|
||||
from app.dao.jobs_dao import dao_create_job
|
||||
from app.notifications.process_notifications import persist_notification
|
||||
from app.v2.errors import InvalidRequest
|
||||
|
||||
|
||||
def create_letter_api_job(template):
|
||||
service = template.service
|
||||
if not service.active:
|
||||
raise InvalidRequest('Create job is not allowed: service is inactive', 403)
|
||||
raise InvalidRequest('Service {} is inactive'.format(service.id), 403)
|
||||
if template.archived:
|
||||
raise InvalidRequest('Create job is not allowed: template is deleted', 400)
|
||||
|
||||
raise InvalidRequest('Template {} is deleted'.format(template.id), 400)
|
||||
|
||||
job = Job(
|
||||
original_file_name='letter submitted via api',
|
||||
@@ -21,13 +22,15 @@ def create_letter_api_job(template):
|
||||
created_by=None
|
||||
)
|
||||
dao_create_job(job)
|
||||
return job
|
||||
|
||||
|
||||
def create_letter_notification(letter_data, job, api_key):
|
||||
notification = persist_notification(
|
||||
template_id=job.template.id,
|
||||
template_version=job.template.version,
|
||||
recipient=letter_data['personalisation']['address line 1'], # or addressline1 or address_line_1?
|
||||
# we only accept addresses_with_underscores from the API (from CSV we also accept dashes, spaces etc)
|
||||
recipient=letter_data['personalisation']['address_line_1'],
|
||||
service=job.service,
|
||||
personalisation=letter_data['personalisation'],
|
||||
notification_type=LETTER_TYPE,
|
||||
|
||||
@@ -30,7 +30,7 @@ def url_with_token(data, url, config):
|
||||
def get_template_instance(template, values):
|
||||
from app.models import SMS_TYPE, EMAIL_TYPE, LETTER_TYPE
|
||||
return {
|
||||
SMS_TYPE: SMSMessageTemplate, EMAIL_TYPE: PlainTextEmailTemplate, LETTER_TYPE: LetterPreviewTemplate
|
||||
SMS_TYPE: SMSMessageTemplate, EMAIL_TYPE: PlainTextEmailTemplate, LETTER_TYPE: PlainTextEmailTemplate
|
||||
}[template['template_type']](template, values)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user