diff --git a/completion_aggregator/__init__.py b/completion_aggregator/__init__.py index c3df9e47..16d29f73 100644 --- a/completion_aggregator/__init__.py +++ b/completion_aggregator/__init__.py @@ -4,6 +4,6 @@ from __future__ import absolute_import, unicode_literals -__version__ = '3.0.1' +__version__ = '3.0.2' default_app_config = 'completion_aggregator.apps.CompletionAggregatorAppConfig' # pylint: disable=invalid-name diff --git a/completion_aggregator/utils.py b/completion_aggregator/utils.py index dbed37cc..48e394ee 100644 --- a/completion_aggregator/utils.py +++ b/completion_aggregator/utils.py @@ -6,9 +6,6 @@ from django.utils import timezone from django.utils.translation import ugettext as _ -DJANGO_MAJOR_VERSION = django.VERSION[0] -DJANGO_MINOR_VERSION = django.VERSION[1] - WAFFLE_AGGREGATE_STALE_FROM_SCRATCH = 'completion_aggregator.aggregate_stale_from_scratch' @@ -44,7 +41,7 @@ def make_datetime_timezone_unaware(date): # pylint: disable=line-too-long # Ref: https://github.com/django/django/commit/e707e4c709c2e3f2dad69643eb838f87491891f8#diff-af003fcfed7cfbdeb396f8647ed0f92fR258 # pylint: enable=line-too-long - if DJANGO_MAJOR_VERSION >= 1 and DJANGO_MINOR_VERSION >= 10: + if django.VERSION >= (1, 10): date = date.astimezone(timezone.utc).replace(tzinfo=None) return date diff --git a/tests/test_util_functions.py b/tests/test_util_functions.py index ffeeeb0f..cdcf88f4 100644 --- a/tests/test_util_functions.py +++ b/tests/test_util_functions.py @@ -6,12 +6,15 @@ from __future__ import absolute_import, division, print_function, unicode_literals +from datetime import datetime, timezone +from unittest.mock import patch + import ddt import pytest from django.test import TestCase -from completion_aggregator.utils import get_percent +from completion_aggregator.utils import get_percent, make_datetime_timezone_unaware @ddt.ddt @@ -32,3 +35,21 @@ def test_get_percent_with_invalid_values(self): def test_get_percent_with_valid_values(self, earned, possible, expected_percentage): percentage = get_percent(earned, possible) self.assertEqual(percentage, expected_percentage) + + +@ddt.ddt +class MakeTimeZoneUnawareTestCase(TestCase): + """ + Tests of the `make_datetime_timezone_unaware` function + """ + + @ddt.data( + (1, 10, 'a1'), + (1, 10), + (2, 0, 'a1'), + (2, 2), + ) + def test_make_datetime_timezone_unaware(self, version): + with patch('django.VERSION', version): + date = make_datetime_timezone_unaware(datetime.now(timezone.utc)) + assert date.tzinfo is None