Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lms/djangoapps/branding/tests/test_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from django.test.utils import override_settings
from django.urls import reverse
from milestones.tests.utils import MilestonesTestCaseMixin
from pytz import UTC

from common.djangoapps.edxmako.shortcuts import render_to_response
from common.djangoapps.util.milestones_helpers import set_prerequisite_courses
Expand All @@ -23,6 +22,7 @@
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.course_block import CATALOG_VISIBILITY_ABOUT, CATALOG_VISIBILITY_NONE
from zoneinfo import ZoneInfo

FEATURES_WITH_STARTDATE = settings.FEATURES.copy()
FEATURES_WITH_STARTDATE['DISABLE_START_DATES'] = False
Expand All @@ -48,7 +48,7 @@ def setUp(self):
self.factory = RequestFactory()
self.course = CourseFactory.create(
days_early_for_beta=5,
enrollment_start=datetime.datetime.now(UTC) + datetime.timedelta(days=3),
enrollment_start=datetime.datetime.now(ZoneInfo("UTC")) + datetime.timedelta(days=3),
user_id=self.user.id,
)

Expand Down Expand Up @@ -181,8 +181,8 @@ def setUp(self):
number='1000',
display_name='Starting later, Announced later',
metadata={
'start': datetime.datetime.now(UTC) + datetime.timedelta(days=4),
'announcement': datetime.datetime.now(UTC) + datetime.timedelta(days=3),
'start': datetime.datetime.now(ZoneInfo("UTC")) + datetime.timedelta(days=4),
'announcement': datetime.datetime.now(ZoneInfo("UTC")) + datetime.timedelta(days=3),
},
emit_signals=True,
)
Expand All @@ -191,8 +191,8 @@ def setUp(self):
number='1001',
display_name='Starting earlier, Announced earlier',
metadata={
'start': datetime.datetime.now(UTC) + datetime.timedelta(days=2),
'announcement': datetime.datetime.now(UTC) + datetime.timedelta(days=1),
'start': datetime.datetime.now(ZoneInfo("UTC")) + datetime.timedelta(days=2),
'announcement': datetime.datetime.now(ZoneInfo("UTC")) + datetime.timedelta(days=1),
},
emit_signals=True,
)
Expand Down
6 changes: 3 additions & 3 deletions lms/djangoapps/bulk_email/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from django.test import TestCase
from django.test.utils import override_settings
from opaque_keys.edx.keys import CourseKey
from pytz import UTC

from common.djangoapps.course_modes.models import CourseMode
from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory, StaffFactory
Expand All @@ -35,6 +34,7 @@
from openedx.core.djangoapps.course_groups.models import CourseCohort
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order
from zoneinfo import ZoneInfo


@ddt.ddt
Expand Down Expand Up @@ -84,8 +84,8 @@ def test_bad_to_option(self):
CourseEmail.create(course_id, sender, to_option, subject, html_message)

@ddt.data(
datetime.datetime(1999, 1, 1, tzinfo=UTC),
datetime.datetime(datetime.MAXYEAR, 1, 1, tzinfo=UTC),
datetime.datetime(1999, 1, 1, tzinfo=ZoneInfo("UTC")),
datetime.datetime(datetime.MAXYEAR, 1, 1, tzinfo=ZoneInfo("UTC")),
)
def test_track_target(self, expiration_datetime):
"""
Expand Down
4 changes: 2 additions & 2 deletions lms/djangoapps/ccx/api/v0/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import json
import logging

import pytz
from ccx_keys.locator import CCXLocator
from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user
from django.db import transaction
Expand All @@ -30,6 +29,7 @@
from openedx.core.lib.api import authentication, permissions
from openedx.core.lib.courses import get_course_by_id
from xmodule.modulestore.django import SignalHandler # lint-amnesty, pylint: disable=wrong-import-order
from zoneinfo import ZoneInfo

from .paginators import CCXAPIPagination
from .serializers import CCXCourseSerializer
Expand Down Expand Up @@ -465,7 +465,7 @@ def post(self, request):
ccx_course_object.save()

# Make sure start/due are overridden for entire course
start = TODAY().replace(tzinfo=pytz.UTC)
start = TODAY().replace(tzinfo=ZoneInfo("UTC"))
override_field_for_ccx(ccx_course_object, master_course_object, 'start', start)
override_field_for_ccx(ccx_course_object, master_course_object, 'due', None)

Expand Down
7 changes: 3 additions & 4 deletions lms/djangoapps/ccx/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
from django.db import models
from lazy import lazy
from opaque_keys.edx.django.models import CourseKeyField, UsageKeyField
from pytz import utc

from xmodule.error_block import ErrorBlock
from xmodule.modulestore.django import modulestore
from zoneinfo import ZoneInfo

log = logging.getLogger("edx.ccx")

Expand Down Expand Up @@ -76,14 +76,13 @@ def max_student_enrollments_allowed(self):

def has_started(self):
"""Return True if the CCX start date is in the past"""
return datetime.now(utc) > self.start
return datetime.now(ZoneInfo("UTC")) > self.start

def has_ended(self):
"""Return True if the CCX due date is set and is in the past"""
if self.due is None:
return False

return datetime.now(utc) > self.due
return datetime.now(ZoneInfo("UTC")) > self.due

@property
def structure(self):
Expand Down
6 changes: 3 additions & 3 deletions lms/djangoapps/ccx/tests/test_ccx_modulestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
from collections import deque
from itertools import chain

import pytz
from ccx_keys.locator import CCXLocator
from six.moves import zip_longest
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory

from common.djangoapps.student.tests.factories import AdminFactory, UserFactory
from lms.djangoapps.ccx.models import CustomCourseForEdX
from zoneinfo import ZoneInfo


class TestCCXModulestoreWrapper(SharedModuleStoreTestCase):
Expand All @@ -24,8 +24,8 @@ class TestCCXModulestoreWrapper(SharedModuleStoreTestCase):
def setUpClass(cls):
super().setUpClass()
cls.course = CourseFactory.create()
start = datetime.datetime(2010, 5, 12, 2, 42, tzinfo=pytz.UTC)
due = datetime.datetime(2010, 7, 7, 0, 0, tzinfo=pytz.UTC)
start = datetime.datetime(2010, 5, 12, 2, 42, tzinfo=ZoneInfo("UTC"))
due = datetime.datetime(2010, 7, 7, 0, 0, tzinfo=ZoneInfo("UTC"))
# Create a course outline
cls.chapters = chapters = [
BlockFactory.create(start=start, parent=cls.course) for _ in range(2)
Expand Down
4 changes: 2 additions & 2 deletions lms/djangoapps/ccx/tests/test_field_override_performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from django.test.utils import override_settings
from edx_django_utils.cache import RequestCache
from opaque_keys.edx.keys import CourseKey
from pytz import UTC
from xblock.core import XBlock
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory, check_mongo_calls, check_sum_of_calls
Expand All @@ -33,6 +32,7 @@
from openedx.core.djangoapps.content.block_structure.api import get_course_in_cache
from openedx.core.djangoapps.waffle_utils.testutils import WAFFLE_TABLES
from openedx.features.content_type_gating.models import ContentTypeGatingConfig
from zoneinfo import ZoneInfo

QUERY_COUNT_TABLE_IGNORELIST = WAFFLE_TABLES

Expand Down Expand Up @@ -117,7 +117,7 @@ def setup_course(self, size, enable_ccx, view_as_ccx):

self.course = CourseFactory.create(
graded=True,
start=datetime.now(UTC),
start=datetime.now(ZoneInfo("UTC")),
grading_policy=grading_policy,
enable_ccx=enable_ccx,
)
Expand Down
18 changes: 9 additions & 9 deletions lms/djangoapps/ccx/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
from datetime import datetime, timedelta

import ddt
from pytz import utc
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory, check_mongo_calls

from common.djangoapps.student.roles import CourseCcxCoachRole
from common.djangoapps.student.tests.factories import AdminFactory
from zoneinfo import ZoneInfo

from ..overrides import override_field_for_ccx
from .factories import CcxFactory
Expand Down Expand Up @@ -59,15 +59,15 @@ def test_ccx_start_is_correct(self):
For this reason we test the difference between and make sure it is less
than one second.
"""
expected = datetime.now(utc)
expected = datetime.now(ZoneInfo("UTC"))
self.set_ccx_override('start', expected)
actual = self.ccx.start
diff = expected - actual
assert abs(diff.total_seconds()) < 1

def test_ccx_start_caching(self):
"""verify that caching the start property works to limit queries"""
now = datetime.now(utc)
now = datetime.now(ZoneInfo("UTC"))
self.set_ccx_override('start', now)
with check_mongo_calls(2):
# these statements are used entirely to demonstrate the
Expand All @@ -84,15 +84,15 @@ def test_ccx_due_without_override(self):

def test_ccx_due_is_correct(self):
"""verify that the due datetime for a ccx is correctly retrieved"""
expected = datetime.now(utc)
expected = datetime.now(ZoneInfo("UTC"))
self.set_ccx_override('due', expected)
actual = self.ccx.due
diff = expected - actual
assert abs(diff.total_seconds()) < 1

def test_ccx_due_caching(self):
"""verify that caching the due property works to limit queries"""
expected = datetime.now(utc)
expected = datetime.now(ZoneInfo("UTC"))
self.set_ccx_override('due', expected)
with check_mongo_calls(2):
# these statements are used entirely to demonstrate the
Expand All @@ -104,23 +104,23 @@ def test_ccx_due_caching(self):

def test_ccx_has_started(self):
"""verify that a ccx marked as starting yesterday has started"""
now = datetime.now(utc)
now = datetime.now(ZoneInfo("UTC"))
delta = timedelta(1)
then = now - delta
self.set_ccx_override('start', then)
assert self.ccx.has_started()

def test_ccx_has_not_started(self):
"""verify that a ccx marked as starting tomorrow has not started"""
now = datetime.now(utc)
now = datetime.now(ZoneInfo("UTC"))
delta = timedelta(1)
then = now + delta
self.set_ccx_override('start', then)
assert not self.ccx.has_started()

def test_ccx_has_ended(self):
"""verify that a ccx that has a due date in the past has ended"""
now = datetime.now(utc)
now = datetime.now(ZoneInfo("UTC"))
delta = timedelta(1)
then = now - delta
self.set_ccx_override('due', then)
Expand All @@ -129,7 +129,7 @@ def test_ccx_has_ended(self):
def test_ccx_has_not_ended(self):
"""verify that a ccx that has a due date in the future has not eneded
"""
now = datetime.now(utc)
now = datetime.now(ZoneInfo("UTC"))
delta = timedelta(1)
then = now + delta
self.set_ccx_override('due', then)
Expand Down
22 changes: 11 additions & 11 deletions lms/djangoapps/ccx/tests/test_overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import datetime
from unittest import mock

import pytz
from ccx_keys.locator import CCXLocator
from django.test.utils import override_settings
from edx_django_utils.cache import RequestCache
Expand All @@ -21,6 +20,7 @@
from lms.djangoapps.courseware.tests.test_field_overrides import inject_field_overrides
from lms.djangoapps.courseware.testutils import FieldOverrideTestMixin
from openedx.core.lib.courses import get_course_by_id
from zoneinfo import ZoneInfo


@override_settings(
Expand All @@ -41,8 +41,8 @@ def setUpClass(cls):
cls.course.enable_ccx = True

# Create a course outline
start = datetime.datetime(2010, 5, 12, 2, 42, tzinfo=pytz.UTC)
due = datetime.datetime(2010, 7, 7, 0, 0, tzinfo=pytz.UTC)
start = datetime.datetime(2010, 5, 12, 2, 42, tzinfo=ZoneInfo("UTC"))
due = datetime.datetime(2010, 7, 7, 0, 0, tzinfo=ZoneInfo("UTC"))
chapters = [BlockFactory.create(start=start, parent=cls.course)
for _ in range(2)]
sequentials = flatten([
Expand Down Expand Up @@ -91,7 +91,7 @@ def test_override_start(self):
"""
Test that overriding start date on a chapter works.
"""
ccx_start = datetime.datetime(2014, 12, 25, 00, 00, tzinfo=pytz.UTC)
ccx_start = datetime.datetime(2014, 12, 25, 00, 00, tzinfo=ZoneInfo("UTC"))
chapter = self.ccx_course.get_children()[0]
override_field_for_ccx(self.ccx, chapter, 'start', ccx_start)
assert chapter.start == ccx_start
Expand All @@ -100,7 +100,7 @@ def test_override_num_queries_new_field(self):
"""
Test that for creating new field executed only create query
"""
ccx_start = datetime.datetime(2014, 12, 25, 00, 00, tzinfo=pytz.UTC)
ccx_start = datetime.datetime(2014, 12, 25, 00, 00, tzinfo=ZoneInfo("UTC"))
chapter = self.ccx_course.get_children()[0]
# One outer SAVEPOINT/RELEASE SAVEPOINT pair around everything caused by the
# transaction.atomic decorator wrapping override_field_for_ccx.
Expand All @@ -114,8 +114,8 @@ def test_override_num_queries_update_existing_field(self):
"""
Test that overriding existing field executed create, fetch and update queries.
"""
ccx_start = datetime.datetime(2014, 12, 25, 00, 00, tzinfo=pytz.UTC)
new_ccx_start = datetime.datetime(2015, 12, 25, 00, 00, tzinfo=pytz.UTC)
ccx_start = datetime.datetime(2014, 12, 25, 00, 00, tzinfo=ZoneInfo("UTC"))
new_ccx_start = datetime.datetime(2015, 12, 25, 00, 00, tzinfo=ZoneInfo("UTC"))
chapter = self.ccx_course.get_children()[0]
override_field_for_ccx(self.ccx, chapter, 'start', ccx_start)
with self.assertNumQueries(3):
Expand All @@ -125,7 +125,7 @@ def test_override_num_queries_field_value_not_changed(self):
"""
Test that if value of field does not changed no query execute.
"""
ccx_start = datetime.datetime(2014, 12, 25, 00, 00, tzinfo=pytz.UTC)
ccx_start = datetime.datetime(2014, 12, 25, 00, 00, tzinfo=ZoneInfo("UTC"))
chapter = self.ccx_course.get_children()[0]
override_field_for_ccx(self.ccx, chapter, 'start', ccx_start)
with self.assertNumQueries(2): # 2 savepoints
Expand All @@ -135,7 +135,7 @@ def test_overriden_field_access_produces_no_extra_queries(self):
"""
Test no extra queries when accessing an overriden field more than once.
"""
ccx_start = datetime.datetime(2014, 12, 25, 00, 00, tzinfo=pytz.UTC)
ccx_start = datetime.datetime(2014, 12, 25, 00, 00, tzinfo=ZoneInfo("UTC"))
chapter = self.ccx_course.get_children()[0]
# One outer SAVEPOINT/RELEASE SAVEPOINT pair around everything caused by the
# transaction.atomic decorator wrapping override_field_for_ccx.
Expand All @@ -149,7 +149,7 @@ def test_override_is_inherited(self):
"""
Test that sequentials inherit overridden start date from chapter.
"""
ccx_start = datetime.datetime(2014, 12, 25, 00, 00, tzinfo=pytz.UTC)
ccx_start = datetime.datetime(2014, 12, 25, 00, 00, tzinfo=ZoneInfo("UTC"))
chapter = self.ccx_course.get_children()[0]
override_field_for_ccx(self.ccx, chapter, 'start', ccx_start)
assert chapter.get_children()[0].start == ccx_start
Expand All @@ -161,7 +161,7 @@ def test_override_is_inherited_even_if_set_in_mooc(self):
(verticals) even if a due date is set explicitly on grandchildren in
the mooc.
"""
ccx_due = datetime.datetime(2015, 1, 1, 00, 00, tzinfo=pytz.UTC)
ccx_due = datetime.datetime(2015, 1, 1, 00, 00, tzinfo=ZoneInfo("UTC"))
chapter = self.ccx_course.get_children()[0]
chapter.display_name = 'itsme!'
override_field_for_ccx(self.ccx, chapter, 'due', ccx_due)
Expand Down
Loading
Loading