1+ from http import HTTPStatus
12import tempfile
23import json
34import pytest
67from click .testing import CliRunner
78
89from planet .cli import cli
9- from tests .integration .test_features_api import TEST_COLLECTION_1 , TEST_COLLECTION_LIST , TEST_FEAT , TEST_GEOM , TEST_URL , list_collections_response , list_features_response , mock_response , to_collection_model
10+ from tests .integration .test_features_api import TEST_COLLECTION_1 , TEST_COLLECTION_LIST , TEST_FEAT , TEST_GEOM , TEST_URL , list_collections_response , list_features_response , mock_response , to_collection_model , to_feature_model
1011
1112
1213def invoke (* args ):
@@ -17,7 +18,11 @@ def invoke(*args):
1718
1819 result = runner .invoke (cli .main , args = args )
1920 assert result .exit_code == 0 , result .output
20- return json .loads (result .output )
21+ if len (result .output ) > 0 :
22+ return json .loads (result .output )
23+
24+ # some commands (delete) return no value.
25+ return None
2126
2227
2328@respx .mock
@@ -122,3 +127,57 @@ def assertf(resp):
122127 req_body = json .loads (respx .calls [0 ].request .content )
123128 assert req_body ["type" ] == "Feature"
124129 assert req_body ["geometry" ] == expected_body
130+
131+
132+ @respx .mock
133+ def test_get_item ():
134+ collection_id = "test"
135+ item_id = "test123"
136+ get_item_url = f'{ TEST_URL } /collections/{ collection_id } /items/{ item_id } '
137+
138+ mock_response (get_item_url ,
139+ json = to_feature_model ("test123" ),
140+ method = "get" ,
141+ status_code = HTTPStatus .OK )
142+
143+ def assertf (resp ):
144+ assert resp ["id" ] == "test123"
145+
146+ assertf (invoke ("items" , "get" , collection_id , item_id ))
147+ assertf (invoke ("items" , "get" ,
148+ f"pl:features/my/{ collection_id } /{ item_id } " ))
149+
150+
151+ @respx .mock
152+ def test_delete_item ():
153+ collection_id = "test"
154+ item_id = "test123"
155+ delete_item_url = f'{ TEST_URL } /collections/{ collection_id } /items/{ item_id } '
156+
157+ mock_response (delete_item_url ,
158+ json = None ,
159+ method = "delete" ,
160+ status_code = HTTPStatus .NO_CONTENT )
161+
162+ def assertf (resp ):
163+ assert resp is None
164+
165+ assertf (invoke ("items" , "delete" , collection_id , item_id ))
166+ assertf (
167+ invoke ("items" , "delete" , f"pl:features/my/{ collection_id } /{ item_id } " ))
168+
169+
170+ @respx .mock
171+ def test_delete_collection ():
172+ collection_id = "test"
173+ collection_url = f'{ TEST_URL } /collections/{ collection_id } '
174+
175+ mock_response (collection_url ,
176+ json = None ,
177+ method = "delete" ,
178+ status_code = HTTPStatus .NO_CONTENT )
179+
180+ def assertf (resp ):
181+ assert resp is None
182+
183+ assertf (invoke ("collections" , "delete" , collection_id ))
0 commit comments