-
Notifications
You must be signed in to change notification settings - Fork 6
JU-6: add support for openedx-filters #573
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| """ | ||
| Test that various filters are fired for models in the student app. | ||
| """ | ||
| from common.djangoapps.student.models import CourseEnrollment, EnrollmentNotAllowed | ||
| from common.djangoapps.student.tests.factories import UserFactory, UserProfileFactory | ||
|
|
||
| from openedx.core.djangolib.testing.utils import skip_unless_lms | ||
| from django.test import TestCase, override_settings | ||
| from openedx_filters.learning.enrollment import PreEnrollmentFilter | ||
|
|
||
|
|
||
| from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase | ||
| from xmodule.modulestore.tests.factories import CourseFactory | ||
|
|
||
| from openedx_filters import PipelineStep | ||
|
|
||
|
|
||
| class TestEnrollmentPipelineStep(PipelineStep): | ||
| """ | ||
| Utility function used when getting steps for pipeline. | ||
| """ | ||
|
|
||
| def run(self, user, course_key, mode): | ||
| """Pipeline steps that changes mode to honor.""" | ||
| if mode == "no-id-professional": | ||
| raise PreEnrollmentFilter.PreventEnrollment() | ||
| return {"mode": "honor"} | ||
|
|
||
|
|
||
| @skip_unless_lms | ||
| class EnrollmentFiltersTest(ModuleStoreTestCase): | ||
| """ | ||
| Tests for the Open edX Filters associated with the enrollment process through the enroll method. | ||
|
|
||
| This class guarantees that the following filters are triggered during the user's enrollment: | ||
|
|
||
| - PreEnrollmentFilter | ||
| """ | ||
|
|
||
| def setUp(self): # pylint: disable=arguments-differ | ||
| super().setUp() | ||
| self.course = CourseFactory.create() | ||
| self.user = UserFactory.create( | ||
| username="test", | ||
| email="test@example.com", | ||
| password="password", | ||
| ) | ||
| self.user_profile = UserProfileFactory.create(user=self.user, name="Test Example") | ||
|
|
||
| @override_settings( | ||
| OPEN_EDX_FILTERS_CONFIG={ | ||
| "org.openedx.learning.course.enrollment.started.v1": { | ||
| "pipeline": [ | ||
| "common.djangoapps.student.tests.test_filters.TestEnrollmentPipelineStep", | ||
| ], | ||
| "fail_silently": False, | ||
| }, | ||
| }, | ||
| ) | ||
| def test_enrollment_filter_executed(self): | ||
| """ | ||
| Test whether the student enrollment filter is triggered before the user's | ||
| enrollment process. | ||
|
|
||
| Expected result: | ||
| - PreEnrollmentFilter is triggered and executes TestEnrollmentPipelineStep. | ||
| - The arguments that the receiver gets are the arguments used by the filter | ||
| with the enrollment mode changed. | ||
| """ | ||
| enrollment = CourseEnrollment.enroll(self.user, self.course.id, mode='audit') | ||
|
|
||
| self.assertEqual('honor', enrollment.mode) | ||
|
|
||
| @override_settings( | ||
| OPEN_EDX_FILTERS_CONFIG={ | ||
| "org.openedx.learning.course.enrollment.started.v1": { | ||
| "pipeline": [ | ||
| "common.djangoapps.student.tests.test_filters.TestEnrollmentPipelineStep", | ||
| ], | ||
| "fail_silently": False, | ||
| }, | ||
| }, | ||
| ) | ||
| def test_enrollment_filter_prevent_enroll(self): | ||
| """ | ||
| Test prevent the user's enrollment through a pipeline step. | ||
|
|
||
| Expected result: | ||
| - PreEnrollmentFilter is triggered and executes TestEnrollmentPipelineStep. | ||
| - The user can't enroll. | ||
| """ | ||
| with self.assertRaises(EnrollmentNotAllowed): | ||
| CourseEnrollment.enroll(self.user, self.course.id, mode='no-id-professional') |
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
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.