1
+ from http import HTTPStatus
1
2
import tempfile
2
3
import json
3
4
import pytest
6
7
from click .testing import CliRunner
7
8
8
9
from 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
10
11
11
12
12
13
def invoke (* args ):
@@ -17,7 +18,11 @@ def invoke(*args):
17
18
18
19
result = runner .invoke (cli .main , args = args )
19
20
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
21
26
22
27
23
28
@respx .mock
@@ -122,3 +127,57 @@ def assertf(resp):
122
127
req_body = json .loads (respx .calls [0 ].request .content )
123
128
assert req_body ["type" ] == "Feature"
124
129
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