def test_phone_number_field_load(number, expected, strict, passes):
"""Ensure that the Phone Number field can format numbers correctly."""
schema = PhoneNumberSchema(context={'strict_phone_validation': strict})
payload = {'phone': number}
if passes:
deserialized = schema.load(payload).data
assert deserialized['phone'] == expected
serialized = schema.dump(deserialized).data
assert serialized['phone'] == expected
else:
error_msg = {
'phone': [("The value for phone ({}) is not a valid phone "
"number.".format(number))]
}
with pytest.raises(ValidationError, message=error_msg):
schema.load(payload)
评论列表
文章目录