forked from Open-EO/openeo-grassgis-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_process_graph.py
131 lines (94 loc) · 5.01 KB
/
test_process_graph.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
# -*- 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"
PROCESS_CHAIN_TEMPLATE = {
"title": "The title of the process chain",
"description": "The description of the process chain",
"process_graph": None,
}
class ProcessGraphTestCase(TestBase):
def setUp(self):
TestBase.setUp(self)
response = self.app.delete('/process_graphs', headers=self.auth)
self.assertEqual(204, response.status_code)
def test_job_creation_1(self):
"""Run the test in the ephemeral database
"""
PROCESS_CHAIN_TEMPLATE["process_graph"] = FILTER_BOX["process_graph"]
response = self.app.post('/process_graphs', data=json.dumps(PROCESS_CHAIN_TEMPLATE),
content_type="application/json", headers=self.auth)
self.assertEqual(201, response.status_code)
process_graph_id = response.get_data().decode("utf-8")
response = self.app.get('/process_graphs', headers=self.auth)
self.assertEqual(200, response.status_code)
data = json.loads(response.get_data().decode("utf-8"))
pprint.pprint(data)
self.assertEqual(process_graph_id, data["process_graphs"][0]["process_graph_id"])
response = self.app.get(f'/process_graphs/{process_graph_id}', headers=self.auth)
self.assertEqual(200, response.status_code)
data = json.loads(response.get_data().decode("utf-8"))
pprint.pprint(data)
self.assertEqual(process_graph_id, data["process_graph_id"])
self.assertEqual(FILTER_BOX["process_graph"], data["process_graph"])
def test_job_creation_2(self):
"""Run the test in the ephemeral database
"""
PROCESS_CHAIN_TEMPLATE["process_graph"] = FILTER_BOX["process_graph"]
response = self.app.post('/process_graphs', data=json.dumps(PROCESS_CHAIN_TEMPLATE),
content_type="application/json", headers=self.auth)
self.assertEqual(201, response.status_code)
process_graph_id = response.get_data().decode("utf-8")
response = self.app.get(f'/process_graphs/{process_graph_id}', headers=self.auth)
self.assertEqual(200, response.status_code)
data = json.loads(response.get_data().decode("utf-8"))
pprint.pprint(data)
self.assertEqual(process_graph_id, data["process_graph_id"])
self.assertEqual(FILTER_BOX["process_graph"], data["process_graph"])
response = self.app.delete(f'/process_graphs/{process_graph_id}', headers=self.auth)
self.assertEqual(204, response.status_code)
response = self.app.get(f'/process_graphs/{process_graph_id}', headers=self.auth)
self.assertEqual(400, response.status_code)
response = self.app.get('/process_graphs', headers=self.auth)
self.assertEqual(200, response.status_code)
data = json.loads(response.get_data().decode("utf-8"))
pprint.pprint(data)
self.assertEqual(0, len(data['process_graphs']))
def test_job_creation_3(self):
"""Run the test in the ephemeral database
"""
PROCESS_CHAIN_TEMPLATE["process_graph"] = FILTER_BOX["process_graph"]
# Create graph
response = self.app.post('/process_graphs', data=json.dumps(PROCESS_CHAIN_TEMPLATE),
content_type="application/json", headers=self.auth)
self.assertEqual(201, response.status_code)
process_graph_id = response.get_data().decode("utf-8")
# Check graph
response = self.app.get(f'/process_graphs/{process_graph_id}', headers=self.auth)
self.assertEqual(200, response.status_code)
data = json.loads(response.get_data().decode("utf-8"))
pprint.pprint(data)
self.assertEqual(process_graph_id, data["process_graph_id"])
self.assertEqual(FILTER_BOX["process_graph"], data["process_graph"])
# Modify graph
PROCESS_CHAIN_TEMPLATE["process_graph"] = ZONAL_STATISTICS_SINGLE["process_graph"]
response = self.app.patch(f'/process_graphs/{process_graph_id}',
data=json.dumps(PROCESS_CHAIN_TEMPLATE),
content_type="application/json", headers=self.auth)
self.assertEqual(204, response.status_code)
# Check graph
response = self.app.get(f'/process_graphs/{process_graph_id}', headers=self.auth)
self.assertEqual(200, response.status_code)
data = json.loads(response.get_data().decode("utf-8"))
pprint.pprint(data)
self.assertEqual(process_graph_id, data["process_graph_id"])
self.assertEqual(ZONAL_STATISTICS_SINGLE["process_graph"], data["process_graph"])
if __name__ == "__main__":
unittest.main()