-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use django utils timezone to make timezone aware
- Loading branch information
1 parent
bcf2974
commit 4887120
Showing
2 changed files
with
14 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,16 @@ | |
Test cases for the learning-assistant api module. | ||
""" | ||
import itertools | ||
from datetime import datetime, timedelta, timezone | ||
import zoneinfo | ||
from datetime import datetime, timedelta | ||
from unittest.mock import MagicMock, patch | ||
|
||
import ddt | ||
from django.conf import settings | ||
from django.contrib.auth import get_user_model | ||
from django.core.cache import cache | ||
from django.test import TestCase, override_settings | ||
from django.utils import timezone | ||
from freezegun import freeze_time | ||
from opaque_keys import InvalidKeyError | ||
from opaque_keys.edx.keys import CourseKey, UsageKey | ||
|
@@ -593,15 +595,15 @@ class CheckIfAuditTrialIsExpiredTests(TestCase): | |
Test suite for audit_trial_is_expired. | ||
""" | ||
|
||
@freeze_time('2024-01-01 00:00:01') | ||
def setUp(self): | ||
super().setUp() | ||
self.course_key = CourseKey.from_string('course-v1:edx+fake+1') | ||
self.user = User(username='tester', email='[email protected]') | ||
self.user.save() | ||
|
||
@freeze_time('2024-01-01 00:00:01 UTC') | ||
def test_upgrade_deadline_expired(self): | ||
today = datetime.now(tz=timezone.utc) | ||
today = timezone.now() | ||
mock_enrollment = MagicMock() | ||
mock_enrollment.upgrade_deadline = today - timedelta(days=1) # yesterday | ||
|
||
|
@@ -614,9 +616,8 @@ def test_upgrade_deadline_expired(self): | |
|
||
self.assertEqual(audit_trial_is_expired(mock_enrollment, audit_trial_data), True) | ||
|
||
@freeze_time('2024-01-01 00:00:01 UTC') | ||
def test_upgrade_deadline_none(self): | ||
today = datetime.now(tz=timezone.utc) | ||
today = datetime.now() | ||
mock_enrollment = MagicMock() | ||
mock_enrollment.upgrade_deadline = None | ||
|
||
|
@@ -642,15 +643,12 @@ def test_upgrade_deadline_none(self): | |
|
||
@ddt.data( | ||
# exactly the trial deadline | ||
datetime(year=2024, month=1, day=1, tzinfo=timezone.utc) - | ||
timedelta(days=settings.LEARNING_ASSISTANT_AUDIT_TRIAL_LENGTH_DAYS), | ||
datetime(year=2024, month=1, day=1) - timedelta(days=settings.LEARNING_ASSISTANT_AUDIT_TRIAL_LENGTH_DAYS), | ||
# 1 day more than trial deadline | ||
datetime(year=2024, month=1, day=1, tzinfo=timezone.utc) - | ||
timedelta(days=settings.LEARNING_ASSISTANT_AUDIT_TRIAL_LENGTH_DAYS + 1), | ||
datetime(year=2024, month=1, day=1) - timedelta(days=settings.LEARNING_ASSISTANT_AUDIT_TRIAL_LENGTH_DAYS + 1), | ||
) | ||
@freeze_time('2024-01-01 00:00:01 UTC') | ||
def test_audit_trial_expired(self, start_date): | ||
today = datetime.now(tz=timezone.utc) | ||
today = datetime.now() | ||
mock_enrollment = MagicMock() | ||
mock_enrollment.upgrade_deadline = today + timedelta(days=1) # tomorrow | ||
|
||
|
@@ -662,9 +660,8 @@ def test_audit_trial_expired(self, start_date): | |
|
||
self.assertEqual(audit_trial_is_expired(mock_enrollment, audit_trial_data), True) | ||
|
||
@freeze_time('2024-01-01 00:00:01 UTC') | ||
def test_audit_trial_unexpired(self): | ||
today = datetime.now(tz=timezone.utc) | ||
today = datetime.now() | ||
mock_enrollment = MagicMock() | ||
mock_enrollment.upgrade_deadline = today + timedelta(days=1) # tomorrow | ||
|
||
|