Skip to content

Commit 8e38604

Browse files
committed
fix: updating tests and fixing code
1 parent 50c6a27 commit 8e38604

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

  • openedx_learning/apps/authoring/collections
  • tests/openedx_learning/apps/authoring/collections

openedx_learning/apps/authoring/collections/api.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,15 +234,12 @@ def set_collections(
234234
removed_collections = set(
235235
r.collection for r in current_relations.exclude(collection__in=collection_qset)
236236
)
237-
removed_collections = set(
238-
r.collection for r in current_relations.exclude(collection__in=collection_qset)
239-
)
240237
new_collections = set(collection_qset.exclude(
241238
id__in=current_relations.values_list('collection', flat=True)
242239
))
243240
# Triggers a m2m_changed signal
244241
publishable_entity.collections.set(
245-
objs=new_collections,
242+
objs=collection_qset,
246243
through_defaults={"created_by_id": created_by},
247244
)
248245
# Update modified date via update to avoid triggering post_save signal for all collections, which can be very slow.

tests/openedx_learning/apps/authoring/collections/test_api.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,6 @@ def test_set_collections(self):
637637
modified_time = datetime(2024, 8, 8, tzinfo=timezone.utc)
638638
with freeze_time(modified_time):
639639
api.set_collections(
640-
self.learning_package.id,
641640
self.draft_component.publishable_entity,
642641
collection_qset=Collection.objects.filter(id__in=[
643642
self.collection1.pk,
@@ -675,7 +674,6 @@ def test_set_collections(self):
675674
new_modified_time = datetime(2024, 8, 8, tzinfo=timezone.utc)
676675
with freeze_time(new_modified_time):
677676
api.set_collections(
678-
self.learning_package.id,
679677
self.draft_component.publishable_entity,
680678
collection_qset=Collection.objects.filter(id__in=[
681679
self.collection3.pk,
@@ -708,13 +706,20 @@ def test_set_collection_wrong_learning_package(self):
708706
key="ComponentTestCase-test-key-3",
709707
title="Components Test Case Learning Package-3",
710708
)
709+
collection = api.create_collection(
710+
learning_package_3.id,
711+
key="MYCOL",
712+
title="My Collection",
713+
created_by=None,
714+
description="Description of Collection",
715+
)
716+
711717

712718
with self.assertRaises(ValidationError):
713719
api.set_collections(
714-
learning_package_3.id,
715720
self.draft_component.publishable_entity,
716721
collection_qset=Collection.objects.filter(id__in=[
717-
self.collection1.pk,
722+
collection.pk,
718723
]),
719724
created_by=self.user.id,
720725
)

0 commit comments

Comments
 (0)