Skip to content

Commit d673f33

Browse files
committed
remove unwanted changes
1 parent 8301176 commit d673f33

File tree

4 files changed

+104
-61
lines changed

4 files changed

+104
-61
lines changed

synapseclient/models/protocols/wikipage_protocol.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,10 @@ class WikiHistorySnapshotSynchronousProtocol(Protocol):
112112
"""Protocol for the methods of the WikiHistorySnapshot class that have synchronous counterparts
113113
generated at runtime."""
114114

115-
@classmethod
116115
def get(
117116
cls,
118117
owner_id: str,
119-
wiki_id: str,
118+
id: str,
120119
*,
121120
offset: int = 0,
122121
limit: int = 20,
@@ -140,9 +139,9 @@ def get(
140139
```
141140
"""
142141
return wrap_async_generator_to_sync_generator(
143-
async_gen_func=WikiHistorySnapshot.get_async,
142+
async_gen_func=cls().get_async,
144143
owner_id=owner_id,
145-
id=wiki_id,
144+
id=id,
146145
offset=offset,
147146
limit=limit,
148147
synapse_client=synapse_client,
@@ -153,7 +152,6 @@ class WikiHeaderSynchronousProtocol(Protocol):
153152
"""Protocol for the methods of the WikiHeader class that have synchronous counterparts
154153
generated at runtime."""
155154

156-
@classmethod
157155
def get(
158156
cls,
159157
owner_id: str,
@@ -179,7 +177,7 @@ def get(
179177
```
180178
"""
181179
return wrap_async_generator_to_sync_generator(
182-
async_gen_func=WikiHeader.get_async,
180+
async_gen_func=cls().get_async,
183181
owner_id=owner_id,
184182
offset=offset,
185183
limit=limit,

synapseclient/models/wiki.py

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import os
66
import pprint
77
from dataclasses import dataclass, field
8-
from typing import Any, AsyncGenerator, Dict, List, Literal, Optional, Union
8+
from typing import Any, AsyncGenerator, Dict, Generator, List, Literal, Optional, Union
99

1010
from synapseclient import Synapse
1111
from synapseclient.api import (
@@ -23,7 +23,12 @@
2323
put_wiki_page,
2424
put_wiki_version,
2525
)
26-
from synapseclient.core.async_utils import async_to_sync, otel_trace_method
26+
from synapseclient.core.async_utils import (
27+
async_to_sync,
28+
otel_trace_method,
29+
skip_async_to_sync,
30+
wrap_async_generator_to_sync_generator,
31+
)
2732
from synapseclient.core.download import (
2833
PresignedUrlInfo,
2934
_pre_signed_url_expiration_time,
@@ -250,10 +255,8 @@ def fill_from_dict(
250255
self.modified_by = wiki_history.get("modifiedBy", None)
251256
return self
252257

258+
@skip_async_to_sync
253259
@classmethod
254-
@otel_trace_method(
255-
method_to_trace_name=lambda self, **kwargs: f"Get_Wiki_History for Owner ID {kwargs['owner_id']}, Wiki ID {kwargs['id']}"
256-
)
257260
async def get_async(
258261
cls,
259262
owner_id: str = None,
@@ -297,6 +300,25 @@ async def main():
297300
item = cls().fill_from_dict(wiki_history=item)
298301
yield item
299302

303+
@classmethod
304+
def get(
305+
cls,
306+
owner_id: str = None,
307+
id: str = None,
308+
*,
309+
offset: int = 0,
310+
limit: int = 20,
311+
synapse_client: Optional["Synapse"] = None,
312+
) -> Generator["WikiHistorySnapshot", None, None]:
313+
return wrap_async_generator_to_sync_generator(
314+
async_gen_func=cls().get_async,
315+
owner_id=owner_id,
316+
id=id,
317+
offset=offset,
318+
limit=limit,
319+
synapse_client=synapse_client,
320+
)
321+
300322

301323
@dataclass
302324
@async_to_sync
@@ -337,10 +359,8 @@ def fill_from_dict(
337359
self.parent_id = wiki_header.get("parentId", None)
338360
return self
339361

362+
@skip_async_to_sync
340363
@classmethod
341-
@otel_trace_method(
342-
method_to_trace_name=lambda self, **kwargs: f"Get_Wiki_Header_Tree for Owner ID {kwargs['owner_id']}"
343-
)
344364
async def get_async(
345365
cls,
346366
owner_id: str = None,
@@ -379,6 +399,39 @@ async def main():
379399
item = cls().fill_from_dict(wiki_header=item)
380400
yield item
381401

402+
@classmethod
403+
def get(
404+
cls,
405+
owner_id: str,
406+
*,
407+
offset: int = 0,
408+
limit: int = 20,
409+
synapse_client: Optional["Synapse"] = None,
410+
) -> Generator["WikiHeader", None, None]:
411+
"""
412+
Get the header tree (hierarchy) of wiki pages for an entity.
413+
Arguments:
414+
owner_id: The ID of the owner entity.
415+
offset: The index of the pagination offset.
416+
limit: Limits the size of the page returned.
417+
synapse_client: Optionally provide a Synapse client.
418+
Yields:
419+
Individual WikiHeader objects for the entity.
420+
421+
Example: Get the header tree (hierarchy) of wiki pages for an entity
422+
```python
423+
for header in WikiHeader.get(owner_id=project.id):
424+
print(f"Header: {header}")
425+
```
426+
"""
427+
return wrap_async_generator_to_sync_generator(
428+
async_gen_func=cls().get_async,
429+
owner_id=owner_id,
430+
offset=offset,
431+
limit=limit,
432+
synapse_client=synapse_client,
433+
)
434+
382435

383436
@dataclass
384437
@async_to_sync

tests/unit/synapseclient/models/async/unit_test_wiki_async.py

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -168,39 +168,35 @@ async def test_fill_from_dict(self) -> None:
168168
assert results == self.history_snapshot
169169

170170
async def test_get_async_success(self) -> None:
171-
# GIVEN mock responses
172-
mock_responses = [
173-
{
171+
async def mock_responses() -> AsyncGenerator[Dict[str, Any], None]:
172+
yield {
174173
"version": 1,
175174
"modifiedOn": "2023-01-01T00:00:00.000Z",
176175
"modifiedBy": "12345",
177-
},
178-
{
176+
}
177+
yield {
179178
"version": 2,
180179
"modifiedOn": "2023-01-02T00:00:00.000Z",
181180
"modifiedBy": "12345",
182-
},
183-
{
181+
}
182+
yield {
184183
"version": 3,
185184
"modifiedOn": "2023-01-03T00:00:00.000Z",
186185
"modifiedBy": "12345",
187-
},
188-
]
186+
}
189187

190188
# Create an async generator mock
191-
async def mock_async_generator(
192-
items: List[Dict[str, Any]]
193-
) -> AsyncGenerator[Dict[str, Any], None]:
194-
for item in items:
189+
async def mock_async_generator() -> AsyncGenerator[WikiHistorySnapshot, None]:
190+
async for item in mock_responses():
195191
yield item
196192

197193
# WHEN I call `get_async`
198194
with patch(
199195
"synapseclient.models.wiki.get_wiki_history",
200-
return_value=mock_async_generator(mock_responses),
196+
return_value=mock_async_generator(),
201197
) as mocked_get:
202198
results = []
203-
async for item in WikiHistorySnapshot.get_async(
199+
async for item in WikiHistorySnapshot().get_async(
204200
owner_id="syn123",
205201
id="wiki1",
206202
offset=0,
@@ -298,30 +294,27 @@ async def test_fill_from_dict(self) -> None:
298294

299295
async def test_get_async_success(self) -> None:
300296
# GIVEN mock responses
301-
mock_responses = [
302-
{
297+
async def mock_responses() -> AsyncGenerator[Dict[str, Any], None]:
298+
yield {
303299
"id": "wiki1",
304300
"title": "Test Wiki",
305301
"parentId": "1234",
306-
},
307-
{
302+
}
303+
yield {
308304
"id": "wiki2",
309305
"title": "Test Wiki 2",
310306
"parentId": "1234",
311-
},
312-
]
307+
}
313308

314309
# Create an async generator mock
315-
async def mock_async_generator(
316-
values: List[Dict[str, Any]]
317-
) -> AsyncGenerator[Dict[str, Any], None]:
318-
for item in values:
310+
async def mock_async_generator() -> AsyncGenerator[WikiHeader, None]:
311+
async for item in mock_responses():
319312
yield item
320313

321314
# WHEN I call `get_async`
322315
with patch(
323316
"synapseclient.models.wiki.get_wiki_header_tree",
324-
return_value=mock_async_generator(mock_responses),
317+
return_value=mock_async_generator(),
325318
) as mocked_get:
326319
results = []
327320
async for item in WikiHeader.get_async(

tests/unit/synapseclient/models/synchronous/unit_test_wiki.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -167,43 +167,42 @@ def test_fill_from_dict(self) -> None:
167167

168168
def test_get_success(self) -> None:
169169
# GIVEN mock responses
170-
mock_responses = [
171-
{
170+
async def mock_responses() -> AsyncGenerator[Dict[str, Any], None]:
171+
yield {
172172
"version": 1,
173173
"modifiedOn": "2023-01-01T00:00:00.000Z",
174174
"modifiedBy": "12345",
175-
},
176-
{
175+
}
176+
yield {
177177
"version": 2,
178178
"modifiedOn": "2023-01-02T00:00:00.000Z",
179179
"modifiedBy": "12345",
180-
},
181-
{
180+
}
181+
yield {
182182
"version": 3,
183183
"modifiedOn": "2023-01-03T00:00:00.000Z",
184184
"modifiedBy": "12345",
185-
},
186-
]
185+
}
187186

188187
# Create an async generator function
189-
async def mock_async_generator(*args, **kwargs):
190-
for item in mock_responses:
188+
async def mock_async_generator():
189+
async for item in mock_responses():
191190
yield item
192191

193192
# WHEN I call `get`
194193
with patch(
195194
"synapseclient.models.wiki.get_wiki_history",
196-
side_effect=mock_async_generator,
195+
return_value=mock_async_generator(),
197196
) as mocked_get:
198-
results = list(
199-
WikiHistorySnapshot.get(
200-
owner_id="syn123",
201-
id="wiki1",
202-
offset=0,
203-
limit=20,
204-
synapse_client=self.syn,
205-
)
206-
)
197+
results = []
198+
for item in WikiHistorySnapshot().get(
199+
owner_id="syn123",
200+
id="wiki1",
201+
offset=0,
202+
limit=20,
203+
synapse_client=self.syn,
204+
):
205+
results.append(item)
207206
# THEN the API should be called with correct parameters
208207
mocked_get.assert_called_once_with(
209208
owner_id="syn123",
@@ -318,7 +317,7 @@ async def mock_async_generator(*args, **kwargs):
318317

319318
with patch(
320319
"synapseclient.models.wiki.get_wiki_header_tree",
321-
side_effect=mock_async_generator,
320+
return_value=mock_async_generator(),
322321
) as mocked_get:
323322
results = list(
324323
WikiHeader.get(

0 commit comments

Comments
 (0)