Skip to content

Commit

Permalink
add remaining session unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bgoesswe committed Jul 3, 2018
1 parent e579953 commit 16e3842
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 25 deletions.
51 changes: 31 additions & 20 deletions examples/notebooks/PoC_GEE_UsingProcess.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
{
"data": {
"text/plain": [
"<openeo.rest.rest_session.RESTSession at 0x7f3b68185400>"
"<openeo.rest.rest_session.RESTSession at 0x7ff3b7a6ae48>"
]
},
"execution_count": 3,
Expand Down Expand Up @@ -149,30 +149,40 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[{'product_id': 'ASTER/AST_L1T_003',\n",
" 'description': 'ASTER L1T Radiance',\n",
" 'source': 'NASA LP DAAC at the USGS EROS Center, https://lpdaac.usgs.gov/dataset_discovery/aster/aster_products_table/ast_l1t'},\n",
" {'product_id': 'AU/GA/AUSTRALIA_5M_DEM',\n",
" 'description': 'Australian 5M DEM',\n",
" 'source': 'Geoscience Australia, https://ecat.ga.gov.au/geonetwork/srv/eng/search#!22be4b55-2465-4320-e053-10a3070a5236'},\n",
" {'product_id': 'CIESIN/GPWv4/population-count',\n",
" 'description': 'Gridded Population of the World, Version 4 (GPWv4): Population Count',\n",
" 'source': 'CIESIN, http://sedac.ciesin.columbia.edu/data/collection/gpw-v4'},\n",
" {'product_id': 'CIESIN/GPWv4/population-density',\n",
" 'description': 'Gridded Population of the World, Version 4 (GPWv4): Population Density',\n",
" 'source': 'CIESIN, http://sedac.ciesin.columbia.edu/data/collection/gpw-v4'},\n",
" {'product_id': 'CIESIN/GPWv4/unwpp-adjusted-population-count',\n",
" 'description': 'Gridded Population of the World, Version 4 (GPWv4): UN-Adjusted Population Count',\n",
" 'source': 'CIESIN, http://sedac.ciesin.columbia.edu/data/collection/gpw-v4'}]"
"{'product_id': 'COPERNICUS/S2',\n",
" 'description': 'Sentinel-2 MSI: MultiSpectral Instrument, Level-1C',\n",
" 'source': 'European Union/ESA/Copernicus, https://sentinel.esa.int/web/sentinel/user-guides/sentinel-2-msi',\n",
" 'time': {'from': '2015-06-23', 'to': '2018-06-27'},\n",
" 'bands': [{'band_id': 'B1'},\n",
" {'band_id': 'B2'},\n",
" {'band_id': 'B3'},\n",
" {'band_id': 'B4'},\n",
" {'band_id': 'B5'},\n",
" {'band_id': 'B6'},\n",
" {'band_id': 'B7'},\n",
" {'band_id': 'B8'},\n",
" {'band_id': 'B8A'},\n",
" {'band_id': 'B9'},\n",
" {'band_id': 'B10'},\n",
" {'band_id': 'B11'},\n",
" {'band_id': 'B12'},\n",
" {'band_id': 'QA10'},\n",
" {'band_id': 'QA20'},\n",
" {'band_id': 'QA60'}],\n",
" 'extent': {'srs': 'EPSG:4326',\n",
" 'left': -180,\n",
" 'right': 180,\n",
" 'bottom': -90,\n",
" 'top': 90}}"
]
},
"execution_count": 7,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -181,7 +191,8 @@
"# Retrieve the list of available collections\n",
"collections = session.list_collections()\n",
"\n",
"list(collections)[:5]"
"list(collections)[:5]\n",
"session.get_collection(PRODUCT_ID)"
]
},
{
Expand Down Expand Up @@ -401,7 +412,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
"version": "3.6.4"
}
},
"nbformat": 4,
Expand Down
1 change: 1 addition & 0 deletions openeo/rest/rest_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def auth(self, username, password, auth_class=NoneAuth) -> bool:

def user_jobs(self) -> dict:
#TODO: Create a kind of User class to abstract the information (e.g. userid, username, password from the session.
#TODO: Move information to Job class and return a list of Jobs.
"""
Loads all jobs of the current user.
:return: jobs: Dict All jobs of the user
Expand Down
10 changes: 10 additions & 0 deletions openeo/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ def user_upload_file(self, file_path, remote_path=None):
:return: status: True if it was successful, False otherwise
"""

@abstractmethod
def user_delete_file(self, file_path):
"""
Deletes a user file in the back end.
:param file_path: remote path to the file that should be deleted.
:return: status: True if it was successful, False otherwise
"""
pass

@abstractmethod
def user_list_files(self):
"""
Expand Down
63 changes: 58 additions & 5 deletions tests/test_rest_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,32 @@
'source': 'NASA LP DAAC at the USGS EROS Center, https://lpdaac.usgs.gov/dataset_discovery/aster/aster_products_table/ast_l1t'},
{'product_id': 'AU/GA/AUSTRALIA_5M_DEM',
'description': 'Australian 5M DEM',
'source': 'Geoscience Australia, https://ecat.ga.gov.au/geonetwork/srv/eng/search#!22be4b55-2465-4320-e053-10a3070a5236'}]
'source': 'Geoscience Australia, https://ecat.ga.gov.au/geonetwork/srv/eng/search#!22be4b55-2465-4320-e053-10a3070a5236'},
{'product_id': 'COPERNICUS/S2',
'description': 'Sentinel-2 MSI: MultiSpectral Instrument, Level-1C',
'source': 'European Union/ESA/Copernicus, https://sentinel.esa.int/web/sentinel/user-guides/sentinel-2-msi',
'time': {'from': '2015-06-23', 'to': '2018-06-27'},
'bands': [{'band_id': 'B1'},
{'band_id': 'B2'},
{'band_id': 'B3'},
{'band_id': 'B4'},
{'band_id': 'B5'},
{'band_id': 'B6'},
{'band_id': 'B7'},
{'band_id': 'B8'},
{'band_id': 'B8A'},
{'band_id': 'B9'},
{'band_id': 'B10'},
{'band_id': 'B11'},
{'band_id': 'B12'},
{'band_id': 'QA10'},
{'band_id': 'QA20'},
{'band_id': 'QA60'}],
'extent': {'srs': 'EPSG:4326',
'left': -180,
'right': 180,
'bottom': -90,
'top': 90}}]

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

def match_process_graph(self, request):

assert request.json() == PROCESSES
return True

def test_user_upload_file(self, m):
upload_url = "{}/users/{}/files/{}".format(self.endpoint, self.user_id,
self.upload_remote_fname)
Expand Down Expand Up @@ -129,13 +159,12 @@ def test_get_process(self, m):

def test_create_job(self, m):

# TODO: Add Test to check if post_data is sent properly
post_data = {}
post_data = PROCESSES
job_id = "MyId"
result = {"job_id": job_id}

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

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

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

assert resp is None

def test_image(self, m):

collection_org = COLLECTIONS[2]
collection_id = collection_org["product_id"]
collection_url = "{}/data/{}".format(self.endpoint, collection_id)
m.register_uri('GET', collection_url, json=collection_org)

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

resp = session.image(collection_id)

assert resp.bands == ['B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8',
'B8A', 'B9', 'B10', 'B11', 'B12', 'QA10', 'QA20', 'QA60']

def user_jobs(self, m):

collection_url = "{}/users/{}/jobs".format(self.endpoint, self.user_id)
m.register_uri('GET', collection_url, json=PROCESSES)

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

resp = session.user_jobs()

assert resp == PROCESSES

0 comments on commit 16e3842

Please sign in to comment.