@@ -27,34 +27,40 @@ def test_empty_order(stapi_client: TestClient):
2727
2828
2929@pytest .fixture
30- def create_order_allowed_payloads () -> list [OrderPayload ]:
31- return [
32- OrderPayload (
30+ def create_order_payloads () -> list [OrderPayload ]:
31+ datetimes = [
32+ ("2024-10-09T18:55:33Z" , "2024-10-12T18:55:33Z" ),
33+ ("2024-10-15T18:55:33Z" , "2024-10-18T18:55:33Z" ),
34+ ("2024-10-20T18:55:33Z" , "2024-10-23T18:55:33Z" ),
35+ ]
36+ payloads = []
37+ for start , end in datetimes :
38+ payload = OrderPayload (
3339 geometry = Point (
34- type = "Point" , coordinates = Position2D (longitude = 13 .4 , latitude = 52 .5 )
40+ type = "Point" , coordinates = Position2D (longitude = 14 .4 , latitude = 56 .5 )
3541 ),
3642 datetime = (
37- datetime .fromisoformat ("2024-11-11T18:55:33Z" ),
38- datetime .fromisoformat ("2024-11-15T18:55:33Z" ),
43+ datetime .fromisoformat (start ),
44+ datetime .fromisoformat (end ),
3945 ),
4046 filter = None ,
4147 order_parameters = MyOrderParameters (s3_path = "s3://my-bucket" ),
42- ),
43- ]
48+ )
49+ payloads .append (payload )
50+ return payloads
4451
4552
4653@pytest .fixture
4754def new_order_response (
4855 product_id : str ,
4956 product_backend : MockProductBackend ,
5057 stapi_client : TestClient ,
51- create_order_allowed_payloads : list [OrderPayload ],
58+ create_order_payloads : list [OrderPayload ],
5259) -> Response :
53- product_backend ._allowed_payloads = create_order_allowed_payloads
54-
60+ product_backend ._allowed_payloads = create_order_payloads
5561 res = stapi_client .post (
5662 f"products/{ product_id } /orders" ,
57- json = create_order_allowed_payloads [0 ].model_dump (),
63+ json = create_order_payloads [0 ].model_dump (),
5864 )
5965
6066 assert res .status_code == status .HTTP_201_CREATED , res .text
@@ -105,23 +111,23 @@ def get_order_response(
105111
106112@pytest .mark .parametrize ("product_id" , ["test-spotlight" ])
107113def test_get_order_properties (
108- get_order_response : Response , create_order_allowed_payloads
114+ get_order_response : Response , create_order_payloads
109115) -> None :
110116 order = get_order_response .json ()
111117
112118 assert order ["geometry" ] == {
113119 "type" : "Point" ,
114- "coordinates" : list (create_order_allowed_payloads [0 ].geometry .coordinates ),
120+ "coordinates" : list (create_order_payloads [0 ].geometry .coordinates ),
115121 }
116122
117123 assert order ["properties" ]["search_parameters" ]["geometry" ] == {
118124 "type" : "Point" ,
119- "coordinates" : list (create_order_allowed_payloads [0 ].geometry .coordinates ),
125+ "coordinates" : list (create_order_payloads [0 ].geometry .coordinates ),
120126 }
121127
122128 assert (
123129 order ["properties" ]["search_parameters" ]["datetime" ]
124- == create_order_allowed_payloads [0 ].model_dump ()["datetime" ]
130+ == create_order_payloads [0 ].model_dump ()["datetime" ]
125131 )
126132
127133
@@ -141,73 +147,21 @@ def test_order_status_after_create(
141147 assert len (res .json ()["statuses" ]) == 1
142148
143149
144- @pytest .mark .parametrize ("product_id" , ["test-spotlight" ])
145- def test_order_status_after_update (
146- get_order_response : Response , stapi_client : TestClient
147- ) -> None :
148- body = get_order_response .json ()
149- statuses_url = find_link (body ["links" ], "monitor" )["href" ]
150-
151- res = stapi_client .post (
152- statuses_url ,
153- json = {
154- "status_code" : "accepted" ,
155- "reason_code" : "REASON1" ,
156- "reason_text" : "some reason" ,
157- },
158- )
159-
160- assert res .status_code == status .HTTP_202_ACCEPTED
161-
162- res = stapi_client .get (statuses_url )
163- assert res .status_code == status .HTTP_200_OK
164- assert res .headers ["Content-Type" ] == "application/json"
165- body = res .json ()
166- assert len (body ["statuses" ]) == 2
167-
168- s = body ["statuses" ][0 ]
169- assert s ["reason_code" ] == "REASON1"
170- assert s ["reason_text" ] == "some reason"
171- assert s ["status_code" ] == "accepted"
172- assert s ["timestamp" ]
173-
174- s = body ["statuses" ][1 ]
175- assert s ["reason_code" ] is None
176- assert s ["reason_text" ] is None
177- assert s ["status_code" ] == "received"
178- assert s ["timestamp" ]
179-
180-
181150@pytest .fixture
182- def create_order_payloads () -> list [OrderPayload ]:
183- datetimes = [
184- ("2024-10-09T18:55:33Z" , "2024-10-12T18:55:33Z" ),
185- ("2024-10-15T18:55:33Z" , "2024-10-18T18:55:33Z" ),
186- ("2024-10-20T18:55:33Z" , "2024-10-23T18:55:33Z" ),
187- ]
188- payloads = []
189- for start , end in datetimes :
190- payload = OrderPayload (
191- geometry = Point (
192- type = "Point" , coordinates = Position2D (longitude = 14.4 , latitude = 56.5 )
193- ),
194- datetime = (
195- datetime .fromisoformat (start ),
196- datetime .fromisoformat (end ),
197- ),
198- filter = None ,
199- order_parameters = MyOrderParameters (s3_path = "s3://my-bucket" ),
151+ def setup_pagination (stapi_client : TestClient , create_order_payloads ) -> None :
152+ product_id = "test-spotlight"
153+
154+ for order in create_order_payloads :
155+ res = stapi_client .post (
156+ f"products/{ product_id } /orders" ,
157+ json = order .model_dump (),
200158 )
201- payloads .append (payload )
202- return payloads
203159
160+ assert res .status_code == status .HTTP_201_CREATED , res .text
161+ assert res .headers ["Content-Type" ] == "application/geo+json"
204162
205- def test_order_pagination (
206- prepare_order_pagination ,
207- stapi_client : TestClient ,
208- ) -> None :
209- # prepare_order_pagination
210163
164+ def test_order_pagination (stapi_client : TestClient , setup_pagination ) -> None :
211165 res = stapi_client .get ("/orders" , params = {"next" : None , "limit" : 1 })
212166 assert res .status_code == status .HTTP_200_OK
213167 body = res .json ()
@@ -223,7 +177,6 @@ def test_order_pagination(
223177 break
224178
225179
226- # separate test here to check for bad token getting back 404
227180def test_token_not_found (stapi_client : TestClient ):
228181 res = stapi_client .get ("/orders" , params = {"next" : "a_token" })
229182 # should return 404 as a result of bad token
0 commit comments