From 6319b5301e19eb85872955cac42c06c0805aa59f Mon Sep 17 00:00:00 2001 From: davidtgq Date: Wed, 1 Aug 2018 17:55:24 -0400 Subject: [PATCH 1/3] Add TypeError to catch null value inputs --- vibora/schemas/extensions/fields.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vibora/schemas/extensions/fields.pyx b/vibora/schemas/extensions/fields.pyx index 037c250..574dfc0 100644 --- a/vibora/schemas/extensions/fields.pyx +++ b/vibora/schemas/extensions/fields.pyx @@ -97,7 +97,7 @@ cdef class Integer(Field): raise ValidationError(error_code=Messages.MUST_BE_INTEGER, field=self.load_from) try: return int(value) - except ValueError: + except (ValueError, TypeError): raise ValidationError(error_code=Messages.MUST_BE_INTEGER, field=self.load_from) @@ -115,7 +115,7 @@ cdef class Number(Field): raise ValidationError(error_code=Messages.MUST_BE_NUMBER, field=self.load_from) try: return float(value) - except ValueError: + except (ValueError, TypeError): raise ValidationError(error_code=Messages.MUST_BE_NUMBER, field=self.load_from) From 9cebdff34dd48e1bdd824959da736dbc083633bf Mon Sep 17 00:00:00 2001 From: davidtgq Date: Wed, 1 Aug 2018 17:56:27 -0400 Subject: [PATCH 2/3] Add test for null input to numeric fields --- tests/schemas/schemas.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/schemas/schemas.py b/tests/schemas/schemas.py index 76887b7..1d6e65e 100644 --- a/tests/schemas/schemas.py +++ b/tests/schemas/schemas.py @@ -28,6 +28,15 @@ class TestSchema(Schema): except InvalidSchema as error: self.assertTrue(len(error.errors), 2) + async def test_numeric_fields_null_input(self): + class TestSchema(Schema): + field1: int + field2: float + + with self.assertRaises(InvalidSchema) as context: + await TestSchema.load({'field1': None, 'field2': None}) + self.assertTrue(len(context.exception.errors), 2) + def test_schema_correctly_identifying_fields(self): class TestSchema(Schema): field1: str From 44a177572001e8008438e6a8f3a2ea3bd0923f54 Mon Sep 17 00:00:00 2001 From: davidtgq Date: Wed, 1 Aug 2018 23:21:01 -0400 Subject: [PATCH 3/3] Remove test to fulfill PR Quality Review standards --- tests/schemas/schemas.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tests/schemas/schemas.py b/tests/schemas/schemas.py index 1d6e65e..76887b7 100644 --- a/tests/schemas/schemas.py +++ b/tests/schemas/schemas.py @@ -28,15 +28,6 @@ class TestSchema(Schema): except InvalidSchema as error: self.assertTrue(len(error.errors), 2) - async def test_numeric_fields_null_input(self): - class TestSchema(Schema): - field1: int - field2: float - - with self.assertRaises(InvalidSchema) as context: - await TestSchema.load({'field1': None, 'field2': None}) - self.assertTrue(len(context.exception.errors), 2) - def test_schema_correctly_identifying_fields(self): class TestSchema(Schema): field1: str