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.
test: adds test to the allow_enrollment api method
- Loading branch information
Showing
2 changed files
with
55 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
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