Skip to content

move planet data stats interval and filter args to required options #894

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 24, 2023
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
20 changes: 14 additions & 6 deletions planet/cli/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,19 +418,27 @@ async def search_run(ctx, search_id, sort, limit, pretty):
@click.argument("item_types",
type=types.CommaSeparatedString(),
callback=check_item_types)
@click.argument('interval', type=click.Choice(STATS_INTERVAL))
@click.argument("filter", type=types.JSON())
async def stats(ctx, item_types, interval, filter):
@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('--interval',
type=click.Choice(STATS_INTERVAL),
required=True,
help='The size of the histogram date buckets.')
async def stats(ctx, item_types, filter, interval):
"""Get a bucketed histogram of items matching the filter.

This function returns a bucketed histogram of results based on the
item_types, interval, and json filter specified (using file or stdin).
item_types, interval, and filter specified.

"""
async with data_client(ctx) as cl:
items = await cl.get_stats(item_types=item_types,
interval=interval,
search_filter=filter)
search_filter=filter,
interval=interval)
echo_json(items)


Expand Down
24 changes: 15 additions & 9 deletions tests/integration/test_data_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,16 +771,18 @@ def test_data_stats_invalid_filter(invoke, filter):
interval = "hour"
item_type = 'PSScene'
runner = CliRunner()
result = invoke(["stats", item_type, interval, filter], runner=runner)
result = invoke(
["stats", item_type, f'--interval={interval}', f'--filter={filter}'],
runner=runner)
assert result.exit_code == 2


@respx.mock
@pytest.mark.parametrize("item_types",
['PSScene', 'SkySatScene', 'PSScene, SkySatScene'])
@pytest.mark.parametrize("interval, exit_code", [(None, 1), ('hou', 2),
@pytest.mark.parametrize("interval, exit_code", [(None, 2), ('hou', 2),
('hour', 0)])
def test_data_stats_invalid_interval(invoke, item_types, interval, exit_code):
def test_data_stats_interval(invoke, item_types, interval, exit_code):
"""Test for planet data stats. Test with multiple item_types.
Test should succeed with valid interval, and fail with invalid interval."""
filter = {
Expand All @@ -797,10 +799,11 @@ def test_data_stats_invalid_interval(invoke, item_types, interval, exit_code):
}]})
respx.post(TEST_STATS_URL).return_value = mock_resp

runner = CliRunner()
result = invoke(["stats", item_types, interval, json.dumps(filter)],
runner=runner)
args = ["stats", item_types, f'--filter={json.dumps(filter)}']
if interval:
args.append(f'--interval={interval}')
Comment on lines +802 to +804
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for adding the keywords 👍


result = invoke(args)
assert result.exit_code == exit_code


Expand Down Expand Up @@ -828,9 +831,12 @@ def test_data_stats_success(invoke, item_types, interval):
}]})
respx.post(TEST_STATS_URL).return_value = mock_resp

runner = CliRunner()
result = invoke(["stats", item_types, interval, json.dumps(filter)],
runner=runner)
result = invoke([
"stats",
item_types,
f'--interval={interval}',
f'--filter={json.dumps(filter)}'
])
assert result.exit_code == 0


Expand Down