Skip to content

Commit 16e3842

Browse files
committed
add remaining session unit tests
1 parent e579953 commit 16e3842

File tree

4 files changed

+100
-25
lines changed

4 files changed

+100
-25
lines changed

examples/notebooks/PoC_GEE_UsingProcess.ipynb

+31-20
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
{
6060
"data": {
6161
"text/plain": [
62-
"<openeo.rest.rest_session.RESTSession at 0x7f3b68185400>"
62+
"<openeo.rest.rest_session.RESTSession at 0x7ff3b7a6ae48>"
6363
]
6464
},
6565
"execution_count": 3,
@@ -149,30 +149,40 @@
149149
},
150150
{
151151
"cell_type": "code",
152-
"execution_count": 7,
152+
"execution_count": 5,
153153
"metadata": {},
154154
"outputs": [
155155
{
156156
"data": {
157157
"text/plain": [
158-
"[{'product_id': 'ASTER/AST_L1T_003',\n",
159-
" 'description': 'ASTER L1T Radiance',\n",
160-
" 'source': 'NASA LP DAAC at the USGS EROS Center, https://lpdaac.usgs.gov/dataset_discovery/aster/aster_products_table/ast_l1t'},\n",
161-
" {'product_id': 'AU/GA/AUSTRALIA_5M_DEM',\n",
162-
" 'description': 'Australian 5M DEM',\n",
163-
" 'source': 'Geoscience Australia, https://ecat.ga.gov.au/geonetwork/srv/eng/search#!22be4b55-2465-4320-e053-10a3070a5236'},\n",
164-
" {'product_id': 'CIESIN/GPWv4/population-count',\n",
165-
" 'description': 'Gridded Population of the World, Version 4 (GPWv4): Population Count',\n",
166-
" 'source': 'CIESIN, http://sedac.ciesin.columbia.edu/data/collection/gpw-v4'},\n",
167-
" {'product_id': 'CIESIN/GPWv4/population-density',\n",
168-
" 'description': 'Gridded Population of the World, Version 4 (GPWv4): Population Density',\n",
169-
" 'source': 'CIESIN, http://sedac.ciesin.columbia.edu/data/collection/gpw-v4'},\n",
170-
" {'product_id': 'CIESIN/GPWv4/unwpp-adjusted-population-count',\n",
171-
" 'description': 'Gridded Population of the World, Version 4 (GPWv4): UN-Adjusted Population Count',\n",
172-
" 'source': 'CIESIN, http://sedac.ciesin.columbia.edu/data/collection/gpw-v4'}]"
158+
"{'product_id': 'COPERNICUS/S2',\n",
159+
" 'description': 'Sentinel-2 MSI: MultiSpectral Instrument, Level-1C',\n",
160+
" 'source': 'European Union/ESA/Copernicus, https://sentinel.esa.int/web/sentinel/user-guides/sentinel-2-msi',\n",
161+
" 'time': {'from': '2015-06-23', 'to': '2018-06-27'},\n",
162+
" 'bands': [{'band_id': 'B1'},\n",
163+
" {'band_id': 'B2'},\n",
164+
" {'band_id': 'B3'},\n",
165+
" {'band_id': 'B4'},\n",
166+
" {'band_id': 'B5'},\n",
167+
" {'band_id': 'B6'},\n",
168+
" {'band_id': 'B7'},\n",
169+
" {'band_id': 'B8'},\n",
170+
" {'band_id': 'B8A'},\n",
171+
" {'band_id': 'B9'},\n",
172+
" {'band_id': 'B10'},\n",
173+
" {'band_id': 'B11'},\n",
174+
" {'band_id': 'B12'},\n",
175+
" {'band_id': 'QA10'},\n",
176+
" {'band_id': 'QA20'},\n",
177+
" {'band_id': 'QA60'}],\n",
178+
" 'extent': {'srs': 'EPSG:4326',\n",
179+
" 'left': -180,\n",
180+
" 'right': 180,\n",
181+
" 'bottom': -90,\n",
182+
" 'top': 90}}"
173183
]
174184
},
175-
"execution_count": 7,
185+
"execution_count": 5,
176186
"metadata": {},
177187
"output_type": "execute_result"
178188
}
@@ -181,7 +191,8 @@
181191
"# Retrieve the list of available collections\n",
182192
"collections = session.list_collections()\n",
183193
"\n",
184-
"list(collections)[:5]"
194+
"list(collections)[:5]\n",
195+
"session.get_collection(PRODUCT_ID)"
185196
]
186197
},
187198
{
@@ -401,7 +412,7 @@
401412
"name": "python",
402413
"nbconvert_exporter": "python",
403414
"pygments_lexer": "ipython3",
404-
"version": "3.6.5"
415+
"version": "3.6.4"
405416
}
406417
},
407418
"nbformat": 4,

openeo/rest/rest_session.py

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def auth(self, username, password, auth_class=NoneAuth) -> bool:
4646

4747
def user_jobs(self) -> dict:
4848
#TODO: Create a kind of User class to abstract the information (e.g. userid, username, password from the session.
49+
#TODO: Move information to Job class and return a list of Jobs.
4950
"""
5051
Loads all jobs of the current user.
5152
:return: jobs: Dict All jobs of the user

openeo/sessions.py

+10
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,16 @@ def user_upload_file(self, file_path, remote_path=None):
142142
:return: status: True if it was successful, False otherwise
143143
"""
144144

145+
@abstractmethod
146+
def user_delete_file(self, file_path):
147+
"""
148+
Deletes a user file in the back end.
149+
150+
:param file_path: remote path to the file that should be deleted.
151+
:return: status: True if it was successful, False otherwise
152+
"""
153+
pass
154+
145155
@abstractmethod
146156
def user_list_files(self):
147157
"""

tests/test_rest_session.py

+58-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,32 @@
1717
'source': 'NASA LP DAAC at the USGS EROS Center, https://lpdaac.usgs.gov/dataset_discovery/aster/aster_products_table/ast_l1t'},
1818
{'product_id': 'AU/GA/AUSTRALIA_5M_DEM',
1919
'description': 'Australian 5M DEM',
20-
'source': 'Geoscience Australia, https://ecat.ga.gov.au/geonetwork/srv/eng/search#!22be4b55-2465-4320-e053-10a3070a5236'}]
20+
'source': 'Geoscience Australia, https://ecat.ga.gov.au/geonetwork/srv/eng/search#!22be4b55-2465-4320-e053-10a3070a5236'},
21+
{'product_id': 'COPERNICUS/S2',
22+
'description': 'Sentinel-2 MSI: MultiSpectral Instrument, Level-1C',
23+
'source': 'European Union/ESA/Copernicus, https://sentinel.esa.int/web/sentinel/user-guides/sentinel-2-msi',
24+
'time': {'from': '2015-06-23', 'to': '2018-06-27'},
25+
'bands': [{'band_id': 'B1'},
26+
{'band_id': 'B2'},
27+
{'band_id': 'B3'},
28+
{'band_id': 'B4'},
29+
{'band_id': 'B5'},
30+
{'band_id': 'B6'},
31+
{'band_id': 'B7'},
32+
{'band_id': 'B8'},
33+
{'band_id': 'B8A'},
34+
{'band_id': 'B9'},
35+
{'band_id': 'B10'},
36+
{'band_id': 'B11'},
37+
{'band_id': 'B12'},
38+
{'band_id': 'QA10'},
39+
{'band_id': 'QA20'},
40+
{'band_id': 'QA60'}],
41+
'extent': {'srs': 'EPSG:4326',
42+
'left': -180,
43+
'right': 180,
44+
'bottom': -90,
45+
'top': 90}}]
2146

2247
PROCESSES = [{'process_id': 'zonal_statistics',
2348
'description': 'Calculates statistics for each zone specified in a file.'},
@@ -47,6 +72,11 @@ def match_uploaded_file(self, request):
4772
assert request.json() == json.loads(content)
4873
return True
4974

75+
def match_process_graph(self, request):
76+
77+
assert request.json() == PROCESSES
78+
return True
79+
5080
def test_user_upload_file(self, m):
5181
upload_url = "{}/users/{}/files/{}".format(self.endpoint, self.user_id,
5282
self.upload_remote_fname)
@@ -129,13 +159,12 @@ def test_get_process(self, m):
129159

130160
def test_create_job(self, m):
131161

132-
# TODO: Add Test to check if post_data is sent properly
133-
post_data = {}
162+
post_data = PROCESSES
134163
job_id = "MyId"
135164
result = {"job_id": job_id}
136165

137-
m.register_uri('POST', "{}/jobs?evaluate={}".format(self.endpoint, "lazy"), status_code=200, json=result)
138-
m.register_uri('POST', "{}/jobs?evaluate={}".format(self.endpoint, "wrong"), status_code=400)
166+
m.register_uri('POST', "{}/jobs?evaluate={}".format(self.endpoint, "lazy"), status_code=200, json=result, additional_matcher=self.match_process_graph)
167+
m.register_uri('POST', "{}/jobs?evaluate={}".format(self.endpoint, "wrong"), status_code=400, additional_matcher=self.match_process_graph)
139168

140169
session = openeo.session(self.user_id, endpoint=self.endpoint)
141170

@@ -147,3 +176,27 @@ def test_create_job(self, m):
147176

148177
assert resp is None
149178

179+
def test_image(self, m):
180+
181+
collection_org = COLLECTIONS[2]
182+
collection_id = collection_org["product_id"]
183+
collection_url = "{}/data/{}".format(self.endpoint, collection_id)
184+
m.register_uri('GET', collection_url, json=collection_org)
185+
186+
session = openeo.session(self.user_id, endpoint=self.endpoint)
187+
188+
resp = session.image(collection_id)
189+
190+
assert resp.bands == ['B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8',
191+
'B8A', 'B9', 'B10', 'B11', 'B12', 'QA10', 'QA20', 'QA60']
192+
193+
def user_jobs(self, m):
194+
195+
collection_url = "{}/users/{}/jobs".format(self.endpoint, self.user_id)
196+
m.register_uri('GET', collection_url, json=PROCESSES)
197+
198+
session = openeo.session(self.user_id, endpoint=self.endpoint)
199+
200+
resp = session.user_jobs()
201+
202+
assert resp == PROCESSES

0 commit comments

Comments
 (0)