mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-20 07:21:13 -05:00
Replace how .load is called
https://marshmallow.readthedocs.io/en/stable/upgrading.html#schemas-are-always-strict `.load` doesn't return a `(data, errors)` tuple any more - only data is returned. A `ValidationError` is raised if validation fails. The code now relies on the `marshmallow_validation_error` error handler to handle errors instead of having to raise an `InvalidRequest`. This has no effect on the response that is returned (a test has been modified to check). Also added a new `password` field to the `UserSchema` so that we don't have to specially check for password errors in the `.create_user` endpoint - we can let marshmallow handle them.
This commit is contained in:
@@ -26,7 +26,7 @@ register_errors(service_invite)
|
||||
@service_invite.route('/service/<service_id>/invite', 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)
|
||||
save_invited_user(invited_user)
|
||||
|
||||
if invited_user.service.has_permission(BROADCAST_TYPE):
|
||||
@@ -79,7 +79,7 @@ def update_invited_user(service_id, invited_user_id):
|
||||
|
||||
current_data = dict(invited_user_schema.dump(fetched).data.items())
|
||||
current_data.update(request.get_json())
|
||||
update_dict = invited_user_schema.load(current_data).data
|
||||
update_dict = invited_user_schema.load(current_data)
|
||||
save_invited_user(update_dict)
|
||||
return jsonify(data=invited_user_schema.dump(fetched).data), 200
|
||||
|
||||
|
||||
Reference in New Issue
Block a user