Skip to content

Commit eedc483

Browse files
build: use openapi client 0.0.30 (#249)
* build: use openapi client 0.0.30 * build: use openapi client 0.0.30 * dependency from http rather than ssh * fix: permission response * fix version
1 parent d61eb5d commit eedc483

File tree

4 files changed

+17
-74
lines changed

4 files changed

+17
-74
lines changed

geoengine/permissions.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from __future__ import annotations
66

7-
import ast
87
from enum import Enum
98
from uuid import UUID
109

@@ -255,11 +254,7 @@ def add_role(name: str, timeout: int = 60) -> RoleId:
255254
user_api = geoengine_openapi_client.UserApi(api_client)
256255
response = user_api.add_role_handler(geoengine_openapi_client.AddRole(name=name, _request_timeout=timeout))
257256

258-
# TODO: find out why JSON string is faulty
259-
# parsed_response = json.loads(response)
260-
parsed_response: dict[str, str] = ast.literal_eval(response)
261-
262-
return RoleId.from_response(parsed_response)
257+
return RoleId(response.id)
263258

264259

265260
def remove_role(role: RoleId, timeout: int = 60):

geoengine/tasks.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ def get_status(self, timeout: int = 3600) -> TaskStatusInfo:
267267

268268
with geoengine_openapi_client.ApiClient(session.configuration) as api_client:
269269
tasks_api = geoengine_openapi_client.TasksApi(api_client)
270-
print(task_id)
271270
response = tasks_api.status_handler(task_id, _request_timeout=timeout)
272271

273272
return TaskStatusInfo.from_response(response)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ readme = { file = "README.md", content-type = "text/markdown" }
1616
license-files = ["LICENSE"]
1717
requires-python = ">=3.10"
1818
dependencies = [
19-
"geoengine-openapi-client == 0.0.29",
19+
"geoengine-openapi-client == 0.0.30",
2020
"geopandas >=1.0,<2.0",
2121
"matplotlib >=3.5,<3.11",
2222
"numpy >=1.21,<2.5",

tests/test_workflow_storage.py

Lines changed: 15 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
"""Tests for WMS calls"""
22

33
import unittest
4-
from uuid import UUID
54

65
import geoengine_openapi_client
76

87
import geoengine as ge
98
from geoengine.datasets import DatasetName, StoredDataset
10-
from geoengine.resource_identifier import UploadId
11-
12-
from . import UrllibMocker
9+
from geoengine.tasks import TaskStatus
10+
from tests.ge_test import GeoEngineTestInstance
1311

1412

1513
class WorkflowStorageTests(unittest.TestCase):
@@ -19,63 +17,11 @@ def setUp(self) -> None:
1917
ge.reset(False)
2018

2119
def test_storing_workflow(self):
22-
expected_request_text = {
23-
"asCog": True,
24-
"description": "Bar",
25-
"displayName": "Foo",
26-
"query": {
27-
"spatialBounds": {
28-
"lowerRightCoordinate": {"x": 180, "y": -90},
29-
"upperLeftCoordinate": {"x": -180, "y": 90},
30-
},
31-
"spatialResolution": {"x": 1.8, "y": 1.8},
32-
"timeInterval": {"end": 1396353600000, "start": 1396353600000},
33-
},
34-
}
35-
36-
with UrllibMocker() as m:
37-
m.post(
38-
"http://mock-instance/anonymous",
39-
json={"id": "c4983c3e-9b53-47ae-bda9-382223bd5081", "project": None, "view": None},
40-
)
41-
42-
m.post(
43-
"http://mock-instance/workflow",
44-
json={"id": "5b9508a8-bd34-5a1c-acd6-75bb832d2d38"},
45-
request_headers={"Authorization": "Bearer c4983c3e-9b53-47ae-bda9-382223bd5081"},
46-
)
47-
48-
m.get(
49-
"http://mock-instance/workflow/5b9508a8-bd34-5a1c-acd6-75bb832d2d38/metadata",
50-
json={
51-
"type": "raster",
52-
"dataType": "U8",
53-
"spatialReference": "EPSG:4326",
54-
"bands": [{"name": "band", "measurement": {"type": "unitless"}}],
55-
},
56-
request_headers={"Authorization": "Bearer c4983c3e-9b53-47ae-bda9-382223bd5081"},
57-
)
20+
# TODO: use `enterContext(cm)` instead of `with cm: ` in Python 3.11
21+
with GeoEngineTestInstance() as ge_instance:
22+
ge_instance.wait_for_ready()
5823

59-
m.post(
60-
"http://mock-instance/datasetFromWorkflow/5b9508a8-bd34-5a1c-acd6-75bb832d2d38",
61-
expected_request_body=expected_request_text,
62-
json={"taskId": "9ec828ef-c3da-4016-8cc7-79e5556267fc"},
63-
request_headers={"Authorization": "Bearer c4983c3e-9b53-47ae-bda9-382223bd5081"},
64-
)
65-
66-
m.get(
67-
"http://mock-instance/tasks/9ec828ef-c3da-4016-8cc7-79e5556267fc/status",
68-
json={
69-
"status": "completed",
70-
"info": {"dataset": "my_new_dataset", "upload": "3086f494-d5a4-4b51-a14b-3b29f8bf7bb0"},
71-
"timeTotal": "00:00:00",
72-
"taskType": "create-dataset",
73-
"description": "Creating dataset Foo from workflow 5b9508a8-bd34-5a1c-acd6-75bb832d2d38",
74-
"timeStarted": "2023-02-16T15:25:45.390Z",
75-
},
76-
)
77-
78-
ge.initialize("http://mock-instance")
24+
ge.initialize(ge_instance.address())
7925

8026
workflow_definition = {"type": "Raster", "operator": {"type": "GdalSource", "params": {"data": "ndvi"}}}
8127

@@ -89,14 +35,17 @@ def test_storing_workflow(self):
8935
)
9036

9137
workflow = ge.register_workflow(workflow_definition)
38+
39+
dataset_name = f"{ge.get_session().user_id}:my_new_dataset"
9240
task = workflow.save_as_dataset(
9341
query,
94-
None,
95-
"Foo",
96-
"Bar",
42+
name=dataset_name,
43+
display_name="Foo",
44+
description="Bar",
9745
)
46+
task.wait_for_finish()
9847
task_status = task.get_status()
99-
stored_dataset = StoredDataset.from_response(task_status.info)
48+
self.assertEqual(task_status.status, TaskStatus.COMPLETED)
10049

101-
self.assertEqual(stored_dataset.dataset_name, DatasetName("my_new_dataset"))
102-
self.assertEqual(stored_dataset.upload_id, UploadId(UUID("3086f494-d5a4-4b51-a14b-3b29f8bf7bb0")))
50+
stored_dataset = StoredDataset.from_response(task_status.info)
51+
self.assertEqual(stored_dataset.dataset_name, DatasetName(dataset_name))

0 commit comments

Comments
 (0)