Skip to content

Commit

Permalink
feat: add timezones constants
Browse files Browse the repository at this point in the history
  • Loading branch information
mumarkhan999 committed Jan 7, 2025
1 parent 4cc30a6 commit d7fde51
Show file tree
Hide file tree
Showing 7 changed files with 429 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Unit tests for home page view.
"""
import ddt
import pytz
from collections import OrderedDict
from datetime import datetime, timedelta
from django.conf import settings
Expand All @@ -12,6 +11,7 @@
override_waffle_switch,
)
from rest_framework import status
from zoneinfo import ZoneInfo

from cms.djangoapps.contentstore.tests.utils import CourseTestCase
from cms.djangoapps.contentstore.tests.test_libraries import LibraryTestCase
Expand Down Expand Up @@ -193,7 +193,7 @@ def test_filter_and_ordering_courses(
display_name="Course (Demo)",
id=archived_course_key,
org=archived_course_key.org,
end=(datetime.now() - timedelta(days=365)).replace(tzinfo=pytz.UTC),
end=(datetime.now() - timedelta(days=365)).replace(tzinfo=ZoneInfo("UTC")),
)
active_course_key = self.store.make_course_key("sample-org", "sample-number", "sample-run")
CourseOverviewFactory.create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
from unittest.mock import patch

import ddt
from zoneinfo import ZoneInfo
from django.conf import settings
from django.test import override_settings
from django.urls import reverse
from edx_toggles.toggles.testutils import override_waffle_switch
from rest_framework import status
from zoneinfo import ZoneInfo

from cms.djangoapps.contentstore.tests.utils import CourseTestCase
from cms.djangoapps.contentstore.utils import reverse_course_url
Expand Down Expand Up @@ -303,7 +303,7 @@ def test_filter_and_ordering_courses(
display_name="Course (Demo)",
id=archived_course_key,
org=archived_course_key.org,
end=(datetime.now() - timedelta(days=365)).replace(tzinfo=pytz.UTC),
end=(datetime.now() - timedelta(days=365)).replace(tzinfo=ZoneInfo("UTC")),
)
active_course_key = self.store.make_course_key("foo-org", "foo-number", "foo-run")
CourseOverviewFactory.create(
Expand Down
2 changes: 1 addition & 1 deletion cms/djangoapps/contentstore/tests/test_courseware_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ def test_delete_course_from_search_index_after_course_deletion(self):
self._test_delete_course_from_search_index_after_course_deletion(self.store)

def test_empty_course(self):
empty_course = CourseFactory.create(modulestore=self.store, start=datetime(2015, 3, 1, tzinfo=UTC))
empty_course = CourseFactory.create(modulestore=self.store, start=datetime(2015, 3, 1, tzinfo=ZoneInfo("UTC")))
added_to_index = CoursewareSearchIndexer.do_course_reindex(self.store, empty_course.id)
assert added_to_index == 0

Expand Down
12 changes: 6 additions & 6 deletions lms/djangoapps/mobile_api/users/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ class TestUserEnrollmentApi(UrlResetMixin, MobileAPITestCase, MobileAuthUserTest
ALLOW_ACCESS_TO_UNRELEASED_COURSE = True
ALLOW_ACCESS_TO_MILESTONE_COURSE = True
ALLOW_ACCESS_TO_NON_VISIBLE_COURSE = True
NEXT_WEEK = datetime.datetime.now(ZoneInfo("UTC")) + datetime.timedelta(days=7)
LAST_WEEK = datetime.datetime.now(ZoneInfo("UTC")) - datetime.timedelta(days=7)
NEXT_WEEK = datetime.datetime.now(ZoneInfo('UTC')) + datetime.timedelta(days=7)
LAST_WEEK = datetime.datetime.now(ZoneInfo('UTC')) - datetime.timedelta(days=7)
THREE_YEARS_AGO = now() - datetime.timedelta(days=(365 * 3))
ADVERTISED_START = "Spring 2016"
ENABLED_SIGNALS = ['course_published']
Expand Down Expand Up @@ -1438,7 +1438,7 @@ def test_user_have_active_and_inactive_enrollments_and_no_completions(self) -> N
old_course = CourseFactory.create(org="edx", mobile_available=True)
self.enroll(old_course.id)
old_enrollment = CourseEnrollment.objects.filter(user=self.user, course=old_course.course_id).first()
old_enrollment.created = datetime.datetime.now(pytz.UTC) - datetime.timedelta(days=31)
old_enrollment.created = datetime.datetime.now(ZoneInfo('UTC')) - datetime.timedelta(days=31)
old_enrollment.save()

response = self.api_response(api_version=API_V1)
Expand Down Expand Up @@ -1466,7 +1466,7 @@ def test_different_enrollment_dates(self, enrolled_days_ago: int, recently_activ
course = CourseFactory.create(org="edx", mobile_available=True, run='1001')
self.enroll(course.id)
enrollment = CourseEnrollment.objects.filter(user=self.user, course=course.course_id).first()
enrollment.created = datetime.datetime.now(pytz.UTC) - datetime.timedelta(days=enrolled_days_ago)
enrollment.created = datetime.datetime.now(ZoneInfo('UTC')) - datetime.timedelta(days=enrolled_days_ago)
enrollment.save()

response = self.api_response(api_version=API_V1)
Expand Down Expand Up @@ -1500,7 +1500,7 @@ def test_different_completion_dates(self, completed_days_ago: int, recently_acti
self.enroll(course.id)
enrollment = CourseEnrollment.objects.filter(user=self.user, course=course.course_id).first()
# make enrollment older 30 days ago
enrollment.created = datetime.datetime.now(pytz.UTC) - datetime.timedelta(days=50)
enrollment.created = datetime.datetime.now(ZoneInfo('UTC')) - datetime.timedelta(days=50)
enrollment.save()
completion = BlockCompletion.objects.create(
user=self.user,
Expand All @@ -1509,7 +1509,7 @@ def test_different_completion_dates(self, completed_days_ago: int, recently_acti
block_key=section.location,
completion=0.5,
)
completion.created = datetime.datetime.now(pytz.UTC) - datetime.timedelta(days=completed_days_ago)
completion.created = datetime.datetime.now(ZoneInfo('UTC')) - datetime.timedelta(days=completed_days_ago)
completion.save()

response = self.api_response(api_version=API_V1)
Expand Down
4 changes: 2 additions & 2 deletions lms/djangoapps/mobile_api/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from functools import cached_property
from typing import Dict, List, Optional, Set

import pytz
from completion.exceptions import UnavailableCompletionData
from completion.models import BlockCompletion
from completion.utilities import get_key_to_last_completed_block
Expand All @@ -25,6 +24,7 @@
from rest_framework.decorators import api_view
from rest_framework.permissions import SAFE_METHODS
from rest_framework.response import Response
from zoneinfo import ZoneInfo
from xblock.fields import Scope
from xblock.runtime import KeyValueStore
from edx_rest_framework_extensions.paginators import DefaultPagination
Expand Down Expand Up @@ -597,7 +597,7 @@ def get(self, request, *args, **kwargs) -> Response:
"""
Gets user's enrollments status.
"""
active_status_date = datetime.datetime.now(pytz.UTC) - datetime.timedelta(days=30)
active_status_date = datetime.datetime.now(ZoneInfo('UTC')) - datetime.timedelta(days=30)
username = kwargs.get('username')
course_ids_where_user_has_completions = self._get_course_ids_where_user_has_completions(
username,
Expand Down
Loading

0 comments on commit d7fde51

Please sign in to comment.