Skip to content

Commit

Permalink
chore: nits
Browse files Browse the repository at this point in the history
  • Loading branch information
ilee2u committed Nov 20, 2024
1 parent 04e0710 commit 0b01a7b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
6 changes: 2 additions & 4 deletions learning_assistant/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def get_message_history(courserun_key, user, message_count):
return message_history


def check_if_audit_trial_is_expired(user, upgrade_deadline):
def audit_trial_is_expired(user, upgrade_deadline):
"""
Given a user (User), get or create the corresponding LearningAssistantAuditTrial trial object.
"""
Expand All @@ -249,6 +249,4 @@ def check_if_audit_trial_is_expired(user, upgrade_deadline):

# If the user's trial is past its expiry date, return "True" for expired. Else, return False
DAYS_SINCE_TRIAL_START_DATE = datetime.now() - audit_trial.start_date
if DAYS_SINCE_TRIAL_START_DATE >= timedelta(days=AUDIT_TRIAL_MAX_DAYS):
return True
return False
return DAYS_SINCE_TRIAL_START_DATE >= timedelta(days=AUDIT_TRIAL_MAX_DAYS)
5 changes: 2 additions & 3 deletions learning_assistant/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
pass

from learning_assistant.api import (
check_if_audit_trial_is_expired,
audit_trial_is_expired,
get_course_id,
get_message_history,
learning_assistant_enabled,
Expand Down Expand Up @@ -80,12 +80,11 @@ def post(self, request, course_run_id):
and enrollment_mode in CourseMode.AUDIT_MODES
and not user_role_is_staff(user_role)
):
# TODO: Add logic to make sure upgrade deadline has not passed.
course_mode = CourseMode.objects.get(course=courserun_key)
upgrade_deadline = course_mode.expiration_datetime()

# If user has an audit enrollment record, get or create their trial
user_audit_trial_expired = check_if_audit_trial_is_expired(request.user, upgrade_deadline)
user_audit_trial_expired = audit_trial_is_expired(request.user, upgrade_deadline)
if user_audit_trial_expired:
return Response(
status=http_status.HTTP_403_FORBIDDEN,
Expand Down
14 changes: 7 additions & 7 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
_extract_block_contents,
_get_children_contents,
_leaf_filter,
check_if_audit_trial_is_expired,
audit_trial_is_expired,
get_block_content,
get_message_history,
learning_assistant_available,
Expand Down Expand Up @@ -486,7 +486,7 @@ def test_get_message_course_id_differences(self):
@ddt.ddt
class CheckIfAuditTrialIsExpiredTests(TestCase):
"""
Test suite for check_if_audit_trial_is_expired.
Test suite for audit_trial_is_expired.
"""

def setUp(self):
Expand All @@ -500,18 +500,18 @@ def setUp(self):

def test_check_if_past_upgrade_deadline(self):
upgrade_deadline = datetime.now() - timedelta(days=1) # yesterday
self.assertEqual(check_if_audit_trial_is_expired(self.user, upgrade_deadline), True)
self.assertEqual(audit_trial_is_expired(self.user, upgrade_deadline), True)

def test_check_if_audit_trial_is_expired_audit_trial_expired(self):
def test_audit_trial_is_expired_audit_trial_expired(self):
LearningAssistantAuditTrial.objects.create(
user=self.user,
start_date=datetime.now() - timedelta(days=AUDIT_TRIAL_MAX_DAYS + 1), # 1 day more than trial deadline
)
self.assertEqual(check_if_audit_trial_is_expired(self.user, self.upgrade_deadline), True)
self.assertEqual(audit_trial_is_expired(self.user, self.upgrade_deadline), True)

def test_check_if_audit_trial_is_expired_audit_trial_unexpired(self):
def test_audit_trial_is_expired_audit_trial_unexpired(self):
LearningAssistantAuditTrial.objects.create(
user=self.user,
start_date=datetime.now() - timedelta(days=AUDIT_TRIAL_MAX_DAYS - 0.99), # 0.99 days less than deadline
)
self.assertEqual(check_if_audit_trial_is_expired(self.user, self.upgrade_deadline), False)
self.assertEqual(audit_trial_is_expired(self.user, self.upgrade_deadline), False)
2 changes: 1 addition & 1 deletion tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def test_course_waffle_inactive(self, mock_waffle):
response = self.client.post(reverse('chat', kwargs={'course_run_id': self.course_id}))
self.assertEqual(response.status_code, 403)

@patch('learning_assistant.views.check_if_audit_trial_is_expired')
@patch('learning_assistant.views.audit_trial_is_expired')
@patch('learning_assistant.views.learning_assistant_enabled')
@patch('learning_assistant.views.get_user_role')
@patch('learning_assistant.views.CourseEnrollment.get_enrollment')
Expand Down

0 comments on commit 0b01a7b

Please sign in to comment.