Skip to content

Commit

Permalink
Fix Django version check (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
viadanna authored Feb 19, 2021
1 parent 7d71d0e commit a4c46ff
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion completion_aggregator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 1 addition & 4 deletions completion_aggregator/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'


Expand Down Expand Up @@ -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

Expand Down
23 changes: 22 additions & 1 deletion tests/test_util_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit a4c46ff

Please sign in to comment.