Repository: planetlabs/planet-client-python

Issue:
Update `search-create` CLI and python API commands to match `search`
**Expected behavior**
UI of `planet data search-create` and `planet data search` should be similar.

**Actual behavior (describe the problem)**
`planet data search` has filter and name as options, `planet data search-create` has name and filter as arguments.

**Proposed Solution**

Update `search-create` CLI and python API commands to match `search`.

Comments:

Patch:
diff --git a/CHANGES.txt b/CHANGES.txt
index 6ec63b9..4963823 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,3 +1,9 @@
+2.0.0-rc.3 (TBD)
+
+Changed:
+- Session class unit tests are marked to be run within an event loop and are
+  no longer skipped (#881).
+
 2.0.0-rc.2 (2023-03-15)
 
 Added:
diff --git a/planet/cli/data.py b/planet/cli/data.py
index cbca75e..46a9603 100644
--- a/planet/cli/data.py
+++ b/planet/cli/data.py
@@ -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',
@@ -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)
 
diff --git a/planet/clients/data.py b/planet/clients/data.py
index 82c22c2..2e80dd0 100644
--- a/planet/clients/data.py
+++ b/planet/clients/data.py
@@ -167,9 +167,9 @@ class DataClient:
             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.
 
@@ -190,9 +190,9 @@ class DataClient:
 
 
         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:
diff --git a/planet/subscription_request.py b/planet/subscription_request.py
index 26b761e..212bdc7 100644
--- a/planet/subscription_request.py
+++ b/planet/subscription_request.py
@@ -133,7 +133,7 @@ def catalog_source(
     parameters = {
         "item_types": item_types,
         "asset_types": asset_types,
-        "geometry": geometry,
+        "geometry": geojson.as_geom(geometry),
     }
 
     try:


Test patch:
diff --git a/tests/integration/test_data_api.py b/tests/integration/test_data_api.py
index 736d751..8a2c500 100644
--- a/tests/integration/test_data_api.py
+++ b/tests/integration/test_data_api.py
@@ -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 = {
@@ -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
diff --git a/tests/integration/test_data_cli.py b/tests/integration/test_data_cli.py
index 6150d25..47265bd 100644
--- a/tests/integration/test_data_cli.py
+++ b/tests/integration/test_data_cli.py
@@ -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
 
 
@@ -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
@@ -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'
     ])
 
diff --git a/tests/unit/test_session.py b/tests/unit/test_session.py
index 5520dfd..ed631bd 100644
--- a/tests/unit/test_session.py
+++ b/tests/unit/test_session.py
@@ -6,6 +6,7 @@ from planet import DataClient, OrdersClient, SubscriptionsClient, Session
 from planet.exceptions import ClientError
 
 
+@pytest.mark.asyncio
 @pytest.mark.parametrize("client_name,client_class",
                          [('data', DataClient), ('orders', OrdersClient),
                           ('subscriptions', SubscriptionsClient)])
@@ -16,6 +17,7 @@ async def test_session_get_client(client_name, client_class):
         assert isinstance(client, client_class)
 
 
+@pytest.mark.asyncio
 async def test_session_get_client_error():
     """Get an exception when no such client exists."""
     async with Session() as session:
diff --git a/tests/unit/test_subscription_request.py b/tests/unit/test_subscription_request.py
index 51e7590..7c0bca2 100644
--- a/tests/unit/test_subscription_request.py
+++ b/tests/unit/test_subscription_request.py
@@ -90,6 +90,30 @@ def test_catalog_source_success(geom_geojson):
     assert res == expected
 
 
+def test_catalog_source_featurecollection(featurecollection_geojson,
+                                          geom_geojson):
+    '''geojson specified as featurecollection is simplified down to just
+    the geometry'''
+    res = subscription_request.catalog_source(
+        item_types=["PSScene"],
+        asset_types=["ortho_analytic_4b"],
+        geometry=featurecollection_geojson,
+        start_time=datetime(2021, 3, 1),
+    )
+
+    expected = {
+        "type": "catalog",
+        "parameters": {
+            "geometry": geom_geojson,
+            "start_time": "2021-03-01T00:00:00Z",
+            "item_types": ["PSScene"],
+            "asset_types": ["ortho_analytic_4b"]
+        }
+    }
+
+    assert res == expected
+
+
 def test_catalog_source_invalid_start_time(geom_geojson):
     with pytest.raises(exceptions.ClientError):
         subscription_request.catalog_source(