@@ -826,3 +826,69 @@ def test_author_view(self):
826826 assert '<li>html 2</li>' in rendered .content
827827 assert '<li>html 3</li>' in rendered .content
828828 assert '<li>html 4</li>' in rendered .content
829+
830+
831+ @ddt .ddt
832+ class TestLegacyLibraryContentBlockMigrationPublishing (LegacyLibraryContentTest ):
833+ """
834+ Unit tests for the `persist_publish_state` flag of
835+ LegacyLibraryContentBlock.v2_update_children_upstream_version.
836+ """
837+
838+ def setUp (self ):
839+ from cms .djangoapps .modulestore_migrator import api
840+ from cms .djangoapps .modulestore_migrator .data import CompositionLevel , RepeatHandlingStrategy
841+ super ().setUp ()
842+ user = UserFactory ()
843+ self ._sync_lc_block_from_library ()
844+ self .organization = OrganizationFactory (short_name = "myorg" )
845+ lib_api .create_library (
846+ org = self .organization ,
847+ slug = "mylib" ,
848+ title = "My Test V2 Library" ,
849+ )
850+ self .library_v2 = lib_api .ContentLibrary .objects .get (slug = "mylib" )
851+ api .start_migration_to_library (
852+ user = user ,
853+ source_key = self .library .location .library_key ,
854+ target_library_key = self .library_v2 .library_key ,
855+ target_collection_slug = None ,
856+ composition_level = CompositionLevel .Component ,
857+ repeat_handling_strategy = RepeatHandlingStrategy .Skip ,
858+ preserve_url_slugs = True ,
859+ forward_source_to_target = True ,
860+ )
861+
862+ @ddt .data (
863+ # Published before migration, flag True: re-published with the migration reflected.
864+ (True , True ),
865+ # Published before migration, flag False (default): published branch is left untouched.
866+ (True , False ),
867+ # Never published before migration, flag True: stays unpublished.
868+ (False , True ),
869+ )
870+ @ddt .unpack
871+ def test_persist_publish_state (self , was_published_before , persist_publish_state ):
872+ """
873+ Tests the `persist_publish_state` flag of `v2_update_children_upstream_version` under
874+ the various combinations of prior publish state and flag value.
875+ """
876+ if was_published_before :
877+ self .store .publish (self .course .location , self .user_id )
878+
879+ self .lc_block .v2_update_children_upstream_version (
880+ self .user_id , persist_publish_state = persist_publish_state ,
881+ )
882+
883+ if was_published_before and persist_publish_state :
884+ with self .store .branch_setting (ModuleStoreEnum .Branch .published_only ):
885+ published_block = self .store .get_item (self .lc_block .location )
886+ assert published_block .is_migrated_to_v2 is True
887+ assert published_block .get_children ()[0 ].upstream == "lb:myorg:mylib:html:html_1"
888+ elif was_published_before and not persist_publish_state :
889+ with self .store .branch_setting (ModuleStoreEnum .Branch .published_only ):
890+ published_block = self .store .get_item (self .lc_block .location )
891+ # The published version still reflects the pre-migration state.
892+ assert published_block .is_migrated_to_v2 is False
893+ else :
894+ assert not self .store .has_published_version (self .store .get_item (self .lc_block .location ))
0 commit comments