Skip to content

Commit

Permalink
test: adds test to the allow_enrollment api method
Browse files Browse the repository at this point in the history
  • Loading branch information
tecoholic committed Aug 20, 2024
1 parent 37e84b3 commit 2626710
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
54 changes: 54 additions & 0 deletions tests/test_enterprise/api_client/test_lms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ max-line-length = 120

[pytest]
DJANGO_SETTINGS_MODULE = enterprise.settings.test
addopts = --cov enterprise --cov enterprise_learner_portal --cov consent --cov integrated_channels --cov-report term-missing --cov-report xml
# addopts = --cov enterprise --cov enterprise_learner_portal --cov consent --cov integrated_channels --cov-report term-missing --cov-report xml
norecursedirs = .* docs requirements node_modules

[isort]
Expand Down

0 comments on commit 2626710

Please sign in to comment.