From 0b01a7bf2e49ba85bebd00b89ff3d395ff2ae9c6 Mon Sep 17 00:00:00 2001 From: ilee2u Date: Wed, 20 Nov 2024 15:22:23 -0500 Subject: [PATCH] chore: nits --- learning_assistant/api.py | 6 ++---- learning_assistant/views.py | 5 ++--- tests/test_api.py | 14 +++++++------- tests/test_views.py | 2 +- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/learning_assistant/api.py b/learning_assistant/api.py index 0d1c67f..3857945 100644 --- a/learning_assistant/api.py +++ b/learning_assistant/api.py @@ -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. """ @@ -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) diff --git a/learning_assistant/views.py b/learning_assistant/views.py index 7e69ee8..bf468fd 100644 --- a/learning_assistant/views.py +++ b/learning_assistant/views.py @@ -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, @@ -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, diff --git a/tests/test_api.py b/tests/test_api.py index d0abc97..d73af07 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -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, @@ -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): @@ -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) diff --git a/tests/test_views.py b/tests/test_views.py index 3b47cf7..bd5aa5b 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -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')