diff --git a/app/events/rest.py b/app/events/rest.py index c7f77c7b8..dc2ef8855 100644 --- a/app/events/rest.py +++ b/app/events/rest.py @@ -13,4 +13,4 @@ def create_event(): data = request.get_json() 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 diff --git a/app/job/rest.py b/app/job/rest.py index 6f4ee8aba..36905bb8c 100644 --- a/app/job/rest.py +++ b/app/job/rest.py @@ -50,7 +50,7 @@ register_errors(job_blueprint) 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) 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] @@ -97,7 +97,7 @@ def get_all_notifications_for_service_job(service_id, job_id): 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, @@ -185,7 +185,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 @@ -219,7 +219,7 @@ def get_paginated_jobs( statuses=statuses, 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: start = job_data['processing_started'] start = dateutil.parser.parse(start).replace(tzinfo=None) if start else None diff --git a/app/notifications/rest.py b/app/notifications/rest.py index 33dbc5f6a..d90ef425d 100644 --- a/app/notifications/rest.py +++ b/app/notifications/rest.py @@ -43,7 +43,7 @@ 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']) @@ -65,7 +65,7 @@ def get_all_notifications(): key_type=api_user.key_type, 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( diff --git a/app/provider_details/rest.py b/app/provider_details/rest.py index dea1c2f9b..f0842303e 100644 --- a/app/provider_details/rest.py +++ b/app/provider_details/rest.py @@ -37,7 +37,7 @@ def get_providers(): @provider_details.route('/', 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) @@ -47,7 +47,7 @@ def get_provider_versions(provider_details_id): data = provider_details_history_schema.dump( versions, many=True - ).data + ) return jsonify(data=data) @@ -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 diff --git a/app/serialised_models.py b/app/serialised_models.py index 6653960ba..583c13591 100644 --- a/app/serialised_models.py +++ b/app/serialised_models.py @@ -66,7 +66,7 @@ class SerialisedTemplate(SerialisedModel): version=version, ) - template_dict = template_schema.dump(fetched_template).data + template_dict = template_schema.dump(fetched_template) db.session.commit() return {'data': template_dict} @@ -98,7 +98,7 @@ class SerialisedService(SerialisedModel): def get_dict(service_id): 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() return {'data': service_dict} diff --git a/app/service/rest.py b/app/service/rest.py index b520250e5..4b9eb4e19 100644 --- a/app/service/rest.py +++ b/app/service/rest.py @@ -200,7 +200,7 @@ def get_services(): return result else: 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) @@ -228,7 +228,7 @@ def get_service_by_id(service_id): else: fetched = dao_fetch_service_by_id(service_id) - data = service_schema.dump(fetched).data + data = service_schema.dump(fetched) return jsonify(data=data) @@ -262,7 +262,7 @@ def create_service(): dao_create_service(valid_service, user) 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('/', methods=['POST']) @@ -271,7 +271,7 @@ def update_service(service_id): fetched_service = dao_fetch_service_by_id(service_id) # Capture the status change here as Marshmallow changes this later 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()) service = service_schema.load(current_data) @@ -295,7 +295,7 @@ def update_service(service_id): 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('//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) 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('//users', methods=['GET']) @@ -356,7 +356,7 @@ def add_user_to_service(service_id, user_id): folder_permissions = data.get('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 @@ -389,12 +389,12 @@ def get_service_history(service_id): ) 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_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_data, errors = template_history_schema.dump(template_history, many=True) + template_data = template_history_schema.dump(template_history, many=True) data = { 'service_history': service_data, @@ -449,7 +449,7 @@ def get_all_notifications_for_service(service_id): if data.get('format_for_csv'): notifications = [notification.serialize_for_csv() for notification in pagination.items] 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 # 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, ) return jsonify( - notification_with_template_schema.dump(notification).data, + notification_with_template_schema.dump(notification), ), 200 @@ -524,7 +524,7 @@ def cancel_notification_for_service(service_id, notification_id): ) return jsonify( - notification_with_template_schema.dump(updated_notification).data + notification_with_template_schema.dump(updated_notification) ), 200 @@ -556,7 +556,7 @@ def search_for_notification_by_to_field(service_id, search_term, statuses, notif ) 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( 1, 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.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): @@ -1172,5 +1172,5 @@ def set_as_broadcast_service(service_id): provider_restriction=data["provider_restriction"] ) - data = service_schema.dump(service).data + data = service_schema.dump(service) return jsonify(data=data) diff --git a/app/service_invite/rest.py b/app/service_invite/rest.py index 34d65fa28..2bb331d7d 100644 --- a/app/service_invite/rest.py +++ b/app/service_invite/rest.py @@ -58,30 +58,30 @@ def create_invited_user(service_id): 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//invite', 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 @service_invite.route('/service//invite/', methods=['GET']) 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) - 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//invite/', methods=['POST']) 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) - 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()) update_dict = invited_user_schema.load(current_data) 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): @@ -96,7 +96,7 @@ def invited_user_url(invited_user_id, invite_link_host=None): @service_invite.route('/invite/service/', methods=['GET']) def get_invited_user(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/', methods=['GET']) @@ -120,4 +120,4 @@ def validate_service_invitation_token(token): raise InvalidRequest(errors, status_code=400) 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 diff --git a/app/template/rest.py b/app/template/rest.py index fe30dc6e8..b59ef9ff0 100644 --- a/app/template/rest.py +++ b/app/template/rest.py @@ -111,7 +111,7 @@ def create_template(service_id): 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('/', methods=['POST']) @@ -140,10 +140,10 @@ def update_template(service_id, template_id): if "reply_to" in data: 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")) - 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()) - updated_template = 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).items()) updated_template.update(data) # Check if there is a change to make. @@ -160,13 +160,13 @@ def update_template(service_id, template_id): if update_dict.archived: update_dict.folder = None 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']) def get_precompiled_template_for_service(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 @@ -175,23 +175,23 @@ def get_precompiled_template_for_service(service_id): def get_all_templates_for_service(service_id): templates = dao_get_all_templates_for_service(service_id=service_id) if str(request.args.get('detailed', True)) == 'True': - data = template_schema.dump(templates, many=True).data + data = template_schema.dump(templates, many=True) else: - data = template_schema_no_detail.dump(templates, many=True).data + data = template_schema_no_detail.dump(templates, many=True) return jsonify(data=data) @template_blueprint.route('/', methods=['GET']) 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) - data = template_schema.dump(fetched_template).data + data = template_schema.dump(fetched_template) return jsonify(data=data) @template_blueprint.route('//preview', methods=['GET']) 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) - data = template_schema.dump(fetched_template).data + data = template_schema.dump(fetched_template) template_object = fetched_template._as_utils_template_with_personalisation( request.args.to_dict() ) @@ -217,7 +217,7 @@ def get_template_version(service_id, template_id, version): service_id=service_id, version=version ) - ).data + ) return jsonify(data=data) @@ -226,7 +226,7 @@ def get_template_versions(service_id, template_id): data = template_history_schema.dump( dao_get_template_versions(service_id=service_id, template_id=template_id), many=True - ).data + ) return jsonify(data=data) diff --git a/app/upload/rest.py b/app/upload/rest.py index 7b1f1fb4c..30a93cd39 100644 --- a/app/upload/rest.py +++ b/app/upload/rest.py @@ -91,7 +91,7 @@ def get_uploaded_letter_by_service_and_print_day(service_id, letter_print_date): 'notifications': notification_with_template_schema.dump( pagination.items, many=True, - ).data, + ), 'page_size': pagination.per_page, 'total': pagination.total, 'links': pagination_links( diff --git a/tests/app/delivery/test_send_to_providers.py b/tests/app/delivery/test_send_to_providers.py index e47b0e173..b5b0967a0 100644 --- a/tests/app/delivery/test_send_to_providers.py +++ b/tests/app/delivery/test_send_to_providers.py @@ -811,8 +811,8 @@ def test_send_sms_to_provider_should_return_template_if_found_in_redis( mocker, client, sample_template ): from app.schemas import service_schema, template_schema - service_dict = service_schema.dump(sample_template.service).data - template_dict = template_schema.dump(sample_template).data + service_dict = service_schema.dump(sample_template.service) + template_dict = template_schema.dump(sample_template) mocker.patch( '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 ): from app.schemas import service_schema, template_schema - service_dict = service_schema.dump(sample_email_template.service).data - template_dict = template_schema.dump(sample_email_template).data + service_dict = service_schema.dump(sample_email_template.service) + template_dict = template_schema.dump(sample_email_template) mocker.patch( 'app.redis_store.get', diff --git a/tests/app/template/test_rest.py b/tests/app/template/test_rest.py index 4536ca497..7d4b5ee92 100644 --- a/tests/app/template/test_rest.py +++ b/tests/app/template/test_rest.py @@ -88,7 +88,7 @@ def test_should_create_a_new_template_for_a_service( template = Template.query.get(json_resp['data']['id']) 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( @@ -879,7 +879,7 @@ def test_create_a_template_with_reply_to(admin_request, sample_user): template = Template.query.get(json_resp['data']['id']) 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() assert th.service_letter_contact_id == letter_contact.id diff --git a/tests/app/test_schemas.py b/tests/app/test_schemas.py index 9c317c349..109678d43 100644 --- a/tests/app/test_schemas.py +++ b/tests/app/test_schemas.py @@ -16,16 +16,15 @@ def test_job_schema_doesnt_return_notifications(sample_notification_with_job): job = sample_notification_with_job.job assert job.notifications.count() == 1 - data, errors = job_schema.dump(job) + data = job_schema.dump(job) - assert not errors assert 'notifications' not in data def test_notification_schema_ignores_absent_api_key(sample_notification_with_job): 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 @@ -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') 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' @@ -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): 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 @@ -109,7 +108,7 @@ def test_provider_details_schema_returns_user_details( from app.schemas import provider_details_schema current_sms_provider = get_provider_details_by_identifier('mmg') 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']) @@ -122,7 +121,7 @@ def test_provider_details_history_schema_returns_user_details( from app.schemas import provider_details_schema current_sms_provider = get_provider_details_by_identifier('mmg') 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) @@ -131,6 +130,6 @@ def test_provider_details_history_schema_returns_user_details( ).order_by( desc(ProviderDetailsHistory.version) ).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']) diff --git a/tests/app/v2/notifications/test_post_notifications.py b/tests/app/v2/notifications/test_post_notifications.py index 1164eb34f..3dbac47a6 100644 --- a/tests/app/v2/notifications/test_post_notifications.py +++ b/tests/app/v2/notifications/test_post_notifications.py @@ -273,8 +273,8 @@ def test_should_cache_template_and_service_in_redis(mocker, client, sample_templ call(expected_templates_key), ] - service_dict = service_schema.dump(sample_template.service).data - template_dict = template_schema.dump(sample_template).data + service_dict = service_schema.dump(sample_template.service) + template_dict = template_schema.dump(sample_template) 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): from app.schemas import service_schema, template_schema - service_dict = service_schema.dump(sample_template.service).data - template_dict = template_schema.dump(sample_template).data + service_dict = service_schema.dump(sample_template.service) + template_dict = template_schema.dump(sample_template) mocker.patch( 'app.redis_store.get',