mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 09:26:08 -05:00
Fixed another 30 tests
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
from flask import Blueprint, jsonify, request
|
from flask import Blueprint, jsonify, request
|
||||||
|
|
||||||
|
from app import db
|
||||||
from app.dao.events_dao import dao_create_event
|
from app.dao.events_dao import dao_create_event
|
||||||
from app.errors import register_errors
|
from app.errors import register_errors
|
||||||
from app.schemas import event_schema
|
from app.schemas import event_schema
|
||||||
@@ -11,6 +12,6 @@ register_errors(events)
|
|||||||
@events.route("", methods=["POST"])
|
@events.route("", methods=["POST"])
|
||||||
def create_event():
|
def create_event():
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
event = event_schema.load(data)
|
event = event_schema.load(data, session=db.session)
|
||||||
dao_create_event(event)
|
dao_create_event(event)
|
||||||
return jsonify(data=event_schema.dump(event)), 201
|
return jsonify(data=event_schema.dump(event)), 201
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ from zoneinfo import ZoneInfo
|
|||||||
import dateutil
|
import dateutil
|
||||||
from flask import Blueprint, current_app, jsonify, request
|
from flask import Blueprint, current_app, jsonify, request
|
||||||
|
|
||||||
|
from app import db
|
||||||
from app.aws.s3 import (
|
from app.aws.s3 import (
|
||||||
get_job_metadata_from_s3,
|
get_job_metadata_from_s3,
|
||||||
get_personalisation_from_s3,
|
get_personalisation_from_s3,
|
||||||
@@ -30,10 +31,10 @@ from app.dao.templates_dao import dao_get_template_by_id
|
|||||||
from app.enums import JobStatus
|
from app.enums import JobStatus
|
||||||
from app.errors import InvalidRequest, register_errors
|
from app.errors import InvalidRequest, register_errors
|
||||||
from app.schemas import (
|
from app.schemas import (
|
||||||
job_schema,
|
JobSchema,
|
||||||
|
UnarchivedTemplateSchema,
|
||||||
notification_with_template_schema,
|
notification_with_template_schema,
|
||||||
notifications_filter_schema,
|
notifications_filter_schema,
|
||||||
unarchived_template_schema,
|
|
||||||
)
|
)
|
||||||
from app.utils import midnight_n_days_ago, pagination_links
|
from app.utils import midnight_n_days_ago, pagination_links
|
||||||
|
|
||||||
@@ -47,7 +48,7 @@ register_errors(job_blueprint)
|
|||||||
def get_job_by_service_and_job_id(service_id, job_id):
|
def get_job_by_service_and_job_id(service_id, job_id):
|
||||||
job = dao_get_job_by_service_id_and_job_id(service_id, job_id)
|
job = dao_get_job_by_service_id_and_job_id(service_id, job_id)
|
||||||
statistics = dao_get_notification_outcomes_for_job(service_id, job_id)
|
statistics = dao_get_notification_outcomes_for_job(service_id, job_id)
|
||||||
data = job_schema.dump(job)
|
data = JobSchema(session=db.session).dump(job)
|
||||||
|
|
||||||
data["statistics"] = [
|
data["statistics"] = [
|
||||||
{"status": statistic[1], "count": statistic[0]} for statistic in statistics
|
{"status": statistic[1], "count": statistic[0]} for statistic in statistics
|
||||||
@@ -257,14 +258,15 @@ def create_job(service_id):
|
|||||||
if data.get("valid") != "True":
|
if data.get("valid") != "True":
|
||||||
raise InvalidRequest("File is not valid, can't create job", 400)
|
raise InvalidRequest("File is not valid, can't create job", 400)
|
||||||
|
|
||||||
errors = unarchived_template_schema.validate({"archived": template.archived})
|
schema = UnarchivedTemplateSchema(session=db.session)
|
||||||
|
errors = schema.validate({"archived": template.archived})
|
||||||
|
|
||||||
if errors:
|
if errors:
|
||||||
raise InvalidRequest(errors, status_code=400)
|
raise InvalidRequest(errors, status_code=400)
|
||||||
|
|
||||||
data.update({"template_version": template.version})
|
data.update({"template_version": template.version})
|
||||||
|
|
||||||
job = job_schema.load(data)
|
job = JobSchema(session=db.session).load(data)
|
||||||
# See admin #1148, for whatever reason schema loading doesn't load this
|
# See admin #1148, for whatever reason schema loading doesn't load this
|
||||||
if original_file_name is not None:
|
if original_file_name is not None:
|
||||||
job.original_file_name = original_file_name
|
job.original_file_name = original_file_name
|
||||||
@@ -281,7 +283,7 @@ def create_job(service_id):
|
|||||||
[str(job.id)], {"sender_id": sender_id}, queue=QueueNames.JOBS
|
[str(job.id)], {"sender_id": sender_id}, queue=QueueNames.JOBS
|
||||||
)
|
)
|
||||||
|
|
||||||
job_json = job_schema.dump(job)
|
job_json = JobSchema(session=db.session).dump(job)
|
||||||
job_json["statistics"] = []
|
job_json["statistics"] = []
|
||||||
|
|
||||||
return jsonify(data=job_json), 201
|
return jsonify(data=job_json), 201
|
||||||
@@ -317,7 +319,7 @@ def get_paginated_jobs(
|
|||||||
page_size=current_app.config["PAGE_SIZE"],
|
page_size=current_app.config["PAGE_SIZE"],
|
||||||
statuses=statuses,
|
statuses=statuses,
|
||||||
)
|
)
|
||||||
data = job_schema.dump(pagination.items, many=True)
|
data = JobSchema(session=db.session).dump(pagination.items, many=True)
|
||||||
for job_data in data:
|
for job_data in data:
|
||||||
start = job_data["processing_started"]
|
start = job_data["processing_started"]
|
||||||
start = dateutil.parser.parse(start).replace(tzinfo=None) if start else None
|
start = dateutil.parser.parse(start).replace(tzinfo=None) if start else None
|
||||||
|
|||||||
@@ -758,7 +758,6 @@ detailed_service_schema = DetailedServiceSchema()
|
|||||||
template_schema = TemplateSchema()
|
template_schema = TemplateSchema()
|
||||||
template_schema_no_detail = TemplateSchemaNoDetail()
|
template_schema_no_detail = TemplateSchemaNoDetail()
|
||||||
api_key_schema = ApiKeySchema()
|
api_key_schema = ApiKeySchema()
|
||||||
job_schema = JobSchema()
|
|
||||||
sms_template_notification_schema = SmsTemplateNotificationSchema()
|
sms_template_notification_schema = SmsTemplateNotificationSchema()
|
||||||
email_notification_schema = EmailNotificationSchema()
|
email_notification_schema = EmailNotificationSchema()
|
||||||
notification_schema = NotificationModelSchema()
|
notification_schema = NotificationModelSchema()
|
||||||
@@ -773,4 +772,3 @@ template_history_schema = TemplateHistorySchema()
|
|||||||
event_schema = EventSchema()
|
event_schema = EventSchema()
|
||||||
provider_details_schema = ProviderDetailsSchema()
|
provider_details_schema = ProviderDetailsSchema()
|
||||||
provider_details_history_schema = ProviderDetailsHistorySchema()
|
provider_details_history_schema = ProviderDetailsHistorySchema()
|
||||||
unarchived_template_schema = UnarchivedTemplateSchema()
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
from flask import Blueprint, jsonify, request
|
from flask import Blueprint, jsonify, request
|
||||||
from sqlalchemy.orm.exc import NoResultFound
|
from sqlalchemy.orm.exc import NoResultFound
|
||||||
|
|
||||||
|
from app import db
|
||||||
from app.dao.services_dao import dao_fetch_service_by_id
|
from app.dao.services_dao import dao_fetch_service_by_id
|
||||||
from app.dao.template_folder_dao import dao_get_template_folder_by_id_and_service_id
|
from app.dao.template_folder_dao import dao_get_template_folder_by_id_and_service_id
|
||||||
from app.dao.templates_dao import (
|
from app.dao.templates_dao import (
|
||||||
@@ -135,7 +136,8 @@ def update_template(service_id, template_id):
|
|||||||
errors = {"content": [message]}
|
errors = {"content": [message]}
|
||||||
raise InvalidRequest(errors, status_code=400)
|
raise InvalidRequest(errors, status_code=400)
|
||||||
|
|
||||||
update_dict = template_schema.load(updated_template)
|
update_dict = template_schema.load(updated_template, session=db.session)
|
||||||
|
|
||||||
if update_dict.archived:
|
if update_dict.archived:
|
||||||
update_dict.folder = None
|
update_dict.folder = None
|
||||||
dao_update_template(update_dict)
|
dao_update_template(update_dict)
|
||||||
|
|||||||
@@ -42,13 +42,13 @@ def url_with_token(data, url, config, base_url=None):
|
|||||||
return base_url + token
|
return base_url + token
|
||||||
|
|
||||||
|
|
||||||
def get_template_instance(template_dict, values_dict=None):
|
def get_template_instance(template, values=None):
|
||||||
from app.enums import TemplateType
|
from app.enums import TemplateType
|
||||||
|
|
||||||
return {
|
return {
|
||||||
TemplateType.SMS: SMSMessageTemplate,
|
TemplateType.SMS: SMSMessageTemplate,
|
||||||
TemplateType.EMAIL: HTMLEmailTemplate,
|
TemplateType.EMAIL: HTMLEmailTemplate,
|
||||||
}[template_dict["template_type"]](template_dict, values_dict)
|
}[template["template_type"]](template, values)
|
||||||
|
|
||||||
|
|
||||||
def template_model_to_dict(template):
|
def template_model_to_dict(template):
|
||||||
|
|||||||
Reference in New Issue
Block a user