forked from openedx/edx-enterprise
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds support for enrolling users in invite-only courses
- Loading branch information
Showing
11 changed files
with
294 additions
and
1 deletion.
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
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
23 changes: 23 additions & 0 deletions
23
...se/migrations/0207_enterprisecustomer_allow_enrollment_in_invite_only_courses_and_more.py
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Generated by Django 4.2.13 on 2024-12-06 03:48 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('enterprise', '0206_auto_20240408_1344'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='enterprisecustomer', | ||
name='allow_enrollment_in_invite_only_courses', | ||
field=models.BooleanField(default=False, help_text="Specifies if learners are allowed to enroll into courses marked as 'invitation-only', when they attempt to enroll from the landing page."), | ||
), | ||
migrations.AddField( | ||
model_name='historicalenterprisecustomer', | ||
name='allow_enrollment_in_invite_only_courses', | ||
field=models.BooleanField(default=False, help_text="Specifies if learners are allowed to enroll into courses marked as 'invitation-only', when they attempt to enroll from the landing page."), | ||
), | ||
] |
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
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 |
---|---|---|
|
@@ -449,6 +449,60 @@ def test_unenroll_already_unenrolled(): | |
assert not unenrolled | ||
|
||
|
||
@responses.activate | ||
@mock.patch('enterprise.api_client.client.JwtBuilder', mock.Mock()) | ||
def test_allow_enrollment(): | ||
email = "[email protected]" | ||
course_id = "course-v1:edX+DemoX+Demo_Course" | ||
expected_response = { | ||
"email": email, | ||
"course_id": course_id, | ||
"auto_enroll": False | ||
} | ||
responses.add( | ||
responses.POST, | ||
_url("enrollment", "enrollment_allowed/"), | ||
json=expected_response, | ||
) | ||
|
||
client = lms_api.EnrollmentApiClient() | ||
allowed = client.allow_enrollment(email, course_id) | ||
assert allowed == expected_response | ||
|
||
|
||
@responses.activate | ||
@mock.patch('enterprise.api_client.client.JwtBuilder', mock.Mock()) | ||
def test_allow_enrollment_raises_an_exception_on_error(): | ||
expected_response = {"message": "Bad Request"} | ||
responses.add( | ||
responses.POST, | ||
_url("enrollment", "enrollment_allowed/"), | ||
json=expected_response, | ||
status=requests.codes.bad_request | ||
) | ||
|
||
client = lms_api.EnrollmentApiClient() | ||
with raises(requests.HTTPError): | ||
client.allow_enrollment("", "") | ||
|
||
|
||
@responses.activate | ||
@mock.patch('enterprise.api_client.client.JwtBuilder', mock.Mock()) | ||
def test_allow_enrollment_does_not_raise_exception_on_conflict(): | ||
email = "[email protected]" | ||
course_id = "course-v1:edX+DemoX+Demo_Course" | ||
expected_response = {"message": f"An enrollment allowed with email {email} and course {course_id} already exists."} | ||
responses.add( | ||
responses.POST, | ||
_url("enrollment", "enrollment_allowed/"), | ||
json=expected_response, | ||
status=requests.codes.conflict | ||
) | ||
|
||
client = lms_api.EnrollmentApiClient() | ||
assert expected_response == client.allow_enrollment(email, course_id) | ||
|
||
|
||
@responses.activate | ||
def test_get_full_course_details(): | ||
course_id = "course-v1:edX+DemoX+Demo_Course" | ||
|
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
Oops, something went wrong.