Replace how .dump is called

As with `.load`, only data is now returned instead of a tuple.
This commit is contained in:
Katie Smith
2022-05-25 11:35:44 +01:00
parent bd4f74b359
commit 8ae2b0bb31
13 changed files with 65 additions and 66 deletions
+1 -1
View File
@@ -13,4 +13,4 @@ def create_event():
data = request.get_json() data = request.get_json()
event = event_schema.load(data) event = event_schema.load(data)
dao_create_event(event) dao_create_event(event)
return jsonify(data=event_schema.dump(event).data), 201 return jsonify(data=event_schema.dump(event)), 201
+4 -4
View File
@@ -50,7 +50,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 data = job_schema.dump(job)
data['statistics'] = [{'status': statistic[1], 'count': statistic[0]} for statistic in statistics] data['statistics'] = [{'status': statistic[1], 'count': statistic[0]} for statistic in statistics]
@@ -97,7 +97,7 @@ def get_all_notifications_for_service_job(service_id, job_id):
if data.get('format_for_csv'): if data.get('format_for_csv'):
notifications = [notification.serialize_for_csv() for notification in paginated_notifications.items] notifications = [notification.serialize_for_csv() for notification in paginated_notifications.items]
else: 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( return jsonify(
notifications=notifications, notifications=notifications,
@@ -185,7 +185,7 @@ def create_job(service_id):
if job.job_status == JOB_STATUS_PENDING: if job.job_status == JOB_STATUS_PENDING:
process_job.apply_async([str(job.id)], {'sender_id': sender_id}, queue=QueueNames.JOBS) 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'] = [] job_json['statistics'] = []
return jsonify(data=job_json), 201 return jsonify(data=job_json), 201
@@ -219,7 +219,7 @@ def get_paginated_jobs(
statuses=statuses, statuses=statuses,
contact_list_id=contact_list_id, contact_list_id=contact_list_id,
) )
data = job_schema.dump(pagination.items, many=True).data data = job_schema.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
+2 -2
View File
@@ -43,7 +43,7 @@ def get_notification_by_id(notification_id):
str(authenticated_service.id), str(authenticated_service.id),
notification_id, notification_id,
key_type=None) 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']) @notifications.route('/notifications', methods=['GET'])
@@ -65,7 +65,7 @@ def get_all_notifications():
key_type=api_user.key_type, key_type=api_user.key_type,
include_jobs=include_jobs) include_jobs=include_jobs)
return jsonify( 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, page_size=page_size,
total=pagination.total, total=pagination.total,
links=pagination_links( links=pagination_links(
+3 -3
View File
@@ -37,7 +37,7 @@ def get_providers():
@provider_details.route('/<uuid:provider_details_id>', methods=['GET']) @provider_details.route('/<uuid:provider_details_id>', methods=['GET'])
def get_provider_by_id(provider_details_id): 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) return jsonify(provider_details=data)
@@ -47,7 +47,7 @@ def get_provider_versions(provider_details_id):
data = provider_details_history_schema.dump( data = provider_details_history_schema.dump(
versions, versions,
many=True many=True
).data )
return jsonify(data=data) return jsonify(data=data)
@@ -74,4 +74,4 @@ def update_provider_details(provider_details_id):
setattr(provider, key, req_json[key]) setattr(provider, key, req_json[key])
dao_update_provider_details(provider) 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
+2 -2
View File
@@ -66,7 +66,7 @@ class SerialisedTemplate(SerialisedModel):
version=version, version=version,
) )
template_dict = template_schema.dump(fetched_template).data template_dict = template_schema.dump(fetched_template)
db.session.commit() db.session.commit()
return {'data': template_dict} return {'data': template_dict}
@@ -98,7 +98,7 @@ class SerialisedService(SerialisedModel):
def get_dict(service_id): def get_dict(service_id):
from app.schemas import service_schema from app.schemas import service_schema
service_dict = service_schema.dump(dao_fetch_service_by_id(service_id)).data service_dict = service_schema.dump(dao_fetch_service_by_id(service_id))
db.session.commit() db.session.commit()
return {'data': service_dict} return {'data': service_dict}
+16 -16
View File
@@ -200,7 +200,7 @@ def get_services():
return result return result
else: else:
services = dao_fetch_all_services(only_active) services = dao_fetch_all_services(only_active)
data = service_schema.dump(services, many=True).data data = service_schema.dump(services, many=True)
return jsonify(data=data) return jsonify(data=data)
@@ -228,7 +228,7 @@ def get_service_by_id(service_id):
else: else:
fetched = dao_fetch_service_by_id(service_id) fetched = dao_fetch_service_by_id(service_id)
data = service_schema.dump(fetched).data data = service_schema.dump(fetched)
return jsonify(data=data) return jsonify(data=data)
@@ -262,7 +262,7 @@ def create_service():
dao_create_service(valid_service, user) dao_create_service(valid_service, user)
set_default_free_allowance_for_service(service=valid_service, year_start=None) set_default_free_allowance_for_service(service=valid_service, year_start=None)
return jsonify(data=service_schema.dump(valid_service).data), 201 return jsonify(data=service_schema.dump(valid_service)), 201
@service_blueprint.route('/<uuid:service_id>', methods=['POST']) @service_blueprint.route('/<uuid:service_id>', methods=['POST'])
@@ -271,7 +271,7 @@ def update_service(service_id):
fetched_service = dao_fetch_service_by_id(service_id) fetched_service = dao_fetch_service_by_id(service_id)
# Capture the status change here as Marshmallow changes this later # Capture the status change here as Marshmallow changes this later
service_going_live = fetched_service.restricted and not req_json.get('restricted', True) service_going_live = fetched_service.restricted and not req_json.get('restricted', True)
current_data = dict(service_schema.dump(fetched_service).data.items()) current_data = dict(service_schema.dump(fetched_service).items())
current_data.update(request.get_json()) current_data.update(request.get_json())
service = service_schema.load(current_data) service = service_schema.load(current_data)
@@ -295,7 +295,7 @@ def update_service(service_id):
include_user_fields=['name'] include_user_fields=['name']
) )
return jsonify(data=service_schema.dump(fetched_service).data), 200 return jsonify(data=service_schema.dump(fetched_service)), 200
@service_blueprint.route('/<uuid:service_id>/api-key', methods=['POST']) @service_blueprint.route('/<uuid:service_id>/api-key', methods=['POST'])
@@ -328,7 +328,7 @@ def get_api_keys(service_id, key_id=None):
error = "API key not found for id: {}".format(service_id) error = "API key not found for id: {}".format(service_id)
raise InvalidRequest(error, status_code=404) raise InvalidRequest(error, status_code=404)
return jsonify(apiKeys=api_key_schema.dump(api_keys, many=True).data), 200 return jsonify(apiKeys=api_key_schema.dump(api_keys, many=True)), 200
@service_blueprint.route('/<uuid:service_id>/users', methods=['GET']) @service_blueprint.route('/<uuid:service_id>/users', methods=['GET'])
@@ -356,7 +356,7 @@ def add_user_to_service(service_id, user_id):
folder_permissions = data.get('folder_permissions', []) folder_permissions = data.get('folder_permissions', [])
dao_add_user_to_service(service, user, permissions, folder_permissions) dao_add_user_to_service(service, user, permissions, folder_permissions)
data = service_schema.dump(service).data data = service_schema.dump(service)
return jsonify(data=data), 201 return jsonify(data=data), 201
@@ -389,12 +389,12 @@ def get_service_history(service_id):
) )
service_history = Service.get_history_model().query.filter_by(id=service_id).all() service_history = Service.get_history_model().query.filter_by(id=service_id).all()
service_data = service_history_schema.dump(service_history, many=True).data service_data = service_history_schema.dump(service_history, many=True)
api_key_history = ApiKey.get_history_model().query.filter_by(service_id=service_id).all() api_key_history = ApiKey.get_history_model().query.filter_by(service_id=service_id).all()
api_keys_data = api_key_history_schema.dump(api_key_history, many=True).data api_keys_data = api_key_history_schema.dump(api_key_history, many=True)
template_history = TemplateHistory.query.filter_by(service_id=service_id).all() template_history = TemplateHistory.query.filter_by(service_id=service_id).all()
template_data, errors = template_history_schema.dump(template_history, many=True) template_data = template_history_schema.dump(template_history, many=True)
data = { data = {
'service_history': service_data, 'service_history': service_data,
@@ -449,7 +449,7 @@ def get_all_notifications_for_service(service_id):
if data.get('format_for_csv'): if data.get('format_for_csv'):
notifications = [notification.serialize_for_csv() for notification in pagination.items] notifications = [notification.serialize_for_csv() for notification in pagination.items]
else: else:
notifications = notification_with_template_schema.dump(pagination.items, many=True).data notifications = notification_with_template_schema.dump(pagination.items, many=True)
# We try and get the next page of results to work out if we need provide a pagination link to the next page # We try and get the next page of results to work out if we need provide a pagination link to the next page
# in our response if it exists. Note, this could be done instead by changing `count_pages` in the previous # in our response if it exists. Note, this could be done instead by changing `count_pages` in the previous
@@ -491,7 +491,7 @@ def get_notification_for_service(service_id, notification_id):
key_type=None, key_type=None,
) )
return jsonify( return jsonify(
notification_with_template_schema.dump(notification).data, notification_with_template_schema.dump(notification),
), 200 ), 200
@@ -524,7 +524,7 @@ def cancel_notification_for_service(service_id, notification_id):
) )
return jsonify( return jsonify(
notification_with_template_schema.dump(updated_notification).data notification_with_template_schema.dump(updated_notification)
), 200 ), 200
@@ -556,7 +556,7 @@ def search_for_notification_by_to_field(service_id, search_term, statuses, notif
) )
return jsonify( return jsonify(
notifications=notification_with_template_schema.dump(results.items, many=True).data, notifications=notification_with_template_schema.dump(results.items, many=True),
links=get_prev_next_pagination_links( links=get_prev_next_pagination_links(
1, 1,
len(next_page_of_pagination.items), len(next_page_of_pagination.items),
@@ -597,7 +597,7 @@ def get_detailed_service(service_id, today_only=False):
service = dao_fetch_service_by_id(service_id) service = dao_fetch_service_by_id(service_id)
service.statistics = get_service_statistics(service_id, today_only) service.statistics = get_service_statistics(service_id, today_only)
return detailed_service_schema.dump(service).data return detailed_service_schema.dump(service)
def get_service_statistics(service_id, today_only, limit_days=7): def get_service_statistics(service_id, today_only, limit_days=7):
@@ -1172,5 +1172,5 @@ def set_as_broadcast_service(service_id):
provider_restriction=data["provider_restriction"] provider_restriction=data["provider_restriction"]
) )
data = service_schema.dump(service).data data = service_schema.dump(service)
return jsonify(data=data) return jsonify(data=data)
+7 -7
View File
@@ -58,30 +58,30 @@ def create_invited_user(service_id):
send_notification_to_queue(saved_notification, False, queue=QueueNames.NOTIFY) send_notification_to_queue(saved_notification, False, queue=QueueNames.NOTIFY)
return jsonify(data=invited_user_schema.dump(invited_user).data), 201 return jsonify(data=invited_user_schema.dump(invited_user)), 201
@service_invite.route('/service/<service_id>/invite', methods=['GET']) @service_invite.route('/service/<service_id>/invite', methods=['GET'])
def get_invited_users_by_service(service_id): def get_invited_users_by_service(service_id):
invited_users = get_invited_users_for_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
@service_invite.route('/service/<service_id>/invite/<invited_user_id>', methods=['GET']) @service_invite.route('/service/<service_id>/invite/<invited_user_id>', methods=['GET'])
def get_invited_user_by_service(service_id, invited_user_id): def get_invited_user_by_service(service_id, invited_user_id):
invited_user = get_invited_user_by_service_and_id(service_id, invited_user_id) invited_user = get_invited_user_by_service_and_id(service_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
@service_invite.route('/service/<service_id>/invite/<invited_user_id>', methods=['POST']) @service_invite.route('/service/<service_id>/invite/<invited_user_id>', methods=['POST'])
def update_invited_user(service_id, invited_user_id): def update_invited_user(service_id, invited_user_id):
fetched = get_invited_user_by_service_and_id(service_id=service_id, invited_user_id=invited_user_id) fetched = get_invited_user_by_service_and_id(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).items())
current_data.update(request.get_json()) current_data.update(request.get_json())
update_dict = invited_user_schema.load(current_data) update_dict = invited_user_schema.load(current_data)
save_invited_user(update_dict) save_invited_user(update_dict)
return jsonify(data=invited_user_schema.dump(fetched).data), 200 return jsonify(data=invited_user_schema.dump(fetched)), 200
def invited_user_url(invited_user_id, invite_link_host=None): def invited_user_url(invited_user_id, invite_link_host=None):
@@ -96,7 +96,7 @@ def invited_user_url(invited_user_id, invite_link_host=None):
@service_invite.route('/invite/service/<uuid:invited_user_id>', methods=['GET']) @service_invite.route('/invite/service/<uuid:invited_user_id>', methods=['GET'])
def get_invited_user(invited_user_id): def get_invited_user(invited_user_id):
invited_user = get_invited_user_by_id(invited_user_id) 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
@service_invite.route('/invite/service/<token>', methods=['GET']) @service_invite.route('/invite/service/<token>', methods=['GET'])
@@ -120,4 +120,4 @@ def validate_service_invitation_token(token):
raise InvalidRequest(errors, status_code=400) raise InvalidRequest(errors, status_code=400)
invited_user = get_invited_user_by_id(invited_user_id) 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
+12 -12
View File
@@ -111,7 +111,7 @@ def create_template(service_id):
dao_create_template(new_template) dao_create_template(new_template)
return jsonify(data=template_schema.dump(new_template).data), 201 return jsonify(data=template_schema.dump(new_template)), 201
@template_blueprint.route('/<uuid:template_id>', methods=['POST']) @template_blueprint.route('/<uuid:template_id>', methods=['POST'])
@@ -140,10 +140,10 @@ def update_template(service_id, template_id):
if "reply_to" in data: if "reply_to" in data:
check_reply_to(service_id, data.get("reply_to"), fetched_template.template_type) check_reply_to(service_id, data.get("reply_to"), fetched_template.template_type)
updated = dao_update_template_reply_to(template_id=template_id, reply_to=data.get("reply_to")) updated = dao_update_template_reply_to(template_id=template_id, reply_to=data.get("reply_to"))
return jsonify(data=template_schema.dump(updated).data), 200 return jsonify(data=template_schema.dump(updated)), 200
current_data = dict(template_schema.dump(fetched_template).data.items()) current_data = dict(template_schema.dump(fetched_template).items())
updated_template = dict(template_schema.dump(fetched_template).data.items()) updated_template = dict(template_schema.dump(fetched_template).items())
updated_template.update(data) updated_template.update(data)
# Check if there is a change to make. # Check if there is a change to make.
@@ -160,13 +160,13 @@ def update_template(service_id, template_id):
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)
return jsonify(data=template_schema.dump(update_dict).data), 200 return jsonify(data=template_schema.dump(update_dict)), 200
@template_blueprint.route('/precompiled', methods=['GET']) @template_blueprint.route('/precompiled', methods=['GET'])
def get_precompiled_template_for_service(service_id): def get_precompiled_template_for_service(service_id):
template = get_precompiled_letter_template(service_id) template = get_precompiled_letter_template(service_id)
template_dict = template_schema.dump(template).data template_dict = template_schema.dump(template)
return jsonify(template_dict), 200 return jsonify(template_dict), 200
@@ -175,23 +175,23 @@ def get_precompiled_template_for_service(service_id):
def get_all_templates_for_service(service_id): def get_all_templates_for_service(service_id):
templates = dao_get_all_templates_for_service(service_id=service_id) templates = dao_get_all_templates_for_service(service_id=service_id)
if str(request.args.get('detailed', True)) == 'True': if str(request.args.get('detailed', True)) == 'True':
data = template_schema.dump(templates, many=True).data data = template_schema.dump(templates, many=True)
else: else:
data = template_schema_no_detail.dump(templates, many=True).data data = template_schema_no_detail.dump(templates, many=True)
return jsonify(data=data) return jsonify(data=data)
@template_blueprint.route('/<uuid:template_id>', methods=['GET']) @template_blueprint.route('/<uuid:template_id>', methods=['GET'])
def get_template_by_id_and_service_id(service_id, template_id): def get_template_by_id_and_service_id(service_id, template_id):
fetched_template = dao_get_template_by_id_and_service_id(template_id=template_id, service_id=service_id) fetched_template = dao_get_template_by_id_and_service_id(template_id=template_id, service_id=service_id)
data = template_schema.dump(fetched_template).data data = template_schema.dump(fetched_template)
return jsonify(data=data) return jsonify(data=data)
@template_blueprint.route('/<uuid:template_id>/preview', methods=['GET']) @template_blueprint.route('/<uuid:template_id>/preview', methods=['GET'])
def preview_template_by_id_and_service_id(service_id, template_id): def preview_template_by_id_and_service_id(service_id, template_id):
fetched_template = dao_get_template_by_id_and_service_id(template_id=template_id, service_id=service_id) fetched_template = dao_get_template_by_id_and_service_id(template_id=template_id, service_id=service_id)
data = template_schema.dump(fetched_template).data data = template_schema.dump(fetched_template)
template_object = fetched_template._as_utils_template_with_personalisation( template_object = fetched_template._as_utils_template_with_personalisation(
request.args.to_dict() request.args.to_dict()
) )
@@ -217,7 +217,7 @@ def get_template_version(service_id, template_id, version):
service_id=service_id, service_id=service_id,
version=version version=version
) )
).data )
return jsonify(data=data) return jsonify(data=data)
@@ -226,7 +226,7 @@ def get_template_versions(service_id, template_id):
data = template_history_schema.dump( data = template_history_schema.dump(
dao_get_template_versions(service_id=service_id, template_id=template_id), dao_get_template_versions(service_id=service_id, template_id=template_id),
many=True many=True
).data )
return jsonify(data=data) return jsonify(data=data)
+1 -1
View File
@@ -91,7 +91,7 @@ def get_uploaded_letter_by_service_and_print_day(service_id, letter_print_date):
'notifications': notification_with_template_schema.dump( 'notifications': notification_with_template_schema.dump(
pagination.items, pagination.items,
many=True, many=True,
).data, ),
'page_size': pagination.per_page, 'page_size': pagination.per_page,
'total': pagination.total, 'total': pagination.total,
'links': pagination_links( 'links': pagination_links(
+4 -4
View File
@@ -811,8 +811,8 @@ def test_send_sms_to_provider_should_return_template_if_found_in_redis(
mocker, client, sample_template mocker, client, sample_template
): ):
from app.schemas import service_schema, template_schema from app.schemas import service_schema, template_schema
service_dict = service_schema.dump(sample_template.service).data service_dict = service_schema.dump(sample_template.service)
template_dict = template_schema.dump(sample_template).data template_dict = template_schema.dump(sample_template)
mocker.patch( mocker.patch(
'app.redis_store.get', 'app.redis_store.get',
@@ -846,8 +846,8 @@ def test_send_email_to_provider_should_return_template_if_found_in_redis(
mocker, client, sample_email_template mocker, client, sample_email_template
): ):
from app.schemas import service_schema, template_schema from app.schemas import service_schema, template_schema
service_dict = service_schema.dump(sample_email_template.service).data service_dict = service_schema.dump(sample_email_template.service)
template_dict = template_schema.dump(sample_email_template).data template_dict = template_schema.dump(sample_email_template)
mocker.patch( mocker.patch(
'app.redis_store.get', 'app.redis_store.get',
+2 -2
View File
@@ -88,7 +88,7 @@ def test_should_create_a_new_template_for_a_service(
template = Template.query.get(json_resp['data']['id']) template = Template.query.get(json_resp['data']['id'])
from app.schemas import template_schema from app.schemas import template_schema
assert sorted(json_resp['data']) == sorted(template_schema.dump(template).data) assert sorted(json_resp['data']) == sorted(template_schema.dump(template))
def test_create_a_new_template_for_a_service_adds_folder_relationship( def test_create_a_new_template_for_a_service_adds_folder_relationship(
@@ -879,7 +879,7 @@ def test_create_a_template_with_reply_to(admin_request, sample_user):
template = Template.query.get(json_resp['data']['id']) template = Template.query.get(json_resp['data']['id'])
from app.schemas import template_schema from app.schemas import template_schema
assert sorted(json_resp['data']) == sorted(template_schema.dump(template).data) assert sorted(json_resp['data']) == sorted(template_schema.dump(template))
th = TemplateHistory.query.filter_by(id=template.id, version=1).one() th = TemplateHistory.query.filter_by(id=template.id, version=1).one()
assert th.service_letter_contact_id == letter_contact.id assert th.service_letter_contact_id == letter_contact.id
+7 -8
View File
@@ -16,16 +16,15 @@ def test_job_schema_doesnt_return_notifications(sample_notification_with_job):
job = sample_notification_with_job.job job = sample_notification_with_job.job
assert job.notifications.count() == 1 assert job.notifications.count() == 1
data, errors = job_schema.dump(job) data = job_schema.dump(job)
assert not errors
assert 'notifications' not in data assert 'notifications' not in data
def test_notification_schema_ignores_absent_api_key(sample_notification_with_job): def test_notification_schema_ignores_absent_api_key(sample_notification_with_job):
from app.schemas import notification_with_template_schema from app.schemas import notification_with_template_schema
data = notification_with_template_schema.dump(sample_notification_with_job).data data = notification_with_template_schema.dump(sample_notification_with_job)
assert data['key_name'] is None assert data['key_name'] is None
@@ -35,7 +34,7 @@ def test_notification_schema_adds_api_key_name(sample_notification):
api_key = create_api_key(sample_notification.service, key_name='Test key') api_key = create_api_key(sample_notification.service, key_name='Test key')
sample_notification.api_key = api_key sample_notification.api_key = api_key
data = notification_with_template_schema.dump(sample_notification).data data = notification_with_template_schema.dump(sample_notification)
assert data['key_name'] == 'Test key' assert data['key_name'] == 'Test key'
@@ -48,7 +47,7 @@ def test_notification_schema_adds_api_key_name(sample_notification):
def test_notification_schema_has_correct_status(sample_notification, schema_name): def test_notification_schema_has_correct_status(sample_notification, schema_name):
from app import schemas from app import schemas
data = getattr(schemas, schema_name).dump(sample_notification).data data = getattr(schemas, schema_name).dump(sample_notification)
assert data['status'] == sample_notification.status assert data['status'] == sample_notification.status
@@ -109,7 +108,7 @@ def test_provider_details_schema_returns_user_details(
from app.schemas import provider_details_schema from app.schemas import provider_details_schema
current_sms_provider = get_provider_details_by_identifier('mmg') current_sms_provider = get_provider_details_by_identifier('mmg')
current_sms_provider.created_by = sample_user current_sms_provider.created_by = sample_user
data = provider_details_schema.dump(current_sms_provider).data data = provider_details_schema.dump(current_sms_provider)
assert sorted(data['created_by'].keys()) == sorted(['id', 'email_address', 'name']) assert sorted(data['created_by'].keys()) == sorted(['id', 'email_address', 'name'])
@@ -122,7 +121,7 @@ def test_provider_details_history_schema_returns_user_details(
from app.schemas import provider_details_schema from app.schemas import provider_details_schema
current_sms_provider = get_provider_details_by_identifier('mmg') current_sms_provider = get_provider_details_by_identifier('mmg')
current_sms_provider.created_by_id = sample_user.id current_sms_provider.created_by_id = sample_user.id
data = provider_details_schema.dump(current_sms_provider).data data = provider_details_schema.dump(current_sms_provider)
dao_update_provider_details(current_sms_provider) dao_update_provider_details(current_sms_provider)
@@ -131,6 +130,6 @@ def test_provider_details_history_schema_returns_user_details(
).order_by( ).order_by(
desc(ProviderDetailsHistory.version) desc(ProviderDetailsHistory.version)
).first() ).first()
data = provider_details_schema.dump(current_sms_provider_in_history).data data = provider_details_schema.dump(current_sms_provider_in_history)
assert sorted(data['created_by'].keys()) == sorted(['id', 'email_address', 'name']) assert sorted(data['created_by'].keys()) == sorted(['id', 'email_address', 'name'])
@@ -273,8 +273,8 @@ def test_should_cache_template_and_service_in_redis(mocker, client, sample_templ
call(expected_templates_key), call(expected_templates_key),
] ]
service_dict = service_schema.dump(sample_template.service).data service_dict = service_schema.dump(sample_template.service)
template_dict = template_schema.dump(sample_template).data template_dict = template_schema.dump(sample_template)
assert len(mock_redis_set.call_args_list) == 2 assert len(mock_redis_set.call_args_list) == 2
@@ -292,8 +292,8 @@ def test_should_cache_template_and_service_in_redis(mocker, client, sample_templ
def test_should_return_template_if_found_in_redis(mocker, client, sample_template): def test_should_return_template_if_found_in_redis(mocker, client, sample_template):
from app.schemas import service_schema, template_schema from app.schemas import service_schema, template_schema
service_dict = service_schema.dump(sample_template.service).data service_dict = service_schema.dump(sample_template.service)
template_dict = template_schema.dump(sample_template).data template_dict = template_schema.dump(sample_template)
mocker.patch( mocker.patch(
'app.redis_store.get', 'app.redis_store.get',