Skip to content

Commit

Permalink
When creating enrollment set is_active explicitly in the enrollment a…
Browse files Browse the repository at this point in the history
…pi call (#2300)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
annagav and pre-commit-ci[bot] authored Jul 31, 2024
1 parent 98084b9 commit 5a532d3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
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

0 comments on commit 5a532d3

Please sign in to comment.