Change all UTC timezones to import from pytz instead of Django.

This commit is contained in:
John Eskew
2017-09-19 18:17:03 -04:00
parent 02f26f55ce
commit 7dfb6cc681
26 changed files with 94 additions and 102 deletions

View File

@@ -62,7 +62,7 @@ from xml.sax.saxutils import escape
import bleach
import mock
import oauthlib.oauth1
from django.utils.timezone import UTC
from pytz import UTC
from lxml import etree
from oauthlib.oauth1.rfc5849 import signature
from pkg_resources import resource_string
@@ -889,7 +889,7 @@ oauth_consumer_key="", oauth_signature="frVp4JuvT1mVXlxktiAUjQ7%2F1cw%3D"'}
close_date = due_date + self.graceperiod # pylint: disable=no-member
else:
close_date = due_date
return close_date is not None and datetime.datetime.now(UTC()) > close_date
return close_date is not None and datetime.datetime.now(UTC) > close_date
class LTIDescriptor(LTIFields, MetadataOnlyEditingDescriptor, EmptyDataRawDescriptor):

View File

@@ -5,10 +5,10 @@ xModule implementation of a learning sequence
# pylint: disable=abstract-method
import collections
from datetime import datetime
from django.utils.timezone import UTC
import json
import logging
from pkg_resources import resource_string
from pytz import UTC
from lxml import etree
from xblock.core import XBlock
@@ -215,7 +215,7 @@ class SequenceModule(SequenceFields, ProctoringFields, XModule):
return (
not date or
not hide_after_date or
datetime.now(UTC()) < date
datetime.now(UTC) < date
)
def student_view(self, context):

View File

@@ -3,7 +3,7 @@
import datetime
import unittest
from django.utils.timezone import UTC
from pytz import UTC
from xmodule.fields import Date, Timedelta, RelativeTime
from xmodule.timeinfo import TimeInfo
@@ -57,15 +57,15 @@ class DateTest(unittest.TestCase):
self.assertEqual(DateTest.date.enforce_type(""), None)
self.assertEqual(
DateTest.date.enforce_type("2012-12-31T23:00:01"),
datetime.datetime(2012, 12, 31, 23, 0, 1, tzinfo=UTC())
datetime.datetime(2012, 12, 31, 23, 0, 1, tzinfo=UTC)
)
self.assertEqual(
DateTest.date.enforce_type(1234567890000),
datetime.datetime(2009, 2, 13, 23, 31, 30, tzinfo=UTC())
datetime.datetime(2009, 2, 13, 23, 31, 30, tzinfo=UTC)
)
self.assertEqual(
DateTest.date.enforce_type(datetime.datetime(2014, 5, 9, 21, 1, 27, tzinfo=UTC())),
datetime.datetime(2014, 5, 9, 21, 1, 27, tzinfo=UTC())
DateTest.date.enforce_type(datetime.datetime(2014, 5, 9, 21, 1, 27, tzinfo=UTC)),
datetime.datetime(2014, 5, 9, 21, 1, 27, tzinfo=UTC)
)
with self.assertRaises(TypeError):
DateTest.date.enforce_type([1])
@@ -79,11 +79,11 @@ class DateTest(unittest.TestCase):
def test_old_due_date_format(self):
current = datetime.datetime.today()
self.assertEqual(
datetime.datetime(current.year, 3, 12, 12, tzinfo=UTC()),
datetime.datetime(current.year, 3, 12, 12, tzinfo=UTC),
DateTest.date.from_json("March 12 12:00")
)
self.assertEqual(
datetime.datetime(current.year, 12, 4, 16, 30, tzinfo=UTC()),
datetime.datetime(current.year, 12, 4, 16, 30, tzinfo=UTC),
DateTest.date.from_json("December 4 16:30")
)
self.assertIsNone(DateTest.date.from_json("12 12:00"))
@@ -92,13 +92,13 @@ class DateTest(unittest.TestCase):
"""
Test the non-standard args being passed to from_json
"""
now = datetime.datetime.now(UTC())
delta = now - datetime.datetime.fromtimestamp(0, UTC())
now = datetime.datetime.now(UTC)
delta = now - datetime.datetime.fromtimestamp(0, UTC)
self.assertEqual(
DateTest.date.from_json(delta.total_seconds() * 1000),
now
)
yesterday = datetime.datetime.now(UTC()) - datetime.timedelta(days=-1)
yesterday = datetime.datetime.now(UTC) - datetime.timedelta(days=-1)
self.assertEqual(DateTest.date.from_json(yesterday), yesterday)
def test_to_json(self):
@@ -157,7 +157,7 @@ class TimedeltaTest(unittest.TestCase):
class TimeInfoTest(unittest.TestCase):
def test_time_info(self):
due_date = datetime.datetime(2000, 4, 14, 10, tzinfo=UTC())
due_date = datetime.datetime(2000, 4, 14, 10, tzinfo=UTC)
grace_pd_string = '1 day 12 hours 59 minutes 59 seconds'
timeinfo = TimeInfo(due_date, grace_pd_string)
self.assertEqual(

View File

@@ -8,7 +8,7 @@ from fs.memoryfs import MemoryFS
from lxml import etree
from mock import Mock, patch
from django.utils.timezone import UTC
from pytz import UTC
from xmodule.xml_module import is_pointer_tag
from opaque_keys.edx.locations import Location
@@ -346,7 +346,7 @@ class ImportTestCase(BaseCourseTestCase):
# Check that the child hasn't started yet
self.assertLessEqual(
datetime.datetime.now(UTC()),
datetime.datetime.now(UTC),
child.start
)

View File

@@ -3,7 +3,7 @@
import datetime
import textwrap
from django.utils.timezone import UTC
from pytz import UTC
from mock import Mock
from xmodule.lti_module import LTIDescriptor
from xmodule.lti_2_util import LTIError
@@ -388,7 +388,7 @@ class LTI20RESTResultServiceTest(LogicTest):
Test that we get a 404 when accept_grades_past_due is False and it is past due
"""
self.setup_system_xmodule_mocks_for_lti20_request_test()
self.xmodule.due = datetime.datetime.now(UTC())
self.xmodule.due = datetime.datetime.now(UTC)
self.xmodule.accept_grades_past_due = False
mock_request = self.get_signed_lti20_mock_request(self.GOOD_JSON_PUT)
response = self.xmodule.lti_2_0_result_rest_handler(mock_request, "user/abcd")

View File

@@ -2,7 +2,7 @@
"""Test for LTI Xmodule functional logic."""
import datetime
from django.utils.timezone import UTC
from pytz import UTC
from mock import Mock, patch, PropertyMock
import textwrap
from lxml import etree
@@ -180,7 +180,7 @@ class LTIModuleTest(LogicTest):
Should fail if we do not accept past due grades, and it is past due.
"""
self.xmodule.accept_grades_past_due = False
self.xmodule.due = datetime.datetime.now(UTC())
self.xmodule.due = datetime.datetime.now(UTC)
self.xmodule.graceperiod = Timedelta().from_json("0 seconds")
request = Request(self.environ)
request.body = self.get_request_body()

View File

@@ -4,7 +4,7 @@ Test cases covering workflows and behaviors for the Randomize XModule
import unittest
from datetime import datetime, timedelta
from django.utils.timezone import UTC
from pytz import UTC
from opaque_keys.edx.locator import BlockUsageLocator
from xblock.fields import ScopeIds
from xmodule.randomize_module import RandomizeModule
@@ -16,7 +16,7 @@ ORG = 'test_org'
COURSE = 'test_course'
START = '2013-01-01T01:00:00'
_TODAY = datetime.now(UTC())
_TODAY = datetime.now(UTC)
_LAST_WEEK = _TODAY - timedelta(days=7)
_NEXT_WEEK = _TODAY + timedelta(days=7)