Skip to content

Commit 4b90e9d

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 481983a commit 4b90e9d

16 files changed

Lines changed: 43 additions & 43 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
@@ -186,7 +186,7 @@ def _migration(m: models.ModulestoreMigration) -> ModulestoreMigration:
186186
source_key=m.source.key,
187187
target_key=LibraryLocatorV2.from_string(m.target.key),
188188
target_title=m.target.title,
189-
target_collection_slug=(m.target_collection.key if m.target_collection else None),
189+
target_collection_slug=(m.target_collection.collection_code if m.target_collection else None),
190190
target_collection_title=(m.target_collection.title if m.target_collection else None),
191191
is_failed=m.is_failed,
192192
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
@@ -226,7 +226,7 @@ def test_start_migration_to_library_with_collection(self):
226226
collection_key = "test-collection"
227227
content_api.create_collection(
228228
learning_package_id=self.learning_package.id,
229-
key=collection_key,
229+
collection_code=collection_key,
230230
title="Test Collection",
231231
created_by=user.id,
232232
)
@@ -243,7 +243,7 @@ def test_start_migration_to_library_with_collection(self):
243243
)
244244

245245
modulestoremigration = ModulestoreMigration.objects.get()
246-
assert modulestoremigration.target_collection.key == collection_key
246+
assert modulestoremigration.target_collection.collection_code == collection_key
247247

248248
def test_start_migration_to_library_with_strategy_skip(self):
249249
"""
@@ -481,19 +481,19 @@ def test_migration_api_for_various_scenarios(self):
481481
# Lib 2 has Collection C
482482
content_api.create_collection(
483483
learning_package_id=self.learning_package.id,
484-
key="test-collection-1a",
484+
collection_code="test-collection-1a",
485485
title="Test Collection A in Lib 1",
486486
created_by=user.id,
487487
)
488488
content_api.create_collection(
489489
learning_package_id=self.learning_package.id,
490-
key="test-collection-1b",
490+
collection_code="test-collection-1b",
491491
title="Test Collection B in Lib 1",
492492
created_by=user.id,
493493
)
494494
content_api.create_collection(
495495
learning_package_id=self.learning_package_2.id,
496-
key="test-collection-2c",
496+
collection_code="test-collection-2c",
497497
title="Test Collection C in Lib 2",
498498
created_by=user.id,
499499
)

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

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

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

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
@@ -193,7 +193,7 @@ def setUp(self) -> None:
193193
with freeze_time(self.created_date):
194194
self.collection = content_api.create_collection(
195195
learning_package_id=self.learning_package.id,
196-
key="MYCOL",
196+
collection_code="MYCOL",
197197
title="my_collection",
198198
created_by=None,
199199
description="my collection description"
@@ -203,7 +203,7 @@ def setUp(self) -> None:
203203
)
204204
self.collection_dict = {
205205
"id": "lib-collectionorg1libmycol-5b647617",
206-
"block_id": self.collection.key,
206+
"block_id": self.collection.collection_code,
207207
"usage_key": str(self.collection_key),
208208
"type": "collection",
209209
"display_name": "my_collection",
@@ -706,7 +706,7 @@ def test_index_library_block_and_collections(self, mock_meilisearch) -> None:
706706
for collection in (collection2, collection1):
707707
library_api.update_library_collection_items(
708708
self.library.key,
709-
collection_key=collection.key,
709+
collection_key=collection.collection_code,
710710
opaque_keys=[
711711
self.problem1.usage_key,
712712
],
@@ -888,7 +888,7 @@ def test_delete_collection(self, mock_meilisearch) -> None:
888888
with freeze_time(updated_date):
889889
library_api.update_library_collection_items(
890890
self.library.key,
891-
collection_key=self.collection.key,
891+
collection_key=self.collection.collection_code,
892892
opaque_keys=[
893893
self.problem1.usage_key,
894894
self.unit.container_key
@@ -902,14 +902,14 @@ def test_delete_collection(self, mock_meilisearch) -> None:
902902
"id": self.doc_problem1["id"],
903903
"collections": {
904904
"display_name": [self.collection.title],
905-
"key": [self.collection.key],
905+
"key": [self.collection.collection_code],
906906
},
907907
}
908908
doc_unit_with_collection = {
909909
"id": self.unit_dict["id"],
910910
"collections": {
911911
"display_name": [self.collection.title],
912-
"key": [self.collection.key],
912+
"key": [self.collection.collection_code],
913913
},
914914
}
915915

@@ -928,7 +928,7 @@ def test_delete_collection(self, mock_meilisearch) -> None:
928928
# Soft-delete the collection
929929
content_api.delete_collection(
930930
self.collection.learning_package_id,
931-
self.collection.key,
931+
self.collection.collection_code,
932932
)
933933

934934
doc_problem_without_collection = {
@@ -963,7 +963,7 @@ def test_delete_collection(self, mock_meilisearch) -> None:
963963
with freeze_time(restored_date):
964964
content_api.restore_collection(
965965
self.collection.learning_package_id,
966-
self.collection.key,
966+
self.collection.collection_code,
967967
)
968968

969969
doc_collection = copy.deepcopy(self.collection_dict)
@@ -985,7 +985,7 @@ def test_delete_collection(self, mock_meilisearch) -> None:
985985
# Hard-delete the collection
986986
content_api.delete_collection(
987987
self.collection.learning_package_id,
988-
self.collection.key,
988+
self.collection.collection_code,
989989
hard_delete=True,
990990
)
991991

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

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

487487
assert doc == {
488488
"id": "lib-collectionedx2012_falltoy_collection-d1d907a4",
489-
"block_id": self.collection.key,
489+
"block_id": self.collection.collection_code,
490490
"usage_key": str(self.collection_key),
491491
"type": "collection",
492492
"org": "edX",
@@ -515,7 +515,7 @@ def test_collection_with_published_library(self):
515515

516516
assert doc == {
517517
"id": "lib-collectionedx2012_falltoy_collection-d1d907a4",
518-
"block_id": self.collection.key,
518+
"block_id": self.collection.collection_code,
519519
"usage_key": str(self.collection_key),
520520
"type": "collection",
521521
"org": "edX",

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
)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def create_library_collection(
5454
try:
5555
collection = content_api.create_collection(
5656
learning_package_id=content_library.learning_package_id,
57-
key=collection_key,
57+
collection_code=collection_key,
5858
title=title,
5959
description=description,
6060
created_by=created_by,
@@ -86,7 +86,7 @@ def update_library_collection(
8686
try:
8787
collection = content_api.update_collection(
8888
learning_package_id=content_library.learning_package_id,
89-
key=collection_key,
89+
collection_code=collection_key,
9090
title=title,
9191
description=description,
9292
)
@@ -232,7 +232,7 @@ def set_library_item_collections(
232232
library_collection=LibraryCollectionData(
233233
collection_key=library_collection_locator(
234234
library_key=library_key,
235-
collection_key=collection.key,
235+
collection_key=collection.collection_code,
236236
),
237237
background=True,
238238
)

0 commit comments

Comments
 (0)