forked from Open-EO/openeo-grassgis-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_jobs.py
203 lines (153 loc) · 7.53 KB
/
test_jobs.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# -*- coding: utf-8 -*-
import unittest
import pprint
from flask import json
from openeo_grass_gis_driver.test_base import TestBase
from openeo_grass_gis_driver.utils.process_graph_examples_v03 import *
__license__ = "Apache License, Version 2.0"
__author__ = "Sören Gebbert"
__copyright__ = "Copyright 2018, Sören Gebbert, mundialis"
__maintainer__ = "Soeren Gebbert"
__email__ = "soerengebbert@googlemail.com"
JOB_TEMPLATE = {
"title": "The title of the job",
"description": "The description of the job",
"process_graph": None,
}
class JobsTestCase(TestBase):
def setUp(self):
TestBase.setUp(self)
response = self.app.delete('/jobs', headers=self.auth)
self.assertEqual(204, response.status_code)
def test_job_creation_1(self):
"""Run the test in the ephemeral database
"""
JOB_TEMPLATE["process_graph"] = FILTER_BOX["process_graph"]
response = self.app.post('/jobs', data=json.dumps(JOB_TEMPLATE), content_type="application/json", headers=self.auth)
self.assertEqual(201, response.status_code)
job_id = response.get_data().decode("utf-8")
response = self.app.get('/jobs')
self.assertEqual(200, response.status_code)
data = json.loads(response.get_data().decode("utf-8"))
pprint.pprint(data)
self.assertEqual(job_id, data["jobs"][0]["job_id"])
response = self.app.get(f'/jobs/{job_id}', headers=self.auth)
self.assertEqual(200, response.status_code)
data = json.loads(response.get_data().decode("utf-8"))
pprint.pprint(data)
self.assertEqual(job_id, data["job_id"])
self.assertEqual(FILTER_BOX["process_graph"], data["process_graph"])
def test_job_creation_2(self):
"""Run the test in the ephemeral database
"""
JOB_TEMPLATE["process_graph"] = ZONAL_STATISTICS["process_graph"]
response = self.app.post('/jobs', data=json.dumps(JOB_TEMPLATE), content_type="application/json", headers=self.auth)
self.assertEqual(201, response.status_code)
job_id = response.get_data().decode("utf-8")
response = self.app.get(f'/jobs/{job_id}', headers=self.auth)
self.assertEqual(200, response.status_code)
data = json.loads(response.get_data().decode("utf-8"))
pprint.pprint(data)
self.assertEqual(job_id, data["job_id"])
self.assertEqual(ZONAL_STATISTICS["process_graph"], data["process_graph"])
response = self.app.get(f'/jobs/{job_id}' + "_nope", headers=self.auth)
self.assertEqual(404, response.status_code)
def test_job_creation_deletion_1(self):
"""Run the test in the ephemeral database
"""
JOB_TEMPLATE["process_graph"] = ZONAL_STATISTICS["process_graph"]
response = self.app.post('/jobs', data=json.dumps(JOB_TEMPLATE), content_type="application/json", headers=self.auth)
self.assertEqual(201, response.status_code)
job_id = response.get_data().decode("utf-8")
response = self.app.get(f'/jobs/{job_id}', headers=self.auth)
self.assertEqual(200, response.status_code)
response = self.app.delete(f'/jobs/{job_id}', headers=self.auth)
self.assertEqual(204, response.status_code)
response = self.app.delete(f'/jobs/{job_id}', headers=self.auth)
self.assertEqual(404, response.status_code)
response = self.app.get(f'/jobs/{job_id}', headers=self.auth)
self.assertEqual(404, response.status_code)
class JobsTestResultsCase(TestBase):
def setUp(self):
TestBase.setUp(self)
response = self.app.delete('/jobs', headers=self.auth)
self.assertEqual(204, response.status_code)
def test_job_creation_and_processing_filter_box(self):
"""Run the test in the ephemeral database
"""
JOB_TEMPLATE["process_graph"] = FILTER_BOX["process_graph"]
response = self.app.post('/jobs', data=json.dumps(JOB_TEMPLATE), content_type="application/json", headers=self.auth)
self.assertEqual(201, response.status_code)
job_id = response.get_data().decode("utf-8")
# Get job information
response = self.app.get(f'/jobs/{job_id}/results', headers=self.auth)
self.assertEqual(200, response.status_code)
data = response.get_data().decode("utf-8")
print(data)
# Start the job
response = self.app.post(f'/jobs/{job_id}/results', headers=self.auth)
data = response.get_data().decode("utf-8")
print(data)
self.assertEqual(202, response.status_code)
# get job information
response = self.app.get(f'/jobs/{job_id}/results', headers=self.auth)
data = response.get_data().decode("utf-8")
print(data)
self.assertEqual(200, response.status_code)
def test_job_creation_and_processing_zonal_stats(self):
"""Run the test in the ephemeral database
"""
JOB_TEMPLATE["process_graph"] = ZONAL_STATISTICS_SINGLE["process_graph"]
response = self.app.post('/jobs', data=json.dumps(JOB_TEMPLATE), content_type="application/json", headers=self.auth)
self.assertEqual(201, response.status_code)
job_id = response.get_data().decode("utf-8")
# Get job information
response = self.app.get(f'/jobs/{job_id}/results', content_type="application/json", headers=self.auth)
self.assertEqual(200, response.status_code)
data = response.get_data().decode("utf-8")
print(data)
# Start the job
response = self.app.post(f'/jobs/{job_id}/results', headers=self.auth)
data = response.get_data().decode("utf-8")
print(data)
self.assertEqual(202, response.status_code)
# get job information
response = self.app.get(f'/jobs/{job_id}/results', headers=self.auth)
data = response.get_data().decode("utf-8")
print(data)
self.assertEqual(200, response.status_code)
# cancel the job
response = self.app.delete(f'/jobs/{job_id}/results', headers=self.auth)
data = response.get_data().decode("utf-8")
print(data)
self.assertEqual(204, response.status_code)
import time
time.sleep(2)
# get job information
response = self.app.get(f'/jobs/{job_id}/results', headers=self.auth)
data = response.get_data().decode("utf-8")
print(data)
self.assertEqual(200, response.status_code)
def test_job_creation_and_patch_filter_box(self):
"""Run job creation and patch test
"""
JOB_TEMPLATE["process_graph"] = FILTER_BOX["process_graph"]
response = self.app.post('/jobs', data=json.dumps(JOB_TEMPLATE), content_type="application/json", headers=self.auth)
self.assertEqual(201, response.status_code)
job_id = response.get_data().decode("utf-8")
print(job_id)
# Get job information
response = self.app.get(f'/jobs/{job_id}', headers=self.auth)
data = response.get_data().decode("utf-8")
print(data)
self.assertEqual(200, response.status_code)
JOB_TEMPLATE["process_graph"] = ZONAL_STATISTICS_SINGLE["process_graph"]
response = self.app.patch(f'/jobs/{job_id}', data=json.dumps(JOB_TEMPLATE), content_type="application/json", headers=self.auth)
self.assertEqual(204, response.status_code)
# Get job information
response = self.app.get(f'/jobs/{job_id}', headers=self.auth)
data = response.get_data().decode("utf-8")
print(data)
self.assertEqual(200, response.status_code)
if __name__ == "__main__":
unittest.main()