Skip to content

Commit 9168232

Browse files
fix: address review comments
1 parent 31ae324 commit 9168232

2 files changed

Lines changed: 20 additions & 10 deletions

File tree

  • src/openedx_content/applets/publishing
  • tests/openedx_content/applets/publishing

src/openedx_content/applets/publishing/api.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,9 @@ def publish_from_drafts(
475475
of the Drafts that are passed in.
476476
"""
477477
if DraftChangeLogContext.get_active_draft_change_log(learning_package_id) is not None:
478-
raise ValidationError("Cannot publish while in bulk_draft_changes_for().")
478+
raise ValidationError(
479+
f"Cannot publish learning package {learning_package_id} while in bulk_draft_changes_for()."
480+
)
479481
if published_at is None:
480482
published_at = datetime.now(tz=timezone.utc)
481483

tests/openedx_content/applets/publishing/test_api.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2545,6 +2545,7 @@ def test_publish_functions_rejected_inside_bulk_draft_changes_for(self) -> None:
25452545
ordering of DraftChangeLog vs. PublishLog records and can leave Drafts
25462546
and Published rows out of sync if the outer context later raises.
25472547
"""
2548+
lp1_id = self.learning_package_1.id
25482549
entity = publishing_api.create_publishable_entity(
25492550
self.learning_package_1.id,
25502551
"entity_for_bulk_publish_check",
@@ -2559,13 +2560,20 @@ def test_publish_functions_rejected_inside_bulk_draft_changes_for(self) -> None:
25592560
created_by=None,
25602561
)
25612562

2562-
with pytest.raises(ValidationError, match="Cannot publish while in bulk_draft_changes_for()."):
2563-
with publishing_api.bulk_draft_changes_for(self.learning_package_1.id):
2564-
publishing_api.publish_all_drafts(self.learning_package_1.id)
2563+
with pytest.raises(
2564+
ValidationError,
2565+
match=f"Cannot publish learning package {lp1_id} while in bulk_draft_changes_for()."
2566+
):
2567+
with publishing_api.bulk_draft_changes_for(lp1_id):
2568+
publishing_api.publish_all_drafts(lp1_id)
25652569

2566-
with pytest.raises(ValidationError, match="Cannot publish while in bulk_draft_changes_for()."):
2567-
with publishing_api.bulk_draft_changes_for(self.learning_package_1.id):
2568-
publishing_api.publish_from_drafts(
2569-
self.learning_package_1.id,
2570-
Draft.objects.filter(entity__learning_package_id=self.learning_package_1.id),
2571-
)
2570+
with pytest.raises(
2571+
ValidationError,
2572+
match=f"Cannot publish learning package {lp1_id} while in bulk_draft_changes_for()."
2573+
):
2574+
with publishing_api.bulk_draft_changes_for(lp1_id):
2575+
publishing_api.publish_from_drafts(lp1_id, Draft.objects.filter(entity__learning_package_id=lp1_id))
2576+
2577+
# But we CAN publish if the bulk_draft_changes_for is a different learning package:
2578+
with publishing_api.bulk_draft_changes_for(self.learning_package_2.id):
2579+
publishing_api.publish_all_drafts(lp1_id)

0 commit comments

Comments
 (0)