Skip to content

Commit

Permalink
Merge pull request #94 from ambitioninc/develop
Browse files Browse the repository at this point in the history
1.4.0
  • Loading branch information
somewes authored Oct 12, 2021
2 parents 194a123 + 8967117 commit 4587fe0
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 20 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ python:

env:
matrix:
- DJANGO=2.0
- DJANGO=2.1
- DJANGO=2.2
- DJANGO=master

Expand Down
6 changes: 6 additions & 0 deletions data_schema/convert_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import pytz

from data_schema.field_schema_type import FieldSchemaType, FieldSchemaCase
from data_schema.exceptions import InvalidDateFormatException


class ValueConverter(object):
Expand Down Expand Up @@ -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)

Expand Down
8 changes: 7 additions & 1 deletion data_schema/docs/release_notes.rst
Original file line number Diff line number Diff line change
@@ -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
------
Expand Down
4 changes: 4 additions & 0 deletions data_schema/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@


class InvalidDateFormatException(Exception):
pass
10 changes: 10 additions & 0 deletions data_schema/tests/convert_value_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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')
2 changes: 1 addition & 1 deletion data_schema/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.3.0'
__version__ = '1.4.0'
12 changes: 6 additions & 6 deletions requirements/requirements-testing.txt
Original file line number Diff line number Diff line change
@@ -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
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
8 changes: 1 addition & 7 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
[tox]
envlist =
flake8
py{36}-django20
py{36,37}-django21
py{36,37}-django22
py{36,37}-djangomaster

[testenv]
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 =
Expand All @@ -25,7 +21,5 @@ commands = flake8 data_schema

[travis:env]
DJANGO =
2.0: django20
2.1: django21
2.2: django22
master: djangomaster

0 comments on commit 4587fe0

Please sign in to comment.