Skip to content

Commit 3fe5d50

Browse files
committed
remove _aiter from generator function names and update usage in tests
1 parent d4c8b26 commit 3fe5d50

File tree

9 files changed

+113
-112
lines changed

9 files changed

+113
-112
lines changed

planet/cli/data.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,12 @@ async def search(ctx, item_types, filter, limit, name, sort, pretty):
272272
parameter will be applied to the stored quick search.
273273
"""
274274
async with data_client(ctx) as cl:
275-
items_aiter = cl.search_aiter(item_types,
276-
filter,
277-
name=name,
278-
sort=sort,
279-
limit=limit)
280-
async for item in items_aiter:
275+
276+
async for item in cl.search(item_types,
277+
filter,
278+
name=name,
279+
sort=sort,
280+
limit=limit):
281281
echo_json(item, pretty)
282282

283283

planet/cli/orders.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ async def list(ctx, state, limit, pretty):
6767
optionally pretty-printed.
6868
'''
6969
async with orders_client(ctx) as cl:
70-
orders_aiter = cl.list_orders_aiter(state=state, limit=limit)
71-
async for o in orders_aiter:
70+
async for o in cl.list_orders(state=state, limit=limit):
7271
echo_json(o, pretty)
7372

7473

planet/cli/subscriptions.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ async def list_subscriptions_cmd(ctx, status, limit, pretty):
4242
"""Prints a sequence of JSON-encoded Subscription descriptions."""
4343
async with CliSession(auth=ctx.obj['AUTH']) as session:
4444
client = SubscriptionsClient(session)
45-
subs_aiter = client.list_subscriptions_aiter(status=status,
46-
limit=limit)
47-
async for sub in subs_aiter:
45+
async for sub in client.list_subscriptions(status=status, limit=limit):
4846
echo_json(sub, pretty)
4947

5048

@@ -158,8 +156,7 @@ async def list_subscription_results_cmd(ctx,
158156
"""Gets results of a subscription and prints the API response."""
159157
async with CliSession(auth=ctx.obj['AUTH']) as session:
160158
client = SubscriptionsClient(session)
161-
results_aiter = client.get_results_aiter(subscription_id,
162-
status=status,
163-
limit=limit)
164-
async for result in results_aiter:
159+
async for result in client.get_results(subscription_id,
160+
status=status,
161+
limit=limit):
165162
echo_json(result, pretty)

planet/clients/data.py

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,23 @@ def _searches_url(self):
9393
def _item_url(self, item_type, item_id):
9494
return f'{self._base_url}/item-types/{item_type}/items/{item_id}'
9595

96-
async def search_aiter(self,
97-
item_types: List[str],
98-
search_filter: dict,
99-
name: Optional[str] = None,
100-
sort: Optional[str] = None,
101-
limit: int = 100) -> AsyncIterator[dict]:
96+
async def search(self,
97+
item_types: List[str],
98+
search_filter: dict,
99+
name: Optional[str] = None,
100+
sort: Optional[str] = None,
101+
limit: int = 100) -> AsyncIterator[dict]:
102102
"""Iterate over results from a quick search.
103103
104104
Quick searches are saved for a short period of time (~month). The
105105
`name` parameter of the search defaults to the id of the generated
106106
search id if `name` is not specified.
107107
108+
Note:
109+
The name of this method is based on the API's method name. This
110+
method provides iteration over results, it does not get a
111+
single result description or return a list of descriptions.
112+
108113
Parameters:
109114
item_types: The item types to include in the search.
110115
search_filter: Structured search criteria.
@@ -224,16 +229,16 @@ async def update_search(self,
224229
json=request)
225230
return response.json()
226231

227-
async def list_searches_aiter(self,
228-
sort: str = 'created desc',
229-
search_type: str = 'any',
230-
limit: int = 100) -> AsyncIterator[dict]:
232+
async def list_searches(self,
233+
sort: str = 'created desc',
234+
search_type: str = 'any',
235+
limit: int = 100) -> AsyncIterator[dict]:
231236
"""Iterate through list of searches available to the user.
232237
233-
NOTE: the term 'saved' is overloaded here. We want to list saved
234-
searches that are 'quick' or list saved searches that are 'saved'? Do
235-
we want to introduce a new term, 'stored' that encompasses 'saved' and
236-
'quick' searches?
238+
Note:
239+
The name of this method is based on the API's method name. This
240+
method provides iteration over results, it does not get a
241+
single result description or return a list of descriptions.
237242
238243
Parameters:
239244
sort: Field and direction to order results by.
@@ -295,11 +300,16 @@ async def get_search(self, search_id: str) -> dict:
295300
response = await self._session.request(method='GET', url=url)
296301
return response.json()
297302

298-
async def run_search_aiter(self,
299-
search_id: str,
300-
limit: int = 100) -> AsyncIterator[dict]:
303+
async def run_search(self,
304+
search_id: str,
305+
limit: int = 100) -> AsyncIterator[dict]:
301306
"""Iterate over results from a saved search.
302307
308+
Note:
309+
The name of this method is based on the API's method name. This
310+
method provides iteration over results, it does not get a
311+
single result description or return a list of descriptions.
312+
303313
Parameters:
304314
search_id: Stored search identifier.
305315
limit: Maximum number of results to return. When set to 0, no

planet/clients/orders.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -463,18 +463,23 @@ async def wait(self,
463463

464464
return current_state
465465

466-
async def list_orders_aiter(self,
467-
state: Optional[str] = None,
468-
limit: int = 100) -> AsyncIterator[dict]:
466+
async def list_orders(self,
467+
state: Optional[str] = None,
468+
limit: int = 100) -> AsyncIterator[dict]:
469469
"""Iterate over the list of stored order requests.
470470
471+
Note:
472+
The name of this method is based on the API's method name. This
473+
method provides iteration over results, it does not get a
474+
single result description or return a list of descriptions.
475+
471476
Parameters:
472477
state: Filter orders to given state.
473478
limit: Maximum number of results to return. When set to 0, no
474479
maximum is applied.
475480
476-
Returns:
477-
Iterator over user orders that match the query
481+
Yields:
482+
Description of an order.
478483
479484
Raises:
480485
planet.exceptions.APIError: On API error.

planet/clients/subscriptions.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ class SubscriptionsClient:
3131
def __init__(self, session: Session) -> None:
3232
self._session = session
3333

34-
async def list_subscriptions_aiter(
35-
self,
36-
status: Optional[Set[str]] = None,
37-
limit: int = 100) -> AsyncIterator[dict]:
34+
async def list_subscriptions(self,
35+
status: Optional[Set[str]] = None,
36+
limit: int = 100) -> AsyncIterator[dict]:
3837
"""Iterate over list of account subscriptions with optional filtering.
3938
4039
Note:
@@ -193,10 +192,10 @@ async def get_subscription(self, subscription_id: str) -> dict:
193192
sub = resp.json()
194193
return sub
195194

196-
async def get_results_aiter(self,
197-
subscription_id: str,
198-
status: Optional[Set[str]] = None,
199-
limit: int = 100) -> AsyncIterator[dict]:
195+
async def get_results(self,
196+
subscription_id: str,
197+
status: Optional[Set[str]] = None,
198+
limit: int = 100) -> AsyncIterator[dict]:
200199
"""Iterate over results of a Subscription.
201200
202201
Note:

tests/integration/test_data_api.py

Lines changed: 35 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ def search_response(item_descriptions):
6767

6868
@respx.mock
6969
@pytest.mark.asyncio
70-
async def test_search_aiter_basic(item_descriptions,
71-
search_filter,
72-
search_response,
73-
session):
70+
async def test_search_basic(item_descriptions,
71+
search_filter,
72+
search_response,
73+
session):
7474

7575
quick_search_url = f'{TEST_URL}/quick-search'
7676
next_page_url = f'{TEST_URL}/blob/?page_marker=IAmATest'
@@ -89,10 +89,10 @@ async def test_search_aiter_basic(item_descriptions,
8989
respx.get(next_page_url).return_value = mock_resp2
9090

9191
cl = DataClient(session, base_url=TEST_URL)
92-
item_aiter = cl.search_aiter(['PSScene'],
93-
search_filter,
94-
name='quick_search')
95-
items_list = [i async for i in item_aiter]
92+
items_list = [
93+
i async for i in cl.search(
94+
['PSScene'], search_filter, name='quick_search')
95+
]
9696

9797
# check that request is correct
9898
expected_request = {
@@ -109,10 +109,10 @@ async def test_search_aiter_basic(item_descriptions,
109109

110110
@respx.mock
111111
@pytest.mark.asyncio
112-
async def test_search_aiter_sort(item_descriptions,
113-
search_filter,
114-
search_response,
115-
session):
112+
async def test_search_sort(item_descriptions,
113+
search_filter,
114+
search_response,
115+
session):
116116

117117
sort = 'acquired asc'
118118
quick_search_url = f'{TEST_URL}/quick-search?_sort={sort}'
@@ -125,18 +125,17 @@ async def test_search_aiter_sort(item_descriptions,
125125
# if the sort parameter is not used correctly, the client will not send
126126
# the request to the mocked endpoint and this test will fail
127127
cl = DataClient(session, base_url=TEST_URL)
128-
item_aiter = cl.search_aiter(['PSScene'], search_filter, sort=sort)
129128

130129
# run through the iterator to actually initiate the call
131-
[i async for i in item_aiter]
130+
[i async for i in cl.search(['PSScene'], search_filter, sort=sort)]
132131

133132

134133
@respx.mock
135134
@pytest.mark.asyncio
136-
async def test_search_aiter_limit(item_descriptions,
137-
search_filter,
138-
search_response,
139-
session):
135+
async def test_search_limit(item_descriptions,
136+
search_filter,
137+
search_response,
138+
session):
140139

141140
quick_search_url = f'{TEST_URL}/quick-search'
142141

@@ -148,8 +147,9 @@ async def test_search_aiter_limit(item_descriptions,
148147
respx.post(quick_search_url).return_value = mock_resp
149148

150149
cl = DataClient(session, base_url=TEST_URL)
151-
item_aiter = cl.search_aiter(['PSScene'], search_filter, limit=2)
152-
items_list = [i async for i in item_aiter]
150+
items_list = [
151+
i async for i in cl.search(['PSScene'], search_filter, limit=2)
152+
]
153153

154154
# check only the first two results were returned
155155
assert items_list == item_descriptions[:2]
@@ -297,19 +297,18 @@ async def test_update_search_basic(search_filter, session):
297297
@respx.mock
298298
@pytest.mark.asyncio
299299
@pytest.mark.parametrize("limit, expected_list_length", [(None, 4), (3, 3)])
300-
async def test_list_searches_aiter_success(limit,
301-
expected_list_length,
302-
search_result,
303-
session):
300+
async def test_list_searches_success(limit,
301+
expected_list_length,
302+
search_result,
303+
session):
304304
page1_response = {"_links": {}, "searches": [search_result] * 4}
305305
route = respx.get(TEST_SEARCHES_URL)
306306
route.return_value = httpx.Response(200, json=page1_response)
307307

308308
cl = DataClient(session, base_url=TEST_URL)
309309

310-
search_aiter = cl.list_searches_aiter(limit=limit)
311-
searches_list_length = len([s async for s in search_aiter])
312-
assert searches_list_length == expected_list_length
310+
assert len([s async for s in cl.list_searches(limit=limit)
311+
]) == expected_list_length
313312

314313
assert route.called
315314

@@ -320,19 +319,17 @@ async def test_list_searches_aiter_success(limit,
320319
"sort, search_type, expectation",
321320
[('DOESNOTEXIST', 'ANY', pytest.raises(exceptions.ClientError)),
322321
('CREATED DESC', 'DOESNOTEXIST', pytest.raises(exceptions.ClientError))])
323-
async def test_list_searches_aiter_args_do_not_match(sort,
324-
search_type,
325-
expectation,
326-
session):
322+
async def test_list_searches_args_do_not_match(sort,
323+
search_type,
324+
expectation,
325+
session):
327326
route = respx.get(TEST_SEARCHES_URL)
328327
route.return_value = httpx.Response(200, json={})
329328

330329
cl = DataClient(session, base_url=TEST_URL)
331330

332331
with expectation:
333-
searches_aiter = cl.list_searches_aiter(sort=sort,
334-
search_type=search_type)
335-
[s async for s in searches_aiter]
332+
[s async for s in cl.list_searches(sort=sort, search_type=search_type)]
336333

337334
assert not route.called
338335

@@ -357,7 +354,7 @@ async def test_delete_search(retcode, expectation, session):
357354

358355
@respx.mock
359356
@pytest.mark.asyncio
360-
async def test_run_search_aiter_success(item_descriptions, session):
357+
async def test_run_search_success(item_descriptions, session):
361358
sid = 'search_id'
362359
route = respx.get(f'{TEST_SEARCHES_URL}/{sid}/results')
363360

@@ -376,8 +373,7 @@ async def test_run_search_aiter_success(item_descriptions, session):
376373
respx.get(next_page_url).return_value = mock_resp2
377374

378375
cl = DataClient(session, base_url=TEST_URL)
379-
item_aiter = cl.run_search_aiter(sid)
380-
items_list = [i async for i in item_aiter]
376+
items_list = [i async for i in cl.run_search(sid)]
381377

382378
assert route.called
383379

@@ -387,17 +383,14 @@ async def test_run_search_aiter_success(item_descriptions, session):
387383

388384
@respx.mock
389385
@pytest.mark.asyncio
390-
async def test_run_search_aiter_doesnotexist(session):
386+
async def test_run_search_doesnotexist(session):
391387
sid = 'search_id'
392388
route = respx.get(f'{TEST_SEARCHES_URL}/{sid}/results')
393389
route.return_value = httpx.Response(404)
394390

395391
cl = DataClient(session, base_url=TEST_URL)
396392
with pytest.raises(exceptions.APIError):
397-
item_aiter = cl.run_search_aiter(sid)
398-
# this won't throw the error until the iterator is processed
399-
# issue 476
400-
[i async for i in item_aiter]
393+
[i async for i in cl.run_search(sid)]
401394

402395
assert route.called
403396

0 commit comments

Comments
 (0)