mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-30 06:21:50 -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:
@@ -64,7 +64,7 @@ def test_user_update_schema_accepts_valid_attribute_pairs(user_attribute, user_v
|
||||
}
|
||||
from app.schemas import user_update_schema_load_json
|
||||
|
||||
data, errors = user_update_schema_load_json.load(update_dict)
|
||||
errors = user_update_schema_load_json.validate(update_dict)
|
||||
assert not errors
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ def test_user_update_schema_rejects_invalid_attribute_pairs(user_attribute, user
|
||||
}
|
||||
|
||||
with pytest.raises(ValidationError):
|
||||
data, errors = user_update_schema_load_json.load(update_dict)
|
||||
user_update_schema_load_json.load(update_dict)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('user_attribute', [
|
||||
@@ -96,7 +96,7 @@ def test_user_update_schema_rejects_disallowed_attribute_keys(user_attribute):
|
||||
from app.schemas import user_update_schema_load_json
|
||||
|
||||
with pytest.raises(ValidationError) as excinfo:
|
||||
data, errors = user_update_schema_load_json.load(update_dict)
|
||||
user_update_schema_load_json.load(update_dict)
|
||||
|
||||
assert excinfo.value.messages['_schema'][0] == 'Unknown field name {}'.format(user_attribute)
|
||||
|
||||
|
||||
@@ -116,6 +116,7 @@ def test_post_user(admin_request, notify_db_session):
|
||||
json_resp = admin_request.post('user.create_user', _data=data, _expected_status=201)
|
||||
|
||||
user = User.query.filter_by(email_address='user@digital.cabinet-office.gov.uk').first()
|
||||
assert user.check_password("password")
|
||||
assert json_resp['data']['email_address'] == user.email_address
|
||||
assert json_resp['data']['id'] == str(user.id)
|
||||
assert user.auth_type == EMAIL_AUTH_TYPE
|
||||
@@ -888,7 +889,7 @@ def test_cannot_update_user_password_using_attributes_method(admin_request, samp
|
||||
_data={'password': 'foo'},
|
||||
_expected_status=400
|
||||
)
|
||||
assert resp['message']['_schema'] == ['Unknown field name password']
|
||||
assert resp == {'message': {'_schema': ['Unknown field name password']}, 'result': 'error'}
|
||||
|
||||
|
||||
def test_get_orgs_and_services_nests_services(admin_request, sample_user):
|
||||
|
||||
Reference in New Issue
Block a user