Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions planet/cli/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ def filter(ctx,
callback=check_item_types)
@click.option('--filter',
type=types.JSON(),
help='Apply specified filter to search.')
help="""Apply specified filter to search. Can be a json string,
filename, or '-' for stdin.""")
@limit
@click.option('--name', type=str, help='Name of the saved search.')
@click.option('--sort',
Expand Down Expand Up @@ -321,32 +322,35 @@ async def search(ctx, item_types, filter, limit, name, sort, pretty):
@click.pass_context
@translate_exceptions
@coro
@click.argument('name')
@click.argument("item_types",
type=types.CommaSeparatedString(),
callback=check_item_types)
@click.argument("filter", type=types.JSON())
@click.option(
'--filter',
type=types.JSON(),
required=True,
help="""Filter to apply to search. Can be a json string, filename,
or '-' for stdin.""")
@click.option('--name',
type=str,
required=True,
help='Name of the saved search.')
@click.option('--daily-email',
is_flag=True,
help='Send a daily email when new results are added.')
@pretty
async def search_create(ctx, name, item_types, filter, daily_email, pretty):
async def search_create(ctx, item_types, filter, name, daily_email, pretty):
"""Create a new saved structured item search.

This function outputs a full JSON description of the created search,
optionally pretty-printed.

NAME is the name to give the search.

ITEM_TYPES is a comma-separated list of item-types to search.

FILTER must be JSON and can be specified a json string, filename, or '-'
for stdin.
"""
async with data_client(ctx) as cl:
items = await cl.create_search(name=name,
item_types=item_types,
items = await cl.create_search(item_types=item_types,
search_filter=filter,
name=name,
enable_email=daily_email)
echo_json(items, pretty)

Expand Down
4 changes: 2 additions & 2 deletions planet/clients/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ async def search(self,
yield i

async def create_search(self,
name: str,
item_types: List[str],
search_filter: dict,
name: str,
enable_email: bool = False) -> dict:
"""Create a new saved structured item search.

Expand All @@ -190,9 +190,9 @@ async def create_search(self,


Parameters:
name: The name of the saved search.
item_types: The item types to include in the search.
search_filter: Structured search criteria.
name: The name of the saved search.
enable_email: Send a daily email when new results are added.

Returns:
Expand Down
9 changes: 6 additions & 3 deletions tests/integration/test_data_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,9 @@ async def test_create_search_basic(search_filter, session):
respx.post(TEST_SEARCHES_URL).return_value = mock_resp

cl = DataClient(session, base_url=TEST_URL)
search = await cl.create_search('test', ['PSScene'], search_filter)
search = await cl.create_search(['PSScene'],
search_filter=search_filter,
name='test')

# check that request is correct
expected_request = {
Expand Down Expand Up @@ -281,8 +283,9 @@ async def test_create_search_email(search_filter, session):
respx.post(TEST_SEARCHES_URL).return_value = mock_resp

cl = DataClient(session, base_url=TEST_URL)
search = await cl.create_search('test', ['PSScene'],
search_filter,
search = await cl.create_search(['PSScene'],
search_filter=search_filter,
name='test',
enable_email=True)

# check that request is correct
Expand Down
19 changes: 15 additions & 4 deletions tests/integration/test_data_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,13 @@ def test_data_search_create_filter_invalid_json(invoke, item_types, filter):
name = "temp"

runner = CliRunner()
result = invoke(["search-create", name, item_types, filter], runner=runner)
result = invoke([
"search-create",
item_types,
f'--name={name}',
f'--filter={json.dumps(filter)}'
],
runner=runner)
assert result.exit_code == 2


Expand All @@ -599,7 +605,12 @@ def test_data_search_create_filter_success(invoke, item_types):
respx.post(TEST_SEARCHES_URL).return_value = mock_resp

runner = CliRunner()
result = invoke(["search-create", name, item_types, json.dumps(filter)],
result = invoke([
"search-create",
item_types,
f'--filter={json.dumps(filter)}',
f'--name={name}'
],
runner=runner)

assert result.exit_code == 0
Expand All @@ -621,9 +632,9 @@ def test_data_search_create_daily_email(invoke, search_result):

result = invoke([
'search-create',
'temp',
'SkySatScene',
json.dumps(filter),
'--name=temp',
f'--filter={json.dumps(filter)}',
'--daily-email'
])

Expand Down