Skip to content

Commit d85fd70

Browse files
committed
implement planet subscriptions request
1 parent 1e7a0b5 commit d85fd70

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

planet/cli/subscriptions.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from .options import limit, pretty
1010
from .session import CliSession
1111
from planet.clients.subscriptions import SubscriptionsClient
12+
from .. import subscription_request
1213

1314

1415
@asynccontextmanager
@@ -157,3 +158,38 @@ async def list_subscription_results_cmd(ctx,
157158
status=status,
158159
limit=limit):
159160
echo_json(result, pretty)
161+
162+
163+
@subscriptions.command()
164+
@click.option('--name',
165+
required=True,
166+
type=str,
167+
help='Subscription name. Does not need to be unique.')
168+
@click.option('--source',
169+
required=True,
170+
type=types.JSON(),
171+
help='Source JSON. Can be a string, filename or - for stdin.')
172+
@click.option('--delivery',
173+
required=True,
174+
type=types.JSON(),
175+
help='Delivery JSON. Can be a string, filename or - for stdin.')
176+
@click.option(
177+
'--notifications',
178+
type=types.JSON(),
179+
help='Notifications JSON. Can be a string, filename or - for stdin.')
180+
@click.option('--tools',
181+
type=types.JSON(),
182+
help='Toolchain JSON. Can be a string, filename or - for stdin.')
183+
@pretty
184+
def request(name, source, delivery, notifications, tools, pretty):
185+
"""Generate a subscriptions request."""
186+
res = subscription_request.build_request(name,
187+
source,
188+
delivery,
189+
notifications=notifications,
190+
tools=tools)
191+
echo_json(res, pretty)
192+
193+
194+
async def request_catalog():
195+
raise NotImplementedError

tests/integration/test_subscriptions_cli.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
TODO: tests for 3 options of the planet-subscriptions-results command.
1313
1414
"""
15-
1615
import json
1716

1817
from click.testing import CliRunner
@@ -250,3 +249,37 @@ def test_subscriptions_results_success(invoke, options, expected_count):
250249

251250
assert result.exit_code == 0 # success.
252251
assert result.output.count('"id"') == expected_count
252+
253+
254+
def test_request_base_success(invoke, geom_geojson):
255+
"""Request command succeeds"""
256+
source = json.dumps({
257+
"type": "catalog",
258+
"parameters": {
259+
"geometry": geom_geojson,
260+
"start_time": "2021-03-01T00:00:00Z",
261+
"end_time": "2023-11-01T00:00:00Z",
262+
"rrule": "FREQ=MONTHLY;BYMONTH=3,4,5,6,7,8,9,10",
263+
"item_types": ["PSScene"],
264+
"asset_types": ["ortho_analytic_4b"]
265+
}
266+
})
267+
delivery = json.dumps({
268+
"type": "amazon_s3",
269+
"parameters": {
270+
"aws_access_key_id": "keyid",
271+
"aws_secret_access_key": "accesskey",
272+
"bucket": "bucket",
273+
"aws_region": "region"
274+
}
275+
})
276+
277+
result = invoke([
278+
'request',
279+
'--name=test',
280+
f'--source={source}',
281+
f'--delivery={delivery}'
282+
])
283+
284+
assert source in result.output
285+
assert result.exit_code == 0 # success.

0 commit comments

Comments
 (0)