diff --git a/.travis.yml b/.travis.yml index 551c038..c900606 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,8 +8,6 @@ python: env: matrix: - - DJANGO=2.0 - - DJANGO=2.1 - DJANGO=2.2 - DJANGO=master diff --git a/data_schema/convert_value.py b/data_schema/convert_value.py index ca39bc6..a5cdd21 100644 --- a/data_schema/convert_value.py +++ b/data_schema/convert_value.py @@ -10,6 +10,7 @@ import pytz from data_schema.field_schema_type import FieldSchemaType, FieldSchemaCase +from data_schema.exceptions import InvalidDateFormatException class ValueConverter(object): @@ -154,6 +155,11 @@ def _convert_value(self, value, format_str): if self.is_string(value): value = datetime.strptime(value, format_str) if format_str else parse(value) + # It is assumed that value is a datetime here. If it isn't a datetime, then it is a bad value like + # a number that is too large to be parsed as an integer + if type(value) != datetime: + raise InvalidDateFormatException(f'Invalid date format: {value}') + # Convert any aware datetime objects to naive utc return value if value.tzinfo is None else fleming.convert_to_tz(value, pytz.utc, return_naive=True) diff --git a/data_schema/docs/release_notes.rst b/data_schema/docs/release_notes.rst index c75f351..cc0f849 100644 --- a/data_schema/docs/release_notes.rst +++ b/data_schema/docs/release_notes.rst @@ -1,5 +1,11 @@ Release Notes -============= + + +v1.4.0 +------ +* Raise InvalidDateFormatException when trying to parse a timestamp that is too large. +* remove django 2.0 +* remove django 2.1 v1.3.0 ------ diff --git a/data_schema/exceptions.py b/data_schema/exceptions.py new file mode 100644 index 0000000..fa7eccb --- /dev/null +++ b/data_schema/exceptions.py @@ -0,0 +1,4 @@ + + +class InvalidDateFormatException(Exception): + pass diff --git a/data_schema/tests/convert_value_tests.py b/data_schema/tests/convert_value_tests.py index 42f9cb9..9442625 100644 --- a/data_schema/tests/convert_value_tests.py +++ b/data_schema/tests/convert_value_tests.py @@ -4,6 +4,7 @@ from data_schema.models import FieldSchemaType from data_schema.convert_value import convert_value +from data_schema.exceptions import InvalidDateFormatException class ConvertValueExceptionTest(SimpleTestCase): @@ -122,3 +123,12 @@ def test_convert(self): self.assertEqual(datetime(2017, 3, 1, 0), convert_value(FieldSchemaType.DATE_FLOORED, '2017-03-01T10:30.000Z')) self.assertEqual(datetime(2017, 3, 1, 0), convert_value(FieldSchemaType.DATE_FLOORED, '2017-03-01 10:30.00')) self.assertEqual(datetime(2017, 3, 1, 0), convert_value(FieldSchemaType.DATE_FLOORED, '2017-03-01')) + + def test_convert_too_large_integer(self): + """ + Verifies that InvalidDateFormatException is raised instead of a generic attribute error + """ + with self.assertRaises(InvalidDateFormatException) as context: + convert_value(FieldSchemaType.DATE_FLOORED, 3333333333333333333333333) + + self.assertEqual(str(context.exception), 'Invalid date format: 3333333333333333333333333') diff --git a/data_schema/version.py b/data_schema/version.py index 19b4f1d..96e3ce8 100644 --- a/data_schema/version.py +++ b/data_schema/version.py @@ -1 +1 @@ -__version__ = '1.3.0' +__version__ = '1.4.0' diff --git a/requirements/requirements-testing.txt b/requirements/requirements-testing.txt index d9a3e3b..48603f6 100644 --- a/requirements/requirements-testing.txt +++ b/requirements/requirements-testing.txt @@ -1,6 +1,6 @@ -coverage -coveralls -django-dynamic-fixture -django-nose -mock -psycopg2 +coverage<=5.5 +coveralls<=3.0.1 +django-dynamic-fixture<=3.1.1 +django-nose<=1.4.7 +mock<=4.0.3 +psycopg2<=2.8.6 diff --git a/setup.py b/setup.py index b8d5363..07f1668 100644 --- a/setup.py +++ b/setup.py @@ -36,18 +36,17 @@ def get_version(): 'License :: OSI Approved :: BSD License', 'Operating System :: OS Independent', 'Framework :: Django', - 'Framework :: Django :: 2.0', - 'Framework :: Django :: 2.1', 'Framework :: Django :: 2.2', ], license='MIT', install_requires=[ - 'Django>=2.0', + 'Django<4.0', 'django-manager-utils>=1.4.0', 'fleming>=0.5.0', 'python-dateutil>=2.2', ], tests_require=[ + 'Django<4.0', 'django-dynamic-fixture', 'psycopg2', 'django-nose', diff --git a/tox.ini b/tox.ini index f30ec9a..c5d578e 100644 --- a/tox.ini +++ b/tox.ini @@ -1,8 +1,6 @@ [tox] envlist = flake8 - py{36}-django20 - py{36,37}-django21 py{36,37}-django22 py{36,37}-djangomaster @@ -10,9 +8,7 @@ envlist = setenv = DB = postgres deps = - django20: Django>=2.0,<2.1 - django21: Django>=2.1,<2.2 - django22: Django>=2.2,<2.3 + django22: Django>=2.2,<3.0 djangomaster: https://github.com/django/django/archive/master.tar.gz -rrequirements/requirements-testing.txt commands = @@ -25,7 +21,5 @@ commands = flake8 data_schema [travis:env] DJANGO = - 2.0: django20 - 2.1: django21 2.2: django22 master: djangomaster