Skip to content

Commit

Permalink
#1224 Marshmallow Upgrade (#1988)
Browse files Browse the repository at this point in the history
  • Loading branch information
mchlwellman authored Sep 11, 2024
1 parent 4768cd1 commit ecca087
Show file tree
Hide file tree
Showing 23 changed files with 979 additions and 941 deletions.
2 changes: 1 addition & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ fileignoreconfig:
- filename: app/notifications/process_notifications.py
checksum: ae4e31c6eb56d91ec80ae09d13baf4558cf461c65f08893b93fee43f036a17a7
- filename: poetry.lock
checksum: 345297bd6db4826ec387193ee102b8efcb8567a1333530d97932bd9df2f1ac59
checksum: 34d12acdf749363555c31add4e7e7afa9e2a27afd792bd98c85f331b87bd7112
version: "1.0"
2 changes: 1 addition & 1 deletion app/accept_invite/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def validate_invitation_token(

if invitation_type == 'service':
invited_user = get_invited_user_by_id(invited_user_id)
return jsonify(data=invited_user_schema.dump(invited_user).data), 200
return jsonify(data=invited_user_schema.dump(invited_user)), 200
elif invitation_type == 'organisation':
invited_user = dao_get_invited_organisation_user(invited_user_id)
return jsonify(data=invited_user.serialize()), 200
Expand Down
8 changes: 4 additions & 4 deletions app/communication_item/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def create_communication_item():
current_app.logger.exception(e)
raise

return communication_item_schema.dump(communication_item).data, 201
return communication_item_schema.dump(communication_item), 201


#############
Expand All @@ -80,7 +80,7 @@ def create_communication_item():
@communication_item_blueprint.route('', methods=['GET'])
def get_all_communication_items():
communication_items = db.session.scalars(select(CommunicationItem)).all()
return jsonify(data=communication_item_schema.dump(communication_items, many=True).data)
return jsonify(data=communication_item_schema.dump(communication_items, many=True))


@communication_item_blueprint.route('/<communication_item_id>', methods=['GET'])
Expand All @@ -97,7 +97,7 @@ def get_communication_item(communication_item_id):
]
}, 404

return communication_item_schema.dump(communication_item).data
return communication_item_schema.dump(communication_item)


#############
Expand Down Expand Up @@ -165,7 +165,7 @@ def partially_update_communication_item(communication_item_id):
current_app.logger.exception(e)
raise

return communication_item_schema.dump(communication_item).data, 200
return communication_item_schema.dump(communication_item), 200


#############
Expand Down
4 changes: 2 additions & 2 deletions app/events/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
@events.route('', methods=['POST'])
def create_event():
data = request.get_json()
event = event_schema.load(data).data
event = event_schema.load(data)
dao_create_event(event)
return jsonify(data=event_schema.dump(event).data), 201
return jsonify(data=event_schema.dump(event)), 201
10 changes: 5 additions & 5 deletions app/invite/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
@invite.route('', methods=['POST'])
def create_invited_user(service_id):
request_json = request.get_json()
invited_user, errors = invited_user_schema.load(request_json)
invited_user = invited_user_schema.load(request_json)
invited_user_instance = save_invited_user(invited_user)

template = dao_get_template_by_id(current_app.config['INVITATION_EMAIL_TEMPLATE_ID'])
Expand All @@ -46,15 +46,15 @@ def create_invited_user(service_id):

send_notification_to_queue(saved_notification, False, queue=QueueNames.NOTIFY)

invited_user_data = invited_user_schema.dump(invited_user).data
invited_user_data = invited_user_schema.dump(invited_user)
invited_user_data['id'] = invited_user_instance.id
return jsonify(data=invited_user_data), 201


@invite.route('', methods=['GET'])
def get_invited_users_by_service(service_id):
invited_users = get_invited_users_for_service(service_id)
return jsonify(data=invited_user_schema.dump(invited_users, many=True).data), 200
return jsonify(data=invited_user_schema.dump(invited_users, many=True)), 200


@invite.route('/<invited_user_id>', methods=['POST'])
Expand All @@ -63,11 +63,11 @@ def update_invited_user(
invited_user_id,
):
fetched = get_invited_user(service_id=service_id, invited_user_id=invited_user_id)
current_data = dict(invited_user_schema.dump(fetched).data.items())
current_data = dict(invited_user_schema.dump(fetched))
current_data.update(request.get_json())
fetched.status = current_data['status']
save_invited_user(fetched)
return jsonify(data=invited_user_schema.dump(fetched).data), 200
return jsonify(data=invited_user_schema.dump(fetched)), 200


def invited_user_url(
Expand Down
12 changes: 6 additions & 6 deletions app/job/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def get_job_by_service_and_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)
data = job_schema.dump(job).data
data = job_schema.dump(job)

data['statistics'] = [{'status': statistic[1], 'count': statistic[0]} for statistic in statistics]

Expand Down Expand Up @@ -80,7 +80,7 @@ def get_all_notifications_for_service_job(
service_id,
job_id,
):
data = notifications_filter_schema.load(request.args).data
data = notifications_filter_schema.load(request.args)
page = data['page'] if 'page' in data else 1
page_size = data['page_size'] if 'page_size' in data else current_app.config.get('PAGE_SIZE')
paginated_notifications = get_notifications_for_job(
Expand All @@ -95,7 +95,7 @@ def get_all_notifications_for_service_job(
if data.get('format_for_csv'):
notifications = [notification.serialize_for_csv() for notification in paginated_notifications.items]
else:
notifications = notification_with_template_schema.dump(paginated_notifications.items, many=True).data
notifications = notification_with_template_schema.dump(paginated_notifications.items, many=True)

return jsonify(
notifications=notifications,
Expand Down Expand Up @@ -152,7 +152,7 @@ def create_job(service_id):

data.update({'template_version': template.version})

job = job_schema.load(data).data
job = job_schema.load(data)

if job.scheduled_for:
job.job_status = JOB_STATUS_SCHEDULED
Expand All @@ -164,7 +164,7 @@ def create_job(service_id):
if job.job_status == JOB_STATUS_PENDING:
process_job.apply_async([str(job.id)], {'sender_id': sender_id}, queue=QueueNames.JOBS)

job_json = job_schema.dump(job).data
job_json = job_schema.dump(job)
job_json['statistics'] = []

return jsonify(data=job_json), 201
Expand All @@ -179,7 +179,7 @@ def get_paginated_jobs(
pagination = dao_get_jobs_by_service_id(
service_id, limit_days=limit_days, page=page, page_size=current_app.config['PAGE_SIZE'], statuses=statuses
)
data = job_schema.dump(pagination.items, many=True).data
data = job_schema.dump(pagination.items, many=True)
for job_data in data:
start = job_data['processing_started']
start = dateutil.parser.parse(start).replace(tzinfo=None) if start else None
Expand Down
21 changes: 11 additions & 10 deletions app/notifications/rest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from flask import Blueprint, jsonify, request, current_app
from marshmallow import ValidationError

from app import api_user, authenticated_service
from app.config import QueueNames
Expand Down Expand Up @@ -45,12 +46,12 @@ def get_notification_by_id(notification_id):
str(authenticated_service.id), notification_id, key_type=None
)

return jsonify(data={'notification': notification_with_personalisation_schema.dump(notification).data}), 200
return jsonify(data={'notification': notification_with_personalisation_schema.dump(notification)}), 200


@notifications.route('/notifications', methods=['GET'])
def get_all_notifications():
data = notifications_filter_schema.load(request.args).data
data = notifications_filter_schema.load(request.args)
include_jobs = data.get('include_jobs', False)
page = data.get('page', 1)
page_size = data.get('page_size', current_app.config.get('API_PAGE_SIZE'))
Expand All @@ -67,7 +68,7 @@ def get_all_notifications():
include_jobs=include_jobs,
)
return jsonify(
notifications=notification_with_personalisation_schema.dump(pagination.items, many=True).data,
notifications=notification_with_personalisation_schema.dump(pagination.items, many=True),
page_size=page_size,
total=pagination.total,
links=pagination_links(pagination, '.get_all_notifications', **request.args.to_dict()),
Expand All @@ -79,18 +80,18 @@ def send_notification(notification_type):
"""
Create a notification. This is a version 1 endpoint.
"""

if notification_type not in [SMS_TYPE, EMAIL_TYPE]:
msg = '{} notification type is not supported'.format(notification_type)
msg = msg + ', please use the latest version of the client' if notification_type == LETTER_TYPE else msg
raise InvalidRequest(msg, 400)

notification_form, errors = (
sms_template_notification_schema if notification_type == SMS_TYPE else email_notification_schema
).load(request.get_json())

if errors:
raise InvalidRequest(errors, status_code=400)
notification_form = None
try:
notification_form = (
sms_template_notification_schema if notification_type == SMS_TYPE else email_notification_schema
).load(request.get_json())
except ValidationError as e:
raise InvalidRequest(e.messages, status_code=400)

check_rate_limiting(authenticated_service, api_user)

Expand Down
2 changes: 1 addition & 1 deletion app/oauth/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def get_services_by_user(user_id):
if service_id not in permissions_by_service:
permissions_by_service[service_id] = []
permissions_by_service[service_id].append(user_permission.permission)
data = {'services': service_schema.dump(services, many=True).data, 'permissions': permissions_by_service}
data = {'services': service_schema.dump(services, many=True), 'permissions': permissions_by_service}
return jsonify(data=data)


Expand Down
6 changes: 3 additions & 3 deletions app/provider_details/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ def get_providers():

@provider_details.route('/<uuid:provider_details_id>', methods=['GET'])
def get_provider_by_id(provider_details_id):
data = provider_details_schema.dump(get_provider_details_by_id(provider_details_id)).data
data = provider_details_schema.dump(get_provider_details_by_id(provider_details_id))
return jsonify(provider_details=data)


@provider_details.route('/<uuid:provider_details_id>/versions', methods=['GET'])
def get_provider_versions(provider_details_id):
versions = dao_get_provider_versions(provider_details_id)
data = provider_details_history_schema.dump(versions, many=True).data
data = provider_details_history_schema.dump(versions, many=True)
return jsonify(data=data)


Expand All @@ -74,4 +74,4 @@ def update_provider_details(provider_details_id):
setattr(provider, key, req_json[key])
dao_update_provider_details(provider)

return jsonify(provider_details=provider_details_schema.dump(provider).data), 200
return jsonify(provider_details=provider_details_schema.dump(provider)), 200
Loading

0 comments on commit ecca087

Please sign in to comment.