Skip to content
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

When creating enrollment set is_active explicitly in the enrollment api call #2300

Merged
merged 7 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions openedx/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,13 @@ def enroll_in_edx_course_runs(
username=username,
force_enrollment=force_enrollment,
)
if not enrollment.is_active:
enrollment = edx_client.enrollments.create_student_enrollment(
course_run.courseware_id,
mode=mode,
username=username,
force_enrollment=force_enrollment,
)
results.append(enrollment)
except HTTPError as exc: # noqa: PERF203
raise EdxApiEnrollErrorException(user, course_run, exc) from exc
Expand Down
8 changes: 6 additions & 2 deletions openedx/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,11 @@ def test_enroll_in_edx_course_runs(settings, mocker, user):
"""Tests that enroll_in_edx_course_runs uses the EdxApi client to enroll in course runs"""
settings.OPENEDX_SERVICE_WORKER_API_TOKEN = "mock_api_token" # noqa: S105
mock_client = mocker.MagicMock()
enroll_return_values = ["result1", "result2"]
enroll_return_values = [
mocker.Mock(is_active=True),
mocker.Mock(is_active=False),
mocker.Mock(is_active=True),
]
mock_client.enrollments.create_student_enrollment = mocker.Mock(
side_effect=enroll_return_values
)
Expand All @@ -467,7 +471,7 @@ def test_enroll_in_edx_course_runs(settings, mocker, user):
username=user.username,
force_enrollment=True,
)
assert enroll_results == enroll_return_values
assert enroll_results == [enroll_return_values[0], enroll_return_values[2]]


def test_enroll_api_fail(mocker, user):
Expand Down
Loading