Skip to content

Commit 8d4e218

Browse files
committed
refactor: Collection.collection_id -> Collection.collection_code
Handles a breaking change from the upgrade of openedx-core. Note: LibraryCollectionLocator.collection_id has not been updated yet; that will happen in a future opaque-keys change. Part of: openedx/openedx-core#322
1 parent 7a8aec9 commit 8d4e218

19 files changed

Lines changed: 58 additions & 47 deletions

File tree

cms/djangoapps/contentstore/rest_api/v1/views/tests/test_home.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def setUp(self):
274274
collection_key = "test-collection"
275275
content_api.create_collection(
276276
learning_package_id=learning_package.id,
277-
key=collection_key,
277+
collection_code=collection_key,
278278
title="Test Collection",
279279
created_by=self.user.id,
280280
)

cms/djangoapps/modulestore_migrator/api/read_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def _migration(m: models.ModulestoreMigration) -> ModulestoreMigration:
180180
source_key=m.source.key,
181181
target_key=LibraryLocatorV2.from_string(m.target.key),
182182
target_title=m.target.title,
183-
target_collection_slug=(m.target_collection.key if m.target_collection else None),
183+
target_collection_slug=(m.target_collection.collection_code if m.target_collection else None),
184184
target_collection_title=(m.target_collection.title if m.target_collection else None),
185185
is_failed=m.is_failed,
186186
task_uuid=m.task_status.uuid,

cms/djangoapps/modulestore_migrator/tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ def _populate_collection(user_id: int, migration: models.ModulestoreMigration) -
409409
if block_target_pks:
410410
content_api.add_to_collection(
411411
learning_package_id=migration.target.pk,
412-
key=migration.target_collection.key,
412+
collection_code=migration.target_collection.collection_code,
413413
entities_qset=PublishableEntity.objects.filter(id__in=block_target_pks),
414414
created_by=user_id,
415415
)

cms/djangoapps/modulestore_migrator/tests/test_api.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def test_start_migration_to_library_with_collection(self):
232232
collection_key = "test-collection"
233233
content_api.create_collection(
234234
learning_package_id=self.learning_package.id,
235-
key=collection_key,
235+
collection_code=collection_key,
236236
title="Test Collection",
237237
created_by=user.id,
238238
)
@@ -249,7 +249,7 @@ def test_start_migration_to_library_with_collection(self):
249249
)
250250

251251
modulestoremigration = ModulestoreMigration.objects.get()
252-
assert modulestoremigration.target_collection.key == collection_key
252+
assert modulestoremigration.target_collection.collection_code == collection_key
253253

254254
def test_start_migration_to_library_with_strategy_skip(self):
255255
"""
@@ -487,19 +487,19 @@ def test_migration_api_for_various_scenarios(self):
487487
# Lib 2 has Collection C
488488
content_api.create_collection(
489489
learning_package_id=self.learning_package.id,
490-
key="test-collection-1a",
490+
collection_code="test-collection-1a",
491491
title="Test Collection A in Lib 1",
492492
created_by=user.id,
493493
)
494494
content_api.create_collection(
495495
learning_package_id=self.learning_package.id,
496-
key="test-collection-1b",
496+
collection_code="test-collection-1b",
497497
title="Test Collection B in Lib 1",
498498
created_by=user.id,
499499
)
500500
content_api.create_collection(
501501
learning_package_id=self.learning_package_2.id,
502-
key="test-collection-2c",
502+
collection_code="test-collection-2c",
503503
title="Test Collection C in Lib 2",
504504
created_by=user.id,
505505
)

openedx/core/djangoapps/content/search/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ def index_collection_batch(batch, num_done, library_key) -> int:
503503
docs = []
504504
for collection in batch:
505505
try:
506-
collection_key = lib_api.library_collection_locator(library_key, collection.key)
506+
collection_key = lib_api.library_collection_locator(library_key, collection.collection_code)
507507
doc = searchable_doc_for_collection(collection_key, collection=collection)
508508
doc.update(searchable_doc_tags(collection_key))
509509
docs.append(doc)
@@ -898,7 +898,7 @@ def upsert_content_library_index_docs(library_key: LibraryLocatorV2, full_index:
898898
docs.append(doc)
899899

900900
for collection in lib_api.get_library_collections(library_key):
901-
collection_key = lib_api.library_collection_locator(library_key, collection.key)
901+
collection_key = lib_api.library_collection_locator(library_key, collection.collection_code)
902902
doc = searchable_doc_for_collection(collection_key, collection=collection)
903903
docs.append(doc)
904904

openedx/core/djangoapps/content/search/documents.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ def searchable_doc_for_collection(
543543
pass
544544

545545
if collection:
546-
assert collection.key == collection_key.collection_id
546+
assert collection.collection_code == collection_key.collection_id
547547

548548
draft_num_children = content_api.filter_publishable_entities(
549549
collection.entities,
@@ -558,7 +558,7 @@ def searchable_doc_for_collection(
558558
Fields.context_key: str(collection_key.context_key),
559559
Fields.org: str(collection_key.org),
560560
Fields.usage_key: str(collection_key),
561-
Fields.block_id: collection.key,
561+
Fields.block_id: collection.collection_code,
562562
Fields.type: DocType.collection,
563563
Fields.display_name: collection.title,
564564
Fields.description: collection.description,

openedx/core/djangoapps/content/search/tests/test_api.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def setUp(self) -> None:
194194
with freeze_time(self.created_date):
195195
self.collection = content_api.create_collection(
196196
learning_package_id=self.learning_package.id,
197-
key="MYCOL",
197+
collection_code="MYCOL",
198198
title="my_collection",
199199
created_by=None,
200200
description="my collection description"
@@ -204,7 +204,7 @@ def setUp(self) -> None:
204204
)
205205
self.collection_dict = {
206206
"id": "lib-collectionorg1libmycol-5b647617",
207-
"block_id": self.collection.key,
207+
"block_id": self.collection.collection_code,
208208
"usage_key": str(self.collection_key),
209209
"type": "collection",
210210
"display_name": "my_collection",
@@ -711,7 +711,7 @@ def test_index_library_block_and_collections(self, mock_meilisearch) -> None:
711711
for collection in (collection2, collection1):
712712
library_api.update_library_collection_items(
713713
self.library.key,
714-
collection_key=collection.key,
714+
collection_key=collection.collection_code,
715715
opaque_keys=[
716716
self.problem1.usage_key,
717717
],
@@ -893,7 +893,7 @@ def test_delete_collection(self, mock_meilisearch) -> None:
893893
with freeze_time(updated_date):
894894
library_api.update_library_collection_items(
895895
self.library.key,
896-
collection_key=self.collection.key,
896+
collection_key=self.collection.collection_code,
897897
opaque_keys=[
898898
self.problem1.usage_key,
899899
self.unit.container_key
@@ -907,14 +907,14 @@ def test_delete_collection(self, mock_meilisearch) -> None:
907907
"id": self.doc_problem1["id"],
908908
"collections": {
909909
"display_name": [self.collection.title],
910-
"key": [self.collection.key],
910+
"key": [self.collection.collection_code],
911911
},
912912
}
913913
doc_unit_with_collection = {
914914
"id": self.unit_dict["id"],
915915
"collections": {
916916
"display_name": [self.collection.title],
917-
"key": [self.collection.key],
917+
"key": [self.collection.collection_code],
918918
},
919919
}
920920

@@ -933,7 +933,7 @@ def test_delete_collection(self, mock_meilisearch) -> None:
933933
# Soft-delete the collection
934934
content_api.delete_collection(
935935
self.collection.learning_package_id,
936-
self.collection.key,
936+
self.collection.collection_code,
937937
)
938938

939939
doc_problem_without_collection = {
@@ -968,7 +968,7 @@ def test_delete_collection(self, mock_meilisearch) -> None:
968968
with freeze_time(restored_date):
969969
content_api.restore_collection(
970970
self.collection.learning_package_id,
971-
self.collection.key,
971+
self.collection.collection_code,
972972
)
973973

974974
doc_collection = copy.deepcopy(self.collection_dict)
@@ -990,7 +990,7 @@ def test_delete_collection(self, mock_meilisearch) -> None:
990990
# Hard-delete the collection
991991
content_api.delete_collection(
992992
self.collection.learning_package_id,
993-
self.collection.key,
993+
self.collection.collection_code,
994994
hard_delete=True,
995995
)
996996

openedx/core/djangoapps/content/search/tests/test_documents.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ def test_collection_with_library(self):
492492

493493
assert doc == {
494494
"id": "lib-collectionedx2012_falltoy_collection-d1d907a4",
495-
"block_id": self.collection.key,
495+
"block_id": self.collection.collection_code,
496496
"usage_key": str(self.collection_key),
497497
"type": "collection",
498498
"org": "edX",
@@ -521,7 +521,7 @@ def test_collection_with_published_library(self):
521521

522522
assert doc == {
523523
"id": "lib-collectionedx2012_falltoy_collection-d1d907a4",
524-
"block_id": self.collection.key,
524+
"block_id": self.collection.collection_code,
525525
"usage_key": str(self.collection_key),
526526
"type": "collection",
527527
"org": "edX",

openedx/core/djangoapps/content_libraries/api/block_metadata.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22
Content libraries data classes related to XBlocks/Components.
33
"""
44
from __future__ import annotations
5+
6+
import typing as t
57
from dataclasses import dataclass
68

79
from django.utils.translation import gettext as _
810
from opaque_keys.edx.locator import LibraryUsageLocatorV2
11+
from openedx_content.models_api import Component
12+
913
from .libraries import (
1014
library_component_usage_key,
1115
PublishableItem,
16+
CollectionMetadata,
1217
)
1318

1419
# The public API is only the following symbols:
@@ -26,7 +31,9 @@ class LibraryXBlockMetadata(PublishableItem):
2631
usage_key: LibraryUsageLocatorV2
2732

2833
@classmethod
29-
def from_component(cls, library_key, component, associated_collections=None):
34+
def from_component(
35+
cls, library_key, component: Component, associated_collections: list[CollectionMetadata] | None = None
36+
) -> t.Self:
3037
"""
3138
Construct a LibraryXBlockMetadata from a Component object.
3239
"""

openedx/core/djangoapps/content_libraries/api/blocks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ def delete_library_block(
729729
library_collection=LibraryCollectionData(
730730
collection_key=library_collection_locator(
731731
library_key=library_key,
732-
collection_key=collection.key,
732+
collection_key=collection.collection_code,
733733
),
734734
background=True,
735735
)
@@ -795,7 +795,7 @@ def restore_library_block(usage_key: LibraryUsageLocatorV2, user_id: int | None
795795
library_collection=LibraryCollectionData(
796796
collection_key=library_collection_locator(
797797
library_key=library_key,
798-
collection_key=collection.key,
798+
collection_key=collection.collection_code,
799799
),
800800
background=True,
801801
)

0 commit comments

Comments
 (0)