Skip to content

Commit b06e60c

Browse files
Merge pull request #19 from geo-engine/retrieve-workflow
query workflow definition
2 parents 81123a0 + 28ef1e9 commit b06e60c

File tree

2 files changed

+94
-2
lines changed

2 files changed

+94
-2
lines changed

geoengine/workflow.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
'''
44

55
from __future__ import annotations
6-
from typing import Dict, List
6+
from typing import Any, Dict, List
77

88
from uuid import UUID
99
from logging import debug
@@ -95,6 +95,18 @@ def get_result_descriptor(self) -> ResultDescriptor:
9595

9696
return self.__result_descriptor
9797

98+
def workflow_definition(self) -> Dict[str, Any]:
99+
'''Return the workflow definition for this workflow'''
100+
101+
session = get_session()
102+
103+
response = req.get(
104+
f'{session.server_url}/workflow/{self.__workflow_id}',
105+
headers=session.auth_header
106+
).json()
107+
108+
return response
109+
98110
def __get_wfs_url(self, bbox: QueryRectangle) -> str:
99111
'''Build a WFS url from a workflow and a `QueryRectangle`'''
100112

@@ -383,7 +395,7 @@ def get_provenance(self) -> List[ProvenanceOutput]:
383395
return [ProvenanceOutput.from_response(item) for item in response]
384396

385397

386-
def register_workflow(workflow: str) -> Workflow:
398+
def register_workflow(workflow: Dict[str, Any]) -> Workflow:
387399
'''
388400
Register a workflow in Geo Engine and receive a `WorkflowId`
389401
'''

tests/test_wfs.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,86 @@ def test_result_descriptor(self):
506506
self.assertEqual(str(exception.exception),
507507
'NotFound: Not Found')
508508

509+
def test_workflow_retrieval(self):
510+
workflow_definition = {
511+
"type": "Vector",
512+
"operator": {
513+
"type": "RasterVectorJoin",
514+
"params": {
515+
"names": [
516+
"NDVI"
517+
],
518+
"featureAggregation": "first",
519+
"temporalAggregation": "none"
520+
},
521+
"sources": {
522+
"vector": {
523+
"type": "OgrSource",
524+
"params": {
525+
"dataset": {
526+
"type": "internal",
527+
"datasetId": "a9623a5b-b6c5-404b-bc5a-313ff72e4e75"
528+
},
529+
"attributeProjection": None
530+
}
531+
},
532+
"rasters": [
533+
{
534+
"type": "GdalSource",
535+
"params": {
536+
"dataset": {
537+
"type": "internal",
538+
"datasetId": "36574dc3-560a-4b09-9d22-d5945f2b8093"
539+
}
540+
}
541+
}
542+
]
543+
}
544+
}
545+
}
546+
547+
with requests_mock.Mocker() as m:
548+
m.post('http://mock-instance/anonymous', json={
549+
"id": "c4983c3e-9b53-47ae-bda9-382223bd5081",
550+
"project": None,
551+
"view": None
552+
})
553+
554+
m.post('http://mock-instance/workflow',
555+
json={
556+
"id": "4a2cb6e0-a3e3-53e4-9a0f-ed1cf2e4c3b7"
557+
},
558+
request_headers={'Authorization': 'Bearer c4983c3e-9b53-47ae-bda9-382223bd5081'})
559+
560+
m.get('http://mock-instance/workflow/4a2cb6e0-a3e3-53e4-9a0f-ed1cf2e4c3b7/metadata',
561+
json={
562+
"type": "vector",
563+
"dataType": "MultiPoint",
564+
"spatialReference": "EPSG:4326",
565+
"columns": {
566+
"name": "text",
567+
"scalerank": "int",
568+
"NDVI": "int",
569+
"natlscale": "float",
570+
"featurecla": "text",
571+
"website": "text"
572+
}
573+
},
574+
request_headers={'Authorization': 'Bearer c4983c3e-9b53-47ae-bda9-382223bd5081'})
575+
576+
m.get('http://mock-instance/workflow/4a2cb6e0-a3e3-53e4-9a0f-ed1cf2e4c3b7',
577+
json=workflow_definition,
578+
request_headers={'Authorization': 'Bearer c4983c3e-9b53-47ae-bda9-382223bd5081'})
579+
580+
ge.initialize("http://mock-instance")
581+
582+
workflow = ge.register_workflow(workflow_definition)
583+
584+
self.assertEqual(
585+
workflow.workflow_definition(),
586+
workflow_definition
587+
)
588+
509589

510590
if __name__ == '__main__':
511591
unittest.main()

0 commit comments

Comments
 (0)