11import unittest
22
3- from unittest .mock import patch
3+ from unittest .mock import patch , MagicMock
44from src .confluence import HeaderSize , ConfluenceGenerator , ConfluenceElements
5- from atlassian import Confluence
65from freezegun import freeze_time
76
87
@@ -22,11 +21,7 @@ def test_H4(self):
2221 def test_H5_fail (self ):
2322 self .assertRaises (AttributeError )
2423
25- def confluence_app (self , url : str , username : str , password : str ):
26- return None
27-
2824 @freeze_time ("2012-01-01" )
29- @patch .object (Confluence , '__init__' , confluence_app )
3025 def test_append_string (self ):
3126 confluence = ConfluenceGenerator ("url" , "api_username" , "api_password" , "page_id" , "page_title" )
3227 confluence .append_string ("test" )
@@ -44,9 +39,8 @@ def test_append_string(self):
4439
4540 def confluence_elements_render (title_text : str , title_size : int , table_headers : list , table_data : list ):
4641 return "TestRender"
47-
42+
4843 @freeze_time ("2012-01-01" )
49- @patch .object (Confluence , '__init__' , confluence_app )
5044 @patch .object (ConfluenceElements , 'render' , confluence_elements_render )
5145 def test_append_block (self ):
5246 confluence = ConfluenceGenerator ("url" , "api_username" , "api_password" , "page_id" , "page_title" )
@@ -68,18 +62,35 @@ def test_append_block(self):
6862 confluence ._ConfluenceGenerator__content
6963 )
7064
71- def confluence_update_page (self , page_id , title , body ):
72- return True
73-
7465 @freeze_time ("2012-01-01" )
75- @patch .object (Confluence , '__init__' , confluence_app )
76- @patch .object (Confluence , 'update_page' , confluence_update_page )
77- def test_update_page (self ):
66+ @patch ('src.confluence.confluence.requests.put' )
67+ @patch ('src.confluence.confluence.requests.get' )
68+ def test_update_page (self , mock_get , mock_put ):
69+ mock_get .return_value .json .return_value = {'version' : {'number' : 5 }}
70+ mock_put .return_value .raise_for_status = MagicMock ()
71+
7872 confluence = ConfluenceGenerator ("url" , "api_username" , "api_password" , "page_id" , "page_title" )
7973
8074 self .assertEqual (
8175 "<ac:structured-macro ac:name=\" toc\" ><ac:parameter ac:name=\" levels\" >2</ac:parameter></ac:structured-macro><p>Automatically generated at 01/01/2012 00:00:00</p>" ,
8276 confluence ._ConfluenceGenerator__content
8377 )
8478
85- self .assertTrue (confluence .update_page ())
79+ confluence .update_page ()
80+
81+ mock_get .assert_called_once_with ("url" , auth = ("api_username" , "api_password" ))
82+ mock_put .assert_called_once_with (
83+ "url" ,
84+ json = {
85+ "id" : "page_id" ,
86+ "status" : "current" ,
87+ "title" : "page_title" ,
88+ "body" : {
89+ "representation" : "storage" ,
90+ "value" : confluence ._ConfluenceGenerator__content ,
91+ },
92+ "version" : {"number" : 6 },
93+ },
94+ auth = ("api_username" , "api_password" ),
95+ )
96+ mock_put .return_value .raise_for_status .assert_called_once ()
0 commit comments