forked from openedx/edx-platform
-
Notifications
You must be signed in to change notification settings - Fork 2
feat: audit preview of verified content in course outline #42
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
80da588
feat: add toggle for audit preview of verified content
nsprenkle 72a6b05
docs: fix incorrect docstring
nsprenkle 67a6b1f
feat: add extended logic for when a user / course should allow audit …
nsprenkle 2a1bc07
feat: when audit preview of verified content is enabled, mark non-aud…
nsprenkle e2c95be
feat: mark previewable sections for audit learners who can preview ve…
nsprenkle 935a53f
style: fix typo in name
nsprenkle 3c2141e
refactor: more efficient verified preview check
nsprenkle 84d0f0c
test: add tests for Course Home API toggle logic
nsprenkle ca0f6c1
test: add tests for outline view with audit preview
nsprenkle ac59048
test: add tests for outline processing with verified preveiw
nsprenkle 9615573
style: fix pycodestyle issues
nsprenkle 06a298f
style: fix pylint issues
nsprenkle 34e270d
style: fix line too long
nsprenkle efc774a
refactor: remove LMS / common coupling
nsprenkle d3a247e
fix: correctly implement verified mode check in toggle
nsprenkle 85f5f3d
fix: restore incorrectly removed check for enrollment track partition
nsprenkle 6cf31a4
docs: fix docstring
nsprenkle 04635ad
test: fix test typos
nsprenkle 5cd98d8
fix: correct nesting of previewable sequence marking
nsprenkle 35f643f
feat: add caching to learner toggle
nsprenkle 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| """ | ||
| Tests for Course Home API toggles. | ||
| """ | ||
|
|
||
| from unittest.mock import Mock, patch | ||
|
|
||
| from django.test import TestCase | ||
| from opaque_keys.edx.keys import CourseKey | ||
|
|
||
| from common.djangoapps.course_modes.models import CourseMode | ||
| from common.djangoapps.course_modes.tests.factories import CourseModeFactory | ||
|
|
||
| from ..toggles import learner_can_preview_verified_content | ||
|
|
||
|
|
||
| class TestLearnerCanPreviewVerifiedContent(TestCase): | ||
| """Test cases for learner_can_preview_verified_content function.""" | ||
|
|
||
| def setUp(self): | ||
| """Set up test fixtures.""" | ||
| self.course_key = CourseKey.from_string("course-v1:TestX+CS101+2024") | ||
| self.user = Mock() | ||
|
|
||
| # Set up patchers | ||
| self.feature_enabled_patcher = patch( | ||
| "lms.djangoapps.course_home_api.toggles.audit_learner_verified_preview_is_enabled" | ||
| ) | ||
| self.verified_mode_for_course_patcher = patch( | ||
| "common.djangoapps.course_modes.models.CourseMode.verified_mode_for_course" | ||
| ) | ||
| self.get_enrollment_patcher = patch( | ||
| "common.djangoapps.student.models.CourseEnrollment.get_enrollment" | ||
| ) | ||
|
|
||
| # Course set up with verified, professional, and audit modes | ||
| self.verified_mode = CourseModeFactory( | ||
| course_id=self.course_key, | ||
| mode_slug=CourseMode.VERIFIED, | ||
| mode_display_name="Verified", | ||
| ) | ||
| self.professional_mode = CourseModeFactory( | ||
| course_id=self.course_key, | ||
| mode_slug=CourseMode.PROFESSIONAL, | ||
| mode_display_name="Professional", | ||
| ) | ||
| self.audit_mode = CourseModeFactory( | ||
| course_id=self.course_key, | ||
| mode_slug=CourseMode.AUDIT, | ||
| mode_display_name="Audit", | ||
| ) | ||
| self.course_modes_dict = { | ||
| "audit": self.audit_mode, | ||
| "verified": self.verified_mode, | ||
| "professional": self.professional_mode, | ||
| } | ||
|
|
||
| # Start patchers | ||
| self.mock_feature_enabled = self.feature_enabled_patcher.start() | ||
| self.mock_verified_mode_for_course = ( | ||
| self.verified_mode_for_course_patcher.start() | ||
| ) | ||
| self.mock_get_enrollment = self.get_enrollment_patcher.start() | ||
|
|
||
| def _enroll_user(self, mode): | ||
| """Helper method to set up user enrollment mock.""" | ||
| mock_enrollment = Mock() | ||
| mock_enrollment.mode = mode | ||
| self.mock_get_enrollment.return_value = mock_enrollment | ||
|
|
||
| def tearDown(self): | ||
| """Clean up patchers.""" | ||
| self.feature_enabled_patcher.stop() | ||
| self.verified_mode_for_course_patcher.stop() | ||
| self.get_enrollment_patcher.stop() | ||
|
|
||
| def test_all_conditions_met_returns_true(self): | ||
| """Test that function returns True when all conditions are met.""" | ||
| # Given the feature is enabled, course has verified mode, and user is enrolled as audit | ||
| self.mock_feature_enabled.return_value = True | ||
| self.mock_verified_mode_for_course.return_value = self.course_modes_dict[ | ||
| "professional" | ||
nsprenkle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ] | ||
| self._enroll_user(CourseMode.AUDIT) | ||
|
|
||
| # When I check if the learner can preview verified content | ||
| result = learner_can_preview_verified_content(self.course_key, self.user) | ||
|
|
||
| # Then the result should be True | ||
| self.assertTrue(result) | ||
|
|
||
| def test_feature_disabled_returns_false(self): | ||
| """Test that function returns False when feature is disabled.""" | ||
| # Given the feature is disabled | ||
| self.mock_feature_enabled.return_value = False | ||
|
|
||
| # ... even if all other conditions are met | ||
| self.mock_verified_mode_for_course.return_value = self.course_modes_dict[ | ||
| "professional" | ||
| ] | ||
nsprenkle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| self._enroll_user(CourseMode.AUDIT) | ||
|
|
||
| # When I check if the learner can preview verified content | ||
| result = learner_can_preview_verified_content(self.course_key, self.user) | ||
|
|
||
| # Then the result should be False | ||
| self.assertFalse(result) | ||
|
|
||
| def test_no_verified_mode_returns_false(self): | ||
| """Test that function returns False when course has no verified mode.""" | ||
| # Given the course does not have a verified mode | ||
| self.mock_verified_mode_for_course.return_value = None | ||
|
|
||
| # ... even if all other conditions are met | ||
| self.mock_feature_enabled.return_value = True | ||
| self._enroll_user(CourseMode.AUDIT) | ||
|
|
||
| # When I check if the learner can preview verified content | ||
| result = learner_can_preview_verified_content(self.course_key, self.user) | ||
|
|
||
| # Then the result should be False | ||
| self.assertFalse(result) | ||
|
|
||
| def test_no_enrollment_returns_false(self): | ||
| """Test that function returns False when user is not enrolled.""" | ||
| # Given the user is unenrolled | ||
| self.mock_get_enrollment.return_value = None | ||
|
|
||
| # ... even if all other conditions are met | ||
| self.mock_feature_enabled.return_value = True | ||
| self.mock_verified_mode_for_course.return_value = self.course_modes_dict[ | ||
| "professional" | ||
| ] | ||
|
|
||
| # When I check if the learner can preview verified content | ||
| result = learner_can_preview_verified_content(self.course_key, self.user) | ||
|
|
||
| # Then the result should be False | ||
| self.assertFalse(result) | ||
|
|
||
| def test_verified_enrollment_returns_false(self): | ||
| """Test that function returns False when user is enrolled in verified mode.""" | ||
| # Given the user is not enrolled as audit | ||
| self._enroll_user(CourseMode.VERIFIED) | ||
|
|
||
| # ... even if all other conditions are met | ||
| self.mock_feature_enabled.return_value = True | ||
| self.mock_verified_mode_for_course.return_value = self.course_modes_dict[ | ||
| "professional" | ||
| ] | ||
|
|
||
| # When I check if the learner can preview verified content | ||
| result = learner_can_preview_verified_content(self.course_key, self.user) | ||
|
|
||
| # Then the result should be False | ||
| self.assertFalse(result) | ||
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.