-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add audit gate to CourseChatView #134
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
95206e7
feat: add audit gate to CourseChatView
ilee2u 2466783
test: add tests
ilee2u 046d13f
feat: add upgrade deadline gate
ilee2u 04e0710
fix: remove "created" test for trial expiration
ilee2u 0b01a7b
chore: nits
ilee2u 4de25d8
fix: distinguish between course modes correctly
ilee2u 07e446d
chore: lint
ilee2u 09d0c55
fix: correct test to cover unexpired audit trial
ilee2u File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -14,3 +14,5 @@ | |
"html": "TEXT", | ||
"video": "VIDEO", | ||
} | ||
|
||
AUDIT_TRIAL_MAX_DAYS = 14 |
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
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,6 +2,7 @@ | |
Test cases for the learning-assistant api module. | ||
""" | ||
import itertools | ||
from datetime import datetime, timedelta | ||
from unittest.mock import MagicMock, patch | ||
|
||
import ddt | ||
|
@@ -16,6 +17,7 @@ | |
_extract_block_contents, | ||
_get_children_contents, | ||
_leaf_filter, | ||
audit_trial_is_expired, | ||
get_block_content, | ||
get_message_history, | ||
learning_assistant_available, | ||
|
@@ -24,8 +26,13 @@ | |
save_chat_message, | ||
set_learning_assistant_enabled, | ||
) | ||
from learning_assistant.constants import AUDIT_TRIAL_MAX_DAYS | ||
from learning_assistant.data import LearningAssistantCourseEnabledData | ||
from learning_assistant.models import LearningAssistantCourseEnabled, LearningAssistantMessage | ||
from learning_assistant.models import ( | ||
LearningAssistantAuditTrial, | ||
LearningAssistantCourseEnabled, | ||
LearningAssistantMessage, | ||
) | ||
|
||
fake_transcript = 'This is the text version from the transcript' | ||
User = get_user_model() | ||
|
@@ -241,6 +248,7 @@ class TestLearningAssistantCourseEnabledApi(TestCase): | |
""" | ||
Test suite for save_chat_message. | ||
""" | ||
|
||
def setUp(self): | ||
super().setUp() | ||
|
||
|
@@ -473,3 +481,37 @@ def test_get_message_course_id_differences(self): | |
self.assertEqual(return_value.user, expected_value[i].user) | ||
self.assertEqual(return_value.role, expected_value[i].role) | ||
self.assertEqual(return_value.content, expected_value[i].content) | ||
|
||
|
||
@ddt.ddt | ||
class CheckIfAuditTrialIsExpiredTests(TestCase): | ||
""" | ||
Test suite for audit_trial_is_expired. | ||
""" | ||
|
||
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() | ||
|
||
self.role = 'verified' | ||
self.upgrade_deadline = datetime.now() + timedelta(days=1) # 1 day from now | ||
|
||
def test_check_if_past_upgrade_deadline(self): | ||
upgrade_deadline = datetime.now() - timedelta(days=1) # yesterday | ||
self.assertEqual(audit_trial_is_expired(self.user, upgrade_deadline), True) | ||
|
||
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(audit_trial_is_expired(self.user, self.upgrade_deadline), True) | ||
|
||
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(audit_trial_is_expired(self.user, self.upgrade_deadline), False) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a somewhat important case to cover, could a test be added to ensure that this code is still called?