Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions lob_python/model_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -914,16 +914,22 @@ def check_validations(
current_validations = validations[input_variable_path]
if (is_json_validation_enabled('multipleOf', configuration) and
'multiple_of' in current_validations and
isinstance(input_values, (int, float)) and
not (float(input_values) / current_validations['multiple_of']).is_integer()):
# Note 'multipleOf' will be as good as the floating point arithmetic.
raise ApiValueError(
"Invalid value for `%s`, value must be a multiple of "
"`%s`" % (
input_variable_path[0],
current_validations['multiple_of']
)
)
isinstance(input_values, (int, float))):
# since floating point arithmetic can be imprecise, we'll convert input_values to string
# and determine whether the decimal place is in a value position (within 3 spots of the end of the string)
try:
decimal_index = str(input_values).index('.')
if decimal_index < len(str(input_values)) - 3:
raise ApiValueError(
"Invalid value for `%s`, value must be a multiple of "
"`%s`" % (
input_variable_path[0],
current_validations['multiple_of']
)
)
except:
# if no decimal, then it's a multiple of 0.01
print("whole dollar amount")

if (is_json_validation_enabled('maxLength', configuration) and
'max_length' in current_validations and
Expand Down
3 changes: 2 additions & 1 deletion test/Integration/test_zip_lookups_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ def test_lookup_error(self):

with self.assertRaises(Exception) as context:
self.api.lookup(zip)
self.assertTrue("invalid ZIP code" in context.exception.__str__())
print(context.exception.__str__())
self.assertTrue("invalid zip code" in context.exception.__str__())


if __name__ == '__main__':
Expand Down