@@ -353,6 +353,51 @@ def test_update_or_create_requires_space_for_a_top_level_page(self, confluence_s
353353 with pytest .raises (ApiValueError , match = "space is required" ):
354354 confluence_server .update_or_create (title = "Top level" , body = "<p>Body</p>" )
355355
356+ @patch .object (ConfluenceServer , "create_page" )
357+ @patch .object (ConfluenceServer , "page_exists" )
358+ @patch .object (ConfluenceServer , "get_descendant_page_id" , return_value = "" )
359+ def test_update_or_create_creates_when_same_title_is_under_another_parent (
360+ self , mock_descendant_id , mock_page_exists , mock_create_page , confluence_server
361+ ):
362+ mock_create_page .return_value = {"id" : "new" , "_links" : {"tinyui" : "/x/new" }}
363+
364+ confluence_server .update_or_create ("parent-a" , "Report" , "<p>Body</p>" , space = "TEAM" )
365+
366+ mock_descendant_id .assert_called_once_with ("TEAM" , "parent-a" , "Report" )
367+ mock_page_exists .assert_not_called ()
368+ mock_create_page .assert_called_once_with (
369+ space = "TEAM" ,
370+ parent_id = "parent-a" ,
371+ title = "Report" ,
372+ body = "<p>Body</p>" ,
373+ representation = "storage" ,
374+ editor = None ,
375+ full_width = False ,
376+ )
377+
378+ @patch .object (ConfluenceServer , "update_page" )
379+ @patch .object (ConfluenceServer , "page_exists" )
380+ @patch .object (ConfluenceServer , "get_descendant_page_id" , return_value = "child-a" )
381+ def test_update_or_create_updates_only_the_matching_child (
382+ self , mock_descendant_id , mock_page_exists , mock_update_page , confluence_server
383+ ):
384+ mock_update_page .return_value = {"id" : "child-a" , "_links" : {"tinyui" : "/x/child" }}
385+
386+ confluence_server .update_or_create ("parent-a" , "Report" , "<p>Body</p>" , space = "TEAM" )
387+
388+ mock_descendant_id .assert_called_once_with ("TEAM" , "parent-a" , "Report" )
389+ mock_page_exists .assert_not_called ()
390+ mock_update_page .assert_called_once_with (
391+ parent_id = "parent-a" ,
392+ page_id = "child-a" ,
393+ title = "Report" ,
394+ body = "<p>Body</p>" ,
395+ representation = "storage" ,
396+ minor_edit = False ,
397+ version_comment = None ,
398+ full_width = False ,
399+ )
400+
356401 @patch .object (ConfluenceServer , "update_page" )
357402 def test_update_existing_page_preserves_confluence_image_storage_markup (self , mock_update_page , confluence_server ):
358403 body = '<table><tr><td><ac:image><ri:attachment ri:filename="chart.png" /></ac:image></td></tr></table>'
0 commit comments