8
8
from stac_fastapi .extensions .core import TransactionExtension
9
9
from stac_fastapi .types .config import ApiSettings
10
10
from stac_fastapi .types .core import BaseCoreClient , BaseTransactionsClient
11
- from stac_fastapi .types .stac import Item , ItemCollection
11
+ from stac_fastapi .types .stac import Collection , Item , ItemCollection
12
12
13
13
14
14
class DummyCoreClient (BaseCoreClient ):
@@ -32,25 +32,32 @@ def item_collection(self, *args, **kwargs):
32
32
33
33
34
34
class DummyTransactionsClient (BaseTransactionsClient ):
35
- """Defines a pattern for implementing the STAC transaction extension ."""
35
+ """Dummy client returning parts of the request, rather than proper STAC items ."""
36
36
37
- def create_item (self , item : Union [Item , ItemCollection ], * args , * *kwargs ):
38
- return {"created" : True , " type" : item ["type" ]}
37
+ def create_item (self , item : Union [Item , ItemCollection ], ** kwargs ):
38
+ return {"type" : item ["type" ]}
39
39
40
- def update_item (self , * args , ** kwargs ):
41
- raise NotImplementedError
40
+ def update_item (self , collection_id : str , item_id : str , item : Item , ** kwargs ):
41
+ return {
42
+ "path_collection_id" : collection_id ,
43
+ "path_item_id" : item_id ,
44
+ "type" : item ["type" ],
45
+ }
42
46
43
- def delete_item (self , * args , ** kwargs ):
44
- raise NotImplementedError
47
+ def delete_item (self , item_id : str , collection_id : str , ** kwargs ):
48
+ return {
49
+ "path_collection_id" : collection_id ,
50
+ "path_item_id" : item_id ,
51
+ }
45
52
46
- def create_collection (self , * args , ** kwargs ):
47
- raise NotImplementedError
53
+ def create_collection (self , collection : Collection , ** kwargs ):
54
+ return { "type" : collection [ "type" ]}
48
55
49
- def update_collection (self , * args , ** kwargs ):
50
- raise NotImplementedError
56
+ def update_collection (self , collection_id : str , collection : Collection , ** kwargs ):
57
+ return { "path_collection_id" : collection_id , "type" : collection [ "type" ]}
51
58
52
- def delete_collection (self , * args , ** kwargs ):
53
- raise NotImplementedError
59
+ def delete_collection (self , collection_id : str , ** kwargs ):
60
+ return { "path_collection_id" : collection_id }
54
61
55
62
56
63
def test_create_item (client : TestClient , item : Item ) -> None :
@@ -69,6 +76,42 @@ def test_create_item_collection(
69
76
assert response .json ()["type" ] == "FeatureCollection"
70
77
71
78
79
+ def test_update_item (client : TestClient , item : Item ) -> None :
80
+ response = client .put (
81
+ "/collections/a-collection/items/an-item" , content = json .dumps (item )
82
+ )
83
+ assert response .is_success , response .text
84
+ assert response .json ()["path_collection_id" ] == "a-collection"
85
+ assert response .json ()["path_item_id" ] == "an-item"
86
+ assert response .json ()["type" ] == "Feature"
87
+
88
+
89
+ def test_delete_item (client : TestClient ) -> None :
90
+ response = client .delete ("/collections/a-collection/items/an-item" )
91
+ assert response .is_success , response .text
92
+ assert response .json ()["path_collection_id" ] == "a-collection"
93
+ assert response .json ()["path_item_id" ] == "an-item"
94
+
95
+
96
+ def test_create_collection (client : TestClient , collection : Collection ) -> None :
97
+ response = client .post ("/collections" , content = json .dumps (collection ))
98
+ assert response .is_success , response .text
99
+ assert response .json ()["type" ] == "Collection"
100
+
101
+
102
+ def test_update_collection (client : TestClient , collection : Collection ) -> None :
103
+ response = client .put ("/collections/a-collection" , content = json .dumps (collection ))
104
+ assert response .is_success , response .text
105
+ assert response .json ()["path_collection_id" ] == "a-collection"
106
+ assert response .json ()["type" ] == "Collection"
107
+
108
+
109
+ def test_delete_collection (client : TestClient , collection : Collection ) -> None :
110
+ response = client .delete ("/collections/a-collection" )
111
+ assert response .is_success , response .text
112
+ assert response .json ()["path_collection_id" ] == "a-collection"
113
+
114
+
72
115
@pytest .fixture
73
116
def client (
74
117
core_client : DummyCoreClient , transactions_client : DummyTransactionsClient
@@ -119,3 +162,19 @@ def item() -> Item:
119
162
"assets" : {},
120
163
"collection" : "test_collection" ,
121
164
}
165
+
166
+
167
+ @pytest .fixture
168
+ def collection () -> Collection :
169
+ return {
170
+ "type" : "Collection" ,
171
+ "stac_version" : "1.0.0" ,
172
+ "stac_extensions" : [],
173
+ "id" : "test_collection" ,
174
+ "extent" : {
175
+ "spatial" : {"bbox" : [[- 180 , - 90 , 180 , 90 ]]},
176
+ "temporal" : {
177
+ "interval" : [["2000-01-01T00:00:00Z" , "2024-01-01T00:00:00Z" ]]
178
+ },
179
+ },
180
+ }
0 commit comments