From 56417c41ed77b7bb3ad25fe2aff5dec73b0bdd92 Mon Sep 17 00:00:00 2001 From: BennyKitchell Date: Mon, 21 Nov 2022 15:21:25 -0600 Subject: [PATCH 1/2] fix: catch multiple of issue for decimals --- lob_python/model_utils.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/lob_python/model_utils.py b/lob_python/model_utils.py index f79331e..e38277c 100755 --- a/lob_python/model_utils.py +++ b/lob_python/model_utils.py @@ -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 From 63bd21090fade62a50c44f1e84c323b4b4f3bb62 Mon Sep 17 00:00:00 2001 From: BennyKitchell Date: Mon, 21 Nov 2022 15:33:30 -0600 Subject: [PATCH 2/2] fix: fix cap error in zip code error verification --- test/Integration/test_zip_lookups_api.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/Integration/test_zip_lookups_api.py b/test/Integration/test_zip_lookups_api.py index 911e434..f1d64a1 100644 --- a/test/Integration/test_zip_lookups_api.py +++ b/test/Integration/test_zip_lookups_api.py @@ -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__':