@@ -199,13 +199,15 @@ async def mock_async_generator(
199199 "synapseclient.models.wiki.get_wiki_history" ,
200200 return_value = mock_async_generator (mock_responses ),
201201 ) as mocked_get :
202- results = await WikiHistorySnapshot .get_async (
202+ results = []
203+ async for item in WikiHistorySnapshot .get_async (
203204 owner_id = "syn123" ,
204205 id = "wiki1" ,
205206 offset = 0 ,
206207 limit = 20 ,
207208 synapse_client = self .syn ,
208- )
209+ ):
210+ results .append (item )
209211 # THEN the API should be called with correct parameters
210212 mocked_get .assert_called_once_with (
211213 owner_id = "syn123" ,
@@ -242,11 +244,12 @@ async def test_get_async_missing_owner_id(self) -> None:
242244 ) as mocked_get , pytest .raises (
243245 ValueError , match = "Must provide owner_id to get wiki history."
244246 ):
245- await WikiHistorySnapshot .get_async (
247+ async for _ in WikiHistorySnapshot .get_async (
246248 owner_id = None ,
247249 id = "wiki1" ,
248250 synapse_client = self .syn ,
249- )
251+ ):
252+ pass
250253 # THEN the API should not be called
251254 mocked_get .assert_not_called ()
252255
@@ -257,11 +260,12 @@ async def test_get_async_missing_id(self) -> None:
257260 ) as mocked_get , pytest .raises (
258261 ValueError , match = "Must provide id to get wiki history."
259262 ):
260- await WikiHistorySnapshot .get_async (
263+ async for _ in WikiHistorySnapshot .get_async (
261264 owner_id = "syn123" ,
262265 id = None ,
263266 synapse_client = self .syn ,
264- )
267+ ):
268+ pass
265269 # THEN the API should not be called
266270 mocked_get .assert_not_called ()
267271
@@ -319,13 +323,14 @@ async def mock_async_generator(
319323 "synapseclient.models.wiki.get_wiki_header_tree" ,
320324 return_value = mock_async_generator (mock_responses ),
321325 ) as mocked_get :
322- results = await WikiHeader .get_async (
326+ results = []
327+ async for item in WikiHeader .get_async (
323328 owner_id = "syn123" ,
324329 synapse_client = self .syn ,
325330 offset = 0 ,
326331 limit = 20 ,
327- )
328-
332+ ):
333+ results . append ( item )
329334 # THEN the API should be called with correct parameters
330335 mocked_get .assert_called_once_with (
331336 owner_id = "syn123" ,
@@ -349,7 +354,8 @@ async def test_get_async_missing_owner_id(self) -> None:
349354 ) as mocked_get , pytest .raises (
350355 ValueError , match = "Must provide owner_id to get wiki header tree."
351356 ):
352- await WikiHeader .get_async (owner_id = None , synapse_client = self .syn )
357+ async for _ in WikiHeader .get_async (owner_id = None , synapse_client = self .syn ):
358+ pass
353359 # THEN the API should not be called
354360 mocked_get .assert_not_called ()
355361
@@ -603,6 +609,28 @@ def test_reformat_attachment_file_name(self, file_name: str, expected: str) -> N
603609 # THEN the result should be the reformatted file name
604610 assert result == expected
605611
612+ @pytest .mark .parametrize (
613+ "file_name,expected" ,
614+ [
615+ ("test.png" , False ),
616+ ("test.jpg" , False ),
617+ ("test.jpeg" , False ),
618+ ("test.txt.gz" , False ),
619+ ("test.txt" , True ),
620+ ],
621+ )
622+ def test_should_gzip_file (self , file_name : str , expected : bool ) -> None :
623+ # WHEN I call `_should_gzip_file` with a file name
624+ result = WikiPage ._should_gzip_file (file_name )
625+ # THEN the result should match the expected value
626+ assert result == expected
627+
628+ def test_should_gzip_file_with_invalid_content (self ) -> None :
629+ # WHEN I call `_should_gzip_file` with invalid content (non-string)
630+ # THEN it should raise an AttributeError
631+ with pytest .raises (AttributeError ):
632+ WikiPage ._should_gzip_file (123 )
633+
606634 async def test_get_markdown_file_handle_success_with_markdown (self ) -> WikiPage :
607635 with patch (
608636 "synapseclient.models.wiki.WikiPage._to_gzip_file" ,
@@ -931,9 +959,12 @@ async def test_determine_wiki_action_create_root(self) -> None:
931959 )
932960
933961 async def test_determine_wiki_action_create_sub (self ) -> None :
962+ async def mock_get_async (* args , ** kwargs ) -> AsyncGenerator [WikiHeader , None ]:
963+ yield WikiHeader (id = "wiki1" , title = "Test Wiki Page" )
964+
934965 with patch (
935966 "synapseclient.models.wiki.WikiHeader.get_async" ,
936- side_effect = SynapseHTTPError ( response = Mock ( status_code = 404 )) ,
967+ side_effect = mock_get_async ,
937968 ) as mock_get_header :
938969 # GIVEN a WikiPage with a parent_id
939970 wiki_page = WikiPage (
@@ -950,9 +981,12 @@ async def test_determine_wiki_action_create_sub(self) -> None:
950981 mock_get_header .assert_not_called ()
951982
952983 async def test_determine_wiki_action_update_existing_root (self ) -> None :
984+ async def mock_get_async (* args , ** kwargs ) -> AsyncGenerator [WikiHeader , None ]:
985+ yield WikiHeader (id = "wiki1" , title = "Test Wiki Page" )
986+
953987 with patch (
954988 "synapseclient.models.wiki.WikiHeader.get_async" ,
955- return_value = WikiHeader ( id = "wiki1" , title = "Test Wiki Page" ) ,
989+ side_effect = mock_get_async ,
956990 ) as mock_get_header :
957991 # GIVEN a WikiPage with an id
958992 wiki_page = WikiPage (
@@ -974,9 +1008,12 @@ async def test_determine_wiki_action_update_existing_root(self) -> None:
9741008 async def test_determine_wiki_action_update_existing_without_passing_id (
9751009 self ,
9761010 ) -> None :
1011+ async def mock_get_async (* args , ** kwargs ) -> AsyncGenerator [WikiHeader , None ]:
1012+ yield WikiHeader (id = "wiki1" , title = "Test Wiki Page" )
1013+
9771014 with patch (
9781015 "synapseclient.models.wiki.WikiHeader.get_async" ,
979- return_value = WikiHeader ( id = "wiki1" , title = "Test Wiki Page" ) ,
1016+ side_effect = mock_get_async ,
9801017 ) as mock_get_header :
9811018 # GIVEN a WikiPage with an id and parent_id
9821019 wiki_page = WikiPage (
0 commit comments