Skip to content

Commit 60dd592

Browse files
feanilclaude
andcommitted
refactor: bind embargo.api.check_course_access at call time
Running `pytest openedx/core/djangoapps/embargo/tests/` in isolation fails one test because `test_redirect_if_blocked_courseware` mocks `embargo.api.check_course_access`, and the mocked call triggers the first-time import of `embargo.views`. views.py's `from .api import check_course_access` captures the MagicMock as `views.check_course_access` permanently. CI doesn't hit this because earlier shard directories preload `embargo.views` before any mock fires. Reproduces on master. Calling via the module attribute resolves at call time, so future mocks on the api function stay visible to the view. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 00f7d86 commit 60dd592

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

openedx/core/djangoapps/embargo/views.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313

1414
from common.djangoapps.edxmako.shortcuts import render_to_response
1515

16-
from . import messages
17-
from .api import check_course_access
16+
from . import api, messages
1817

1918

2019
class CheckCourseAccessView(APIView): # pylint: disable=missing-class-docstring
@@ -48,7 +47,7 @@ def get(self, request):
4847
course_key = CourseKey.from_string(course_id)
4948
except InvalidKeyError as exc:
5049
raise ValidationError('Invalid course_ids') from exc
51-
if not check_course_access(course_key, user=user, ip_addresses=[user_ip_address]):
50+
if not api.check_course_access(course_key, user=user, ip_addresses=[user_ip_address]):
5251
response['access'] = False
5352
break
5453
else:

0 commit comments

Comments
 (0)