diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/vertical_block.py b/cms/djangoapps/contentstore/rest_api/v1/views/vertical_block.py index c308615889c9..85e14de15f81 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/vertical_block.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/vertical_block.py @@ -283,7 +283,7 @@ def get(self, request: Request, usage_key_string: str): child_info = modulestore().get_item(child) user_partition_info = get_visibility_partition_info(child_info, course=course) user_partitions = get_user_partition_info(child_info, course=course) - upstream_link = UpstreamLink.try_fetch_for_block(child_info) + upstream_link = UpstreamLink.try_get_for_block(child_info) validation_messages = get_xblock_validation_messages(child_info) render_error = get_xblock_render_error(request, child_info) diff --git a/cms/djangoapps/contentstore/rest_api/v2/views/downstreams.py b/cms/djangoapps/contentstore/rest_api/v2/views/downstreams.py index 715decfd6a3b..1f6b9e2134e1 100644 --- a/cms/djangoapps/contentstore/rest_api/v2/views/downstreams.py +++ b/cms/djangoapps/contentstore/rest_api/v2/views/downstreams.py @@ -106,7 +106,7 @@ def get(self, request: Request, usage_key_string: str) -> Response: Inspect an XBlock's link to upstream content. """ downstream = _load_accessible_downstream_block(request.user, usage_key_string, require_write_access=False) - if link := UpstreamLink.try_fetch_for_block(downstream): + if link := UpstreamLink.try_get_for_block(downstream): return Response(link.to_json()) raise NotFound(detail=f"Block '{usage_key_string}' is not found") @@ -141,7 +141,7 @@ def post(self, request: Request, usage_key_string: str) -> Response: except (BadUpstream, BadDownstream) as exc: raise ValidationError(detail=str(exc)) from exc modulestore().update_item(downstream, request.user.id) - return Response(UpstreamLink.fetch_for_block(downstream).to_json(), status=200) + return Response(UpstreamLink.get_for_block(downstream).to_json(), status=200) def delete(self, request: Request, usage_key_string: str) -> Response: """ diff --git a/cms/djangoapps/contentstore/rest_api/v2/views/tests/test_downstreams.py b/cms/djangoapps/contentstore/rest_api/v2/views/tests/test_downstreams.py index b961f92acfc5..fa2972f2e869 100644 --- a/cms/djangoapps/contentstore/rest_api/v2/views/tests/test_downstreams.py +++ b/cms/djangoapps/contentstore/rest_api/v2/views/tests/test_downstreams.py @@ -13,7 +13,7 @@ MOCK_UPSTREAM_ERROR = "your LibraryGPT subscription has expired" -def _fetch_upstream_link_good_and_syncable(downstream): +def _get_upstream_link_good_and_syncable(downstream): return UpstreamLink( upstream_ref=downstream.upstream, version_synced=downstream.upstream_version, @@ -24,7 +24,7 @@ def _fetch_upstream_link_good_and_syncable(downstream): ) -def _fetch_upstream_link_bad(_downstream): +def _get_upstream_link_bad(_downstream): raise BadUpstream(MOCK_UPSTREAM_ERROR) @@ -50,7 +50,7 @@ def setUp(self): self.superuser = UserFactory(username="superuser", password="password", is_staff=True, is_superuser=True) self.learner = UserFactory(username="learner", password="password") - @patch.object(UpstreamLink, "fetch_for_block", _fetch_upstream_link_good_and_syncable) + @patch.object(UpstreamLink, "get_for_block", _get_upstream_link_good_and_syncable) def test_200_good_upstream(self): """ Does the happy path work? @@ -62,7 +62,7 @@ def test_200_good_upstream(self): assert response.data['error_message'] is None assert response.data['ready_to_sync'] is True - @patch.object(UpstreamLink, "fetch_for_block", _fetch_upstream_link_bad) + @patch.object(UpstreamLink, "get_for_block", _get_upstream_link_bad) def test_200_bad_upstream(self): """ If the upstream link is broken, do we still return 200, but with an error message in body? diff --git a/cms/lib/xblock/test/test_upstream_sync.py b/cms/lib/xblock/test/test_upstream_sync.py index ee3265dc87df..85ac4d78b640 100644 --- a/cms/lib/xblock/test/test_upstream_sync.py +++ b/cms/lib/xblock/test/test_upstream_sync.py @@ -227,7 +227,7 @@ def test_prompt_and_decline_sync(self): """ # Initial conditions (pre-sync) downstream = BlockFactory.create(category='html', parent=self.unit, upstream=str(self.upstream_key)) - link = UpstreamLink.fetch_for_block(downstream) + link = UpstreamLink.get_for_block(downstream) assert link.version_synced is None assert link.version_declined is None assert link.version_available == 2 # Library block with content starts at version 2 @@ -235,7 +235,7 @@ def test_prompt_and_decline_sync(self): # Initial sync to V2 sync_from_upstream(downstream, self.user, apply_updates=True) - link = UpstreamLink.fetch_for_block(downstream) + link = UpstreamLink.get_for_block(downstream) assert link.version_synced == 2 assert link.version_declined is None assert link.version_available == 2 @@ -245,7 +245,7 @@ def test_prompt_and_decline_sync(self): upstream = xblock.load_block(self.upstream_key, self.user) upstream.data = "Upstream content V3" upstream.save() - link = UpstreamLink.fetch_for_block(downstream) + link = UpstreamLink.get_for_block(downstream) assert link.version_synced == 2 assert link.version_declined is None assert link.version_available == 3 @@ -253,7 +253,7 @@ def test_prompt_and_decline_sync(self): # Decline to sync to V3 -- ready_to_sync becomes False. decline_sync(downstream) - link = UpstreamLink.fetch_for_block(downstream) + link = UpstreamLink.get_for_block(downstream) assert link.version_synced == 2 assert link.version_declined == 3 assert link.version_available == 3 @@ -263,7 +263,7 @@ def test_prompt_and_decline_sync(self): upstream = xblock.load_block(self.upstream_key, self.user) upstream.data = "Upstream content V4" upstream.save() - link = UpstreamLink.fetch_for_block(downstream) + link = UpstreamLink.get_for_block(downstream) assert link.version_synced == 2 assert link.version_declined == 3 assert link.version_available == 4 diff --git a/cms/lib/xblock/upstream_sync.py b/cms/lib/xblock/upstream_sync.py index baf16529eb7b..8cf99fb3b225 100644 --- a/cms/lib/xblock/upstream_sync.py +++ b/cms/lib/xblock/upstream_sync.py @@ -75,12 +75,12 @@ def to_json(self) -> dict[str, t.Any]: } @classmethod - def try_fetch_for_block(cls, downstream: XBlock) -> t.Self | None: + def try_get_for_block(cls, downstream: XBlock) -> t.Self | None: """ - Same as `fetch_for_block`, but upon failure, sets `.error_message` instead of raising an exception. + Same as `get_for_block`, but upon failure, sets `.error_message` instead of raising an exception. """ try: - return cls.fetch_for_block(downstream) + return cls.get_for_block(downstream) except (BadDownstream, BadUpstream) as exc: return cls( upstream_ref=downstream.upstream, @@ -91,7 +91,7 @@ def try_fetch_for_block(cls, downstream: XBlock) -> t.Self | None: ) @classmethod - def fetch_for_block(cls, downstream: XBlock) -> t.Self | None: + def get_for_block(cls, downstream: XBlock) -> t.Self | None: """ Get info on a block's relationship with its linked upstream content (without actually loading the content). @@ -143,7 +143,7 @@ def fetch_for_block(cls, downstream: XBlock) -> t.Self | None: ) -def sync_from_upstream(downstream: XBlock, user: AbstractUser, *, apply_updates: bool) -> None: +def sync_from_upstream(downstream: XBlock, user: AbstractUser) -> None: """ Given an XBlock that is linked to upstream content, fetch latest upstream fields and optionally apply them. @@ -154,7 +154,7 @@ def sync_from_upstream(downstream: XBlock, user: AbstractUser, *, apply_updates: If `downstream` is not linked at all, does nothing. """ # Try to load the upstream. - upstream_link = UpstreamLink.fetch_for_block(downstream) # Can raise BadUpstream or BadUpstream + upstream_link = UpstreamLink.get_for_block(downstream) # Can raise BadUpstream or BadUpstream if not upstream_link: return # No upstream -> nothing to sync. try: @@ -218,7 +218,7 @@ def decline_sync(downstream: XBlock) -> None: If `downstream` is not linked at all, does nothing. """ # Try to load the upstream. - upstream_link = UpstreamLink.fetch_for_block(downstream) # Can raise BadUpstream or BadUpstream + upstream_link = UpstreamLink.get_for_block(downstream) # Can raise BadUpstream or BadUpstream if not upstream_link: return # No upstream -> nothing to sync. downstream.upstream_version_declined = upstream_link.version_available