@@ -879,12 +879,11 @@ def run_publish_channel(self):
879879 publish_channel (
880880 self .admin_user .id ,
881881 self .content_channel .id ,
882- version_notes = "" ,
883882 force = False ,
884883 force_exercises = False ,
885884 send_email = False ,
886885 progress_tracker = None ,
887- language = "fr" ,
886+ is_draft_version = True ,
888887 use_staging_tree = True ,
889888 )
890889
@@ -894,11 +893,9 @@ def test_none_staging_tree(self):
894893 with self .assertRaises (NoneContentNodeTreeError ):
895894 self .run_publish_channel ()
896895
897- def test_staging_tree_published (self ):
898- self .assertFalse (self .content_channel .staging_tree .published )
896+ def test_staging_tree_not_published_for_draft (self ):
899897 self .run_publish_channel ()
900- self .content_channel .refresh_from_db ()
901- self .assertTrue (self .content_channel .staging_tree .published )
898+ self .assertFalse (self .content_channel .staging_tree .published )
902899
903900 def test_next_version_exported (self ):
904901 self .run_publish_channel ()
@@ -928,6 +925,7 @@ def test_staging_tree_used_for_publish(self):
928925 self .admin_user .id ,
929926 True ,
930927 progress_tracker = None ,
928+ is_draft_version = True ,
931929 use_staging_tree = True ,
932930 )
933931 set_active_content_database (self .tempdb )
@@ -944,3 +942,106 @@ def test_staging_tree_used_for_publish(self):
944942 set_active_content_database (None )
945943 if os .path .exists (self .tempdb ):
946944 os .remove (self .tempdb )
945+
946+ class PublishDraftUsingMainTreeTestCase (StudioTestCase ):
947+ @classmethod
948+ def setUpClass (cls ):
949+ super (PublishDraftUsingMainTreeTestCase , cls ).setUpClass ()
950+ cls .patch_copy_db = patch ("contentcuration.utils.publish.save_export_database" )
951+ cls .mock_save_export = cls .patch_copy_db .start ()
952+
953+ @classmethod
954+ def tearDownClass (cls ):
955+ super (PublishDraftUsingMainTreeTestCase , cls ).tearDownClass ()
956+ cls .patch_copy_db .stop ()
957+
958+ def setUp (self ):
959+ super (PublishDraftUsingMainTreeTestCase , self ).setUp ()
960+
961+ self .channel_version = 3
962+ self .incomplete_video_in_main = "Incomplete video in main tree"
963+ self .complete_video_in_main = "Complete video in main tree"
964+
965+ self .content_channel = channel ()
966+ self .content_channel .version = self .channel_version
967+ self .content_channel .save ()
968+
969+ # Incomplete node in main_tree should be excluded.
970+ new_node = create_node (
971+ {"kind_id" : "video" , "title" : self .incomplete_video_in_main , "children" : []}
972+ )
973+ new_node .complete = False
974+ new_node .parent = self .content_channel .main_tree
975+ new_node .published = False
976+ new_node .save ()
977+
978+ # Complete node in main_tree should be included.
979+ new_node = create_node (
980+ {"kind_id" : "video" , "title" : self .complete_video_in_main , "children" : []}
981+ )
982+ new_node .complete = True
983+ new_node .parent = self .content_channel .main_tree
984+ new_node .published = False
985+ new_node .save ()
986+
987+ def run_publish_channel (self ):
988+ publish_channel (
989+ self .admin_user .id ,
990+ self .content_channel .id ,
991+ force = False ,
992+ force_exercises = False ,
993+ send_email = False ,
994+ progress_tracker = None ,
995+ is_draft_version = True ,
996+ use_staging_tree = False ,
997+ )
998+
999+ def test_next_version_exported (self ):
1000+ self .run_publish_channel ()
1001+ self .mock_save_export .assert_called_with (
1002+ self .content_channel .id ,
1003+ "next" ,
1004+ True ,
1005+ )
1006+
1007+ def test_main_tree_not_impacted (self ):
1008+ self .assertFalse (self .content_channel .main_tree .published )
1009+ self .run_publish_channel ()
1010+ self .content_channel .refresh_from_db ()
1011+ self .assertFalse (self .content_channel .main_tree .published )
1012+
1013+ def test_channel_version_not_incremented (self ):
1014+ self .assertEqual (self .content_channel .version , self .channel_version )
1015+ self .run_publish_channel ()
1016+ self .content_channel .refresh_from_db ()
1017+ self .assertEqual (self .content_channel .version , self .channel_version )
1018+
1019+ def test_main_tree_used_for_publish (self ):
1020+ set_channel_icon_encoding (self .content_channel )
1021+ self .tempdb = create_content_database (
1022+ self .content_channel ,
1023+ True ,
1024+ self .admin_user .id ,
1025+ True ,
1026+ progress_tracker = None ,
1027+ is_draft_version = True ,
1028+ use_staging_tree = False ,
1029+ )
1030+ set_active_content_database (self .tempdb )
1031+
1032+ nodes = kolibri_models .ContentNode .objects .all ()
1033+ self .assertEqual (nodes .filter (title = self .incomplete_video_in_main ).count (), 0 )
1034+ self .assertEqual (nodes .filter (title = self .complete_video_in_main ).count (), 1 )
1035+
1036+ cleanup_content_database_connection (self .tempdb )
1037+ set_active_content_database (None )
1038+ if os .path .exists (self .tempdb ):
1039+ os .remove (self .tempdb )
1040+
1041+ def test_only_next_file_created (self ):
1042+ self .mock_save_export .reset_mock ()
1043+ self .run_publish_channel ()
1044+ self .assertEqual (self .mock_save_export .call_count , 1 )
1045+ call_args = self .mock_save_export .call_args
1046+ self .assertEqual (call_args [0 ][1 ], "next" )
1047+ self .assertEqual (call_args [0 ][2 ], True )
0 commit comments