forked from GeoSoftII2020-21/TestRepo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validator_config.py
167 lines (143 loc) · 4.02 KB
/
validator_config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/python
# -*- coding: latin-1 -*-
#@author Judith Becka, https://github.com/a2beckj
#@author Jonas Raabe, https://github.com/jona159
''' import packages'''
import requests
import json
import time
import sys
import re
import urllib.request
import os
import xarray as xr
import netCDF4
import scipy.io.netcdf
import pytest
''' Test Data '''
testjob = {
"title": "Cool Title",
"description": "Example Description",
"process": {
"process_graph": {
"loadcollection1": {
"process_id": "load_collection",
"arguments": {
"timeframe" : ["01-12-1981 00:00:00","30-12-1981 00:00:00","%d-%m-%Y %H:%M:%S"],
"DataType": "SST"
}
},
"SST": {
"process_id": "mean_sst",
"arguments": {
"data":{
"from_node": "loadcollection1"
},
"timeframe":["1981-12-01","1981-12-17"],
"bbox":[-999,-999,-999,-999]
}
},
"save":{
"process_id": "save_result",
"arguments":{
"SaveData":{
"from_node":"SST"
},
"Format": "netcdf"
}
}
}
}
}
def getJobID():
#This funktion gets the id of the last job that has been send to the server.
#The ID is then used in the create_json function
# wait until server has downloaded files
time.sleep(60)
res = requests.get("http://0.0.0.0:80/api/v1/jobs")
# Post test data to /jobs endpoint
x = requests.post("http://0.0.0.0:80/api/v1/jobs", json=testjob, headers={"Content-Type": "application/json"})
print(x)
time.sleep (180)
# Get Job ID
j = requests.get("http://0.0.0.0:80/api/v1/jobs")
rjson = j.json()
job_id = rjson['jobs'][-1]['id']
print(rjson)
print(job_id)
''' call create_json function '''
create_json(job_id)
def create_json(job_id):
'''
This function creates the config file for the backend validator in json format.
It uses the dynamically created job ID
'''
data_set = {
"url": "http://0.0.0.0:80/api/v1",
"openapi": "https://raw.githubusercontent.com/Open-EO/openeo-api/1.0.0/openapi.yaml",
"variables": { },
"endpoints": {
"endpoint.default": {
"url": "/",
"request_type": "GET",
"group": "OpenEO API endpoints"
},
"endpoint.well-known.openeo": {
"url": "/.well-known/openeo",
"request_type": "GET",
"group": "OpenEO API endpoints"
},
"endpoint.collections": {
"url": "/collections",
"request_type": "GET",
"group": "OpenEO API endpoints"
},
"endpoint.processes": {
"url": "/processes",
"request_type": "GET",
"group": "OpenEO API endpoints"
},
"endpoint.jobs_post": {
"url": "/jobs",
"request_type": "POST",
"body": "/home/runner/work/TestRepo/TestRepo/BackendValidator/testjob_sst.json",
"group": "OpenEO API endpoints"
},
"endpoint.jobs_get": {
"url": "/jobs/" + job_id,
"request_type": "GET",
"group": "OpenEO API endpoints"
},
"endpoint.jobs_delete": {
"url": "/jobs/" + job_id,
"request_type": "DELETE",
"group": "OpenEO API endpoints"
},
"endpoint.jobs_patch": {
"url": "/jobs/" + job_id,
"request_type": "PATCH",
"body": "/home/runner/work/TestRepo/TestRepo/BackendValidator/validator_patch.json",
"group": "OpenEO API endpoints"
},
"endpoint.jobs_results_get": {
"url": "/jobs/" + job_id + "/results",
"request_type": "GET",
"group": "OpenEO API endpoints"
},
"endpoint.jobs_results_post": {
"url": "/jobs/" + job_id + "/results",
"request_type": "POST",
"group": "OpenEO API endpoints"
},
"endpoint.data": {
"url": "/data",
"request_type": "POST",
"body": "/home/runner/work/TestRepo/TestRepo/BackendValidator/testjob_ndvi.json",
"group": "Own endpoints"
}
}
}
# save json locally
with open('validator.json', 'w') as f:
json.dump(data_set, f)
getJobID()