diff --git a/openeo/capabilities.py b/openeo/capabilities.py index 2d1d81c4e..8e4ea921f 100644 --- a/openeo/capabilities.py +++ b/openeo/capabilities.py @@ -21,9 +21,12 @@ def api_version(self): return @property - def api_version_check(self): + def api_version_check(self) -> 'ComparableVersion': """Helper to easily check if the API version is at least or below some threshold version.""" - return ComparableVersion(self.api_version()) + api_version = self.api_version() + if not api_version: + raise ApiVersionException("No API version found") + return ComparableVersion(api_version) def list_features(self): """ List all supported features / endpoints.""" diff --git a/openeo/rest/connection.py b/openeo/rest/connection.py index 9ac138e94..c576c0b07 100644 --- a/openeo/rest/connection.py +++ b/openeo/rest/connection.py @@ -14,7 +14,7 @@ from requests.auth import HTTPBasicAuth, AuthBase import openeo -from openeo.capabilities import Capabilities +from openeo.capabilities import Capabilities, ApiVersionException, ComparableVersion from openeo.imagecollection import CollectionMetadata from openeo.rest.auth.auth import NullAuth, BearerAuth from openeo.rest.imagecollectionclient import ImageCollectionClient @@ -153,6 +153,8 @@ class Connection(RestApiConnection): Connection to an openEO backend. """ + _MINIMUM_API_VERSION = ComparableVersion("0.4.0") + def __init__(self, url, auth: AuthBase = None, session: requests.Session = None): """ Constructor of Connection, authenticates user. @@ -161,6 +163,12 @@ def __init__(self, url, auth: AuthBase = None, session: requests.Session = None) super().__init__(root_url=url, auth=auth, session=session) self._cached_capabilities = None + # Initial API version check. + if self._api_version.below(self._MINIMUM_API_VERSION): + raise ApiVersionException("OpenEO API version should be at least {m!s}, but got {v!s}".format( + m=self._MINIMUM_API_VERSION, v= self._api_version) + ) + def authenticate_basic(self, username: str, password: str) -> 'Connection': """ Authenticate a user to the backend using basic username and password. @@ -227,8 +235,7 @@ def list_collection_ids(self) -> List[str]: Get list of all collection ids :return: list of collection ids """ - field = 'id' if self._api_version.at_least('0.4.0') else 'name' - return [collection[field] for collection in self.list_collections() if field in collection] + return [collection['id'] for collection in self.list_collections() if 'id' in collection] def capabilities(self) -> 'Capabilities': """ @@ -304,7 +311,7 @@ def list_processgraphs(self, process_graph): raise NotImplementedError() @property - def _api_version(self): + def _api_version(self) -> ComparableVersion: return self.capabilities().api_version_check def load_collection(self, collection_id: str, **kwargs) -> ImageCollectionClient: @@ -365,7 +372,7 @@ def create_file(self, path): raise NotImplementedError() # TODO: Maybe rename to execute and merge with execute(). - def download(self, graph, outputfile, format_options): + def download(self, graph, outputfile): """ Downloads the result of a process graph synchronously, and save the result to the given file. This method is useful to export binary content such as images. For json content, the execute method is recommended. @@ -375,16 +382,8 @@ def download(self, graph, outputfile, format_options): :param format_options: formating options :return: job_id: String """ - path = "/preview" - request = { - "process_graph": graph - } - if self._api_version.at_least('0.4.0'): - path = "/result" - else: - request["output"] = format_options - - download_url = self.build_url(path) + request = {"process_graph": graph} + download_url = self.build_url("/result") r = self.post(download_url, json=request, stream=True, timeout=1000) with pathlib.Path(outputfile).open(mode="wb") as f: shutil.copyfileobj(r.raw, f) @@ -399,11 +398,7 @@ def execute(self, process_graph, output_format, output_parameters=None, budget=N :return: job_id: String """ # TODO: add output_format to execution - path = "/preview" - if self._api_version.at_least('0.4.0'): - path = "/result" - response = self.post(path, process_graph) - return self.parse_json_response(response) + return self.post(path="/result", json=process_graph).json() def create_job(self, process_graph:Dict, output_format:str=None, output_parameters:Dict={}, title:str=None, description:str=None, plan:str=None, budget=None, @@ -427,16 +422,9 @@ def create_job(self, process_graph:Dict, output_format:str=None, output_paramete "budget": budget } - if not self._api_version.at_least('0.4.0'): - process_graph["output"] = { - "format": output_format, - "parameters": output_parameters - } - job_status = self.post("/jobs", process_graph) job = None - if job_status.status_code == 201: job_info = job_status.headers._store if "openeo-identifier" in job_info: @@ -456,6 +444,7 @@ def parse_json_response(self, response: requests.Response): :param response: Response of a RESTful request :return: response: JSON Response """ + # TODO Deprecated: status handling is now in RestApiConnection if response.status_code == 200 or response.status_code == 201: return response.json() else: diff --git a/openeo/rest/imagecollectionclient.py b/openeo/rest/imagecollectionclient.py index 3e4ace6f5..e802d4364 100644 --- a/openeo/rest/imagecollectionclient.py +++ b/openeo/rest/imagecollectionclient.py @@ -52,7 +52,6 @@ def load_collection( :return: """ # TODO: rename function to load_collection for better similarity with corresponding process id? - assert session.capabilities().api_version_check.at_least('0.4.0') builder = GraphBuilder() process_id = 'load_collection' arguments = { @@ -82,8 +81,6 @@ def load_disk_collection(cls, session: 'Connection', file_format: str, glob_patt :param options: options specific to the file format :return: the data as an ImageCollection """ - assert session.capabilities().api_version_check.at_least('0.4.0') - builder = GraphBuilder() process_id = 'load_disk_data' @@ -968,10 +965,10 @@ def download(self, outputfile: str, **format_options) -> str: raise ValueError("Please use the 'format' keyword argument to specify the output format. Use openeo.connection.Connection#list_file_types to retrieve available ouput formats for this backend.") newcollection = self.graph_add_process("save_result",args) newcollection.graph[newcollection.node_id]["result"] = True - return self.session.download(newcollection.graph, outputfile, format_options) + return self.session.download(newcollection.graph, outputfile) else: self.graph[self.node_id]["result"] = True - return self.session.download(self.graph, outputfile, format_options) + return self.session.download(self.graph, outputfile) def tiled_viewing_service(self,**kwargs) -> Dict: newbuilder = self.builder.copy() diff --git a/tests/rest/test_connection.py b/tests/rest/test_connection.py index f70165a3a..c216ef4ab 100644 --- a/tests/rest/test_connection.py +++ b/tests/rest/test_connection.py @@ -52,9 +52,9 @@ def test_connection_with_session(): session = mock.Mock() response = session.request.return_value response.status_code = 200 - response.json.return_value = {"foo": "bar"} + response.json.return_value = {"foo": "bar", "api_version": "0.4.0"} conn = Connection("https://oeo.net/", session=session) - assert conn.capabilities().capabilities == {"foo": "bar"} + assert conn.capabilities().capabilities["foo"] == "bar" session.request.assert_any_call( url="https://oeo.net/", method="get", headers=mock.ANY, stream=mock.ANY, auth=mock.ANY ) @@ -64,15 +64,16 @@ def test_connect_with_session(): session = mock.Mock() response = session.request.return_value response.status_code = 200 - response.json.return_value = {"foo": "bar"} + response.json.return_value = {"foo": "bar", "api_version": "0.4.0"} conn = connect("https://oeo.net/", session=session) - assert conn.capabilities().capabilities == {"foo": "bar"} + assert conn.capabilities().capabilities["foo"] == "bar" session.request.assert_any_call( url="https://oeo.net/", method="get", headers=mock.ANY, stream=mock.ANY, auth=mock.ANY ) def test_api_error(requests_mock): + requests_mock.get('https://oeo.net/', json={"api_version": "0.4.0"}) conn = Connection(API_URL) requests_mock.get('https://oeo.net/collections/foobar', status_code=404, json={ "code": "CollectionNotFound", "message": "No such things as a collection 'foobar'", "id": "54321" @@ -88,6 +89,7 @@ def test_api_error(requests_mock): def test_api_error_non_json(requests_mock): + requests_mock.get('https://oeo.net/', json={"api_version": "0.4.0"}) conn = Connection(API_URL) requests_mock.get('https://oeo.net/collections/foobar', status_code=500, text="olapola") with pytest.raises(OpenEoApiError) as exc_info: @@ -101,13 +103,14 @@ def test_api_error_non_json(requests_mock): def test_authenticate_basic(requests_mock): + requests_mock.get(API_URL, json={"api_version": "0.4.0"}) conn = Connection(API_URL) def text_callback(request, context): assert request.headers["Authorization"] == "Basic am9objpqMGhu" return '{"access_token":"w3lc0m3"}' - requests_mock.get('https://oeo.net/credentials/basic', text=text_callback) + requests_mock.get(API_URL + 'credentials/basic', text=text_callback) assert isinstance(conn.auth, NullAuth) conn.authenticate_basic(username="john", password="j0hn") @@ -115,11 +118,12 @@ def text_callback(request, context): assert conn.auth.bearer == "w3lc0m3" -def test_authenticate_oidc(oidc_test_setup): +def test_authenticate_oidc(oidc_test_setup, requests_mock): # see test/rest/conftest.py for `oidc_test_setup` fixture client_id = "myclient" oidc_discovery_url = "https://oeo.net/credentials/oidc" state, webbrowser_open = oidc_test_setup(client_id=client_id, oidc_discovery_url=oidc_discovery_url) + requests_mock.get(API_URL, json={"api_version": "0.4.0"}) # With all this set up, kick off the openid connect flow conn = Connection(API_URL) @@ -130,8 +134,8 @@ def test_authenticate_oidc(oidc_test_setup): def test_load_collection_arguments(requests_mock): + requests_mock.get(API_URL, json={"api_version": "0.4.0"}) conn = Connection(API_URL) - requests_mock.get(API_URL, json={"version": "0.4.0"}) requests_mock.get(API_URL + "collections/FOO", json={ "properties": {"eo:bands": [{"name": "red"}, {"name": "green"}, {"name": "blue"}]} }) diff --git a/tests/rest/test_imagecollectionclient.py b/tests/rest/test_imagecollectionclient.py index 99a82d6f6..3281b71d9 100644 --- a/tests/rest/test_imagecollectionclient.py +++ b/tests/rest/test_imagecollectionclient.py @@ -12,8 +12,8 @@ @pytest.fixture def session040(requests_mock): + requests_mock.get(API_URL + "/", json={"api_version": "0.4.0"}) session = openeo.connect(API_URL) - requests_mock.get(API_URL + "/", json={"version": "0.4.0"}) return session diff --git a/tests/test_bandmath.py b/tests/test_bandmath.py index 2d954a194..4fe7ea8cc 100644 --- a/tests/test_bandmath.py +++ b/tests/test_bandmath.py @@ -12,11 +12,11 @@ class TestBandMath(TestCase): def test_basic(self, m): + m.get("http://localhost:8000/api/", json={"api_version": "0.4.0"}) session = openeo.connect("http://localhost:8000/api") session.post = MagicMock() session.download = MagicMock() - m.get("http://localhost:8000/api/", json={"version": "0.4.0"}) m.get("http://localhost:8000/api/collections/SENTINEL2_RADIOMETRY_10M", json={"product_id": "sentinel2_subset", "bands": [{'band_id': 'B02'}, {'band_id': 'B04'}, @@ -32,11 +32,11 @@ def test_basic(self, m): assert cube.band('B02').graph == expected_graph def test_band_indexing(self, m): + m.get("http://localhost:8000/api/", json={"api_version": "0.4.0"}) session = openeo.connect("http://localhost:8000/api") session.post = MagicMock() session.download = MagicMock() - m.get("http://localhost:8000/api/", json={"version": "0.4.0"}) m.get("http://localhost:8000/api/collections/CGS_SENTINEL2_RADIOMETRY_V102_001", json={ "id": "CGS_SENTINEL2_RADIOMETRY_V102_001", "properties": { @@ -58,11 +58,11 @@ def test_band_indexing(self, m): def test_evi(self,m): # configuration phase: define username, endpoint, parameters? + m.get("http://localhost:8000/api/", json={"api_version": "0.4.0"}) session = openeo.connect("http://localhost:8000/api") session.post = MagicMock() session.download = MagicMock() - m.get("http://localhost:8000/api/", json={"version": "0.4.0"}) m.get("http://localhost:8000/api/collections", json={"collections": [{"product_id": "sentinel2_subset"}]}) m.get("http://localhost:8000/api/collections/SENTINEL2_RADIOMETRY_10M", json={"product_id": "sentinel2_subset", "bands": [{'band_id': 'B02'}, @@ -94,11 +94,11 @@ def test_evi(self,m): def test_ndvi_udf(self, m): #configuration phase: define username, endpoint, parameters? + m.get("http://localhost:8000/api/", json={"version": "0.4.1"}) session = openeo.connect("http://localhost:8000/api") session.post = MagicMock() session.download = MagicMock() - m.get("http://localhost:8000/api/", json={"version": "0.4.1"}) m.get("http://localhost:8000/api/collections", json={"collections": [{"product_id": "sentinel2_subset"}]}) m.get("http://localhost:8000/api/collections/SENTINEL2_RADIOMETRY_10M", json={"product_id": "sentinel2_subset", "bands": [{'band_id': 'B0'}, @@ -154,9 +154,9 @@ def test_ndvi_udf(self, m): def test_ndvi_udf_0_4_0(self, m): #configuration phase: define username, endpoint, parameters? + m.get("http://localhost:8000/api/", json={"api_version": "0.4.0"}) session = openeo.connect("http://localhost:8000/api") - m.get("http://localhost:8000/api/", json={"version": "0.4.0"}) m.get("http://localhost:8000/api/collections", json={"collections": [{"product_id": "sentinel2_subset"}]}) m.get("http://localhost:8000/api/collections/SENTINEL2_RADIOMETRY_10M", json={"product_id": "sentinel2_subset", "bands": [{'band_id': 'B0'}, diff --git a/tests/test_batch_jobs.py b/tests/test_batch_jobs.py index 76723df24..7c2aded79 100644 --- a/tests/test_batch_jobs.py +++ b/tests/test_batch_jobs.py @@ -13,11 +13,11 @@ class TestBatchJobs(TestCase): def test_create_job(self,m): + m.get("http://localhost:8000/api/", json={"api_version": "0.4.0"}) session = openeo.connect("http://localhost:8000/api") #session.post = MagicMock() session.download = MagicMock() - m.get("http://localhost:8000/api/", json={"version": "0.4.0"}) m.get("http://localhost:8000/api/collections", json={"collections": [{"product_id": "sentinel2_subset"}]}) m.get("http://localhost:8000/api/collections/SENTINEL2_RADIOMETRY_10M", json={"product_id": "sentinel2_subset", "bands": [{'band_id': 'B02'}, diff --git a/tests/test_capabilities.py b/tests/test_capabilities.py index ac7118048..155bbeaa6 100644 --- a/tests/test_capabilities.py +++ b/tests/test_capabilities.py @@ -43,4 +43,3 @@ def test_checkable_version(): assert v.above(ComparableVersion('1.2')) assert v.at_least(ComparableVersion('1.2.3a')) is False assert v.at_most(ComparableVersion('1.02.03')) - diff --git a/tests/test_logical_operators.py b/tests/test_logical_operators.py index a4dc026c2..40cb3a9f4 100644 --- a/tests/test_logical_operators.py +++ b/tests/test_logical_operators.py @@ -12,11 +12,11 @@ class TestLogicalOps(TestCase): def test_not_equal(self, m): # configuration phase: define username, endpoint, parameters? + m.get("http://localhost:8000/api/", json={"api_version": "0.4.0"}) session = openeo.connect("http://localhost:8000/api") session.post = MagicMock() session.download = MagicMock() - m.get("http://localhost:8000/api/", json={"version": "0.4.0"}) m.get("http://localhost:8000/api/collections", json={"collections": [{"product_id": "sentinel2_subset"}]}) m.get("http://localhost:8000/api/collections/SENTINEL2_SCF", json={ "product_id": "sentinel2_subset", @@ -42,11 +42,11 @@ def test_not_equal(self, m): assert actual_graph == expected_graph def test_or(self, m): + m.get("http://localhost:8000/api/", json={"api_version": "0.4.0"}) session = openeo.connect("http://localhost:8000/api") session.post = MagicMock() session.download = MagicMock() - m.get("http://localhost:8000/api/", json={"version": "0.4.0"}) m.get("http://localhost:8000/api/collections", json={"collections": [{"product_id": "sentinel2_subset"}]}) m.get("http://localhost:8000/api/collections/SENTINEL2_SCF", json={ "product_id": "sentinel2_subset", @@ -65,11 +65,11 @@ def test_or(self, m): assert actual_graph == expected_graph def test_and(self, m): + m.get("http://localhost:8000/api/", json={"api_version": "0.4.0"}) session = openeo.connect("http://localhost:8000/api") session.post = MagicMock() session.download = MagicMock() - m.get("http://localhost:8000/api/", json={"version": "0.4.0"}) m.get("http://localhost:8000/api/collections", json={"collections": [{"product_id": "sentinel2_subset"}]}) m.get("http://localhost:8000/api/collections/SENTINEL2_SCF", json={ "product_id": "sentinel2_subset", diff --git a/tests/test_rest_session.py b/tests/test_rest_session.py index 5eb4b5eac..1ea780042 100644 --- a/tests/test_rest_session.py +++ b/tests/test_rest_session.py @@ -1,18 +1,18 @@ # -*- coding: utf-8 -*- - -import openeo +import json +import os +import tempfile import unittest from unittest import TestCase -import tempfile -import os -import json +import pytest import requests_mock -# MockUp Testdata +import openeo +from openeo.capabilities import ApiVersionException -CAPABILITIES = ['/capabilities', '/capabilities/services', '/capabilities/output_formats', '/data', - '/data/{product_id}', '/processes'] + +# MockUp Testdata COLLECTIONS = [{'product_id': 'ASTER/AST_L1T_003', 'description': 'ASTER L1T Radiance', 'source': 'NASA LP DAAC at the USGS EROS Center, https://lpdaac.usgs.gov/dataset_discovery/aster/aster_products_table/ast_l1t'}, @@ -119,26 +119,39 @@ def test_user_delete_file(self, m): assert status def test_list_capabilities(self, m): - capabilties_url = "{}/".format(self.endpoint) - m.register_uri('GET', capabilties_url, json=CAPABILITIES) + capabilities = { + "api_version": "0.4.0", + "endpoints": [ + {"path": "/collections", "methods": ["GET"]}, + ] + } + m.get("{}/".format(self.endpoint), json=capabilities) con = openeo.connect(self.endpoint) + res = con.capabilities() + assert res.capabilities == capabilities - capabilities = con.capabilities() - assert capabilities.capabilities == CAPABILITIES + def test_capabilities_api_version_too_old(self, m): + m.register_uri('GET', "{}/".format(self.endpoint), json={'version': '0.3.1'}) + with pytest.raises(ApiVersionException): + openeo.connect(self.endpoint) - def test_capabilities_api_version(self, m): - capabilties_url = "{}/".format(self.endpoint) - # Old-style api - m.register_uri('GET', capabilties_url, json={'version': '0.3.1'}) - capabilities = openeo.connect(self.endpoint).capabilities() - assert capabilities.version() == '0.3.1' - assert capabilities.api_version() == '0.3.1' - # 0.4.0 style api - m.register_uri('GET', capabilties_url, json={'api_version': '0.4.0'}) + def test_capabilities_api_version_too_old2(self, m): + m.register_uri('GET', "{}/".format(self.endpoint), json={'api_version': '0.3.1'}) + with pytest.raises(ApiVersionException): + openeo.connect(self.endpoint) + + def test_capabilities_api_version_recent(self, m): + m.register_uri('GET', "{}/".format(self.endpoint), json={'version': '0.4.0'}) capabilities = openeo.connect(self.endpoint).capabilities() assert capabilities.version() == '0.4.0' assert capabilities.api_version() == '0.4.0' + def test_capabilities_api_version_recent2(self, m): + m.register_uri('GET', "{}/".format(self.endpoint), json={'api_version': '0.4.1'}) + capabilities = openeo.connect(self.endpoint).capabilities() + assert capabilities.version() == '0.4.1' + assert capabilities.api_version() == '0.4.1' + def test_capabilities_api_version_check(self, m): capabilties_url = "{}/".format(self.endpoint) m.register_uri('GET', capabilties_url, json={'api_version': '1.2.3'}) @@ -154,28 +167,31 @@ def test_capabilities_api_version_check(self, m): assert capabilities.api_version_check.above('1.2.2') def test_list_collections(self, m): - collection_url = "{}/collections".format(self.endpoint) - m.register_uri('GET', collection_url, json={'collections': COLLECTIONS}) + m.get("http://localhost:8000/api/", json={"api_version": "0.4.0"}) con = openeo.connect(self.endpoint) + collection_url = "{}/collections".format(self.endpoint) + m.register_uri('GET', collection_url, json={'collections': COLLECTIONS}) collections = con.list_collections() assert collections == COLLECTIONS def test_get_collection(self, m): + m.get("http://localhost:8000/api/", json={"api_version": "0.4.0"}) + con = openeo.connect(self.endpoint) + collection_org = COLLECTIONS[0] collection_id = collection_org["product_id"] collection_url = "{}/collections/{}".format(self.endpoint, collection_id) m.register_uri('GET', collection_url, json=collection_org) - con = openeo.connect(self.endpoint) - collection = con.describe_collection(collection_id) assert collection == collection_org def test_get_all_processes(self, m): - processes_url = "{}/processes".format(self.endpoint) - m.register_uri('GET', processes_url, json={"processes": PROCESSES}) + m.get("http://localhost:8000/api/", json={"api_version": "0.4.0"}) con = openeo.connect(self.endpoint) + processes_url = "{}/processes".format(self.endpoint) + m.register_uri('GET', processes_url, json={"processes": PROCESSES}) processes = con.list_processes() assert processes == PROCESSES diff --git a/tests/test_temporal_ops.py b/tests/test_temporal_ops.py index c8a134b0b..39144e599 100644 --- a/tests/test_temporal_ops.py +++ b/tests/test_temporal_ops.py @@ -11,11 +11,11 @@ class TestTemporal(TestCase): def test_apply_dimension_temporal_cumsum(self,m): + m.get("http://localhost:8000/api/", json={"version": "0.4.0"}) session = openeo.connect("http://localhost:8000/api") session.post = MagicMock() session.download = MagicMock() - m.get("http://localhost:8000/api/", json={"version": "0.4.0"}) m.get("http://localhost:8000/api/collections", json={"collections": [{"product_id": "sentinel2_subset"}]}) m.get("http://localhost:8000/api/collections/SENTINEL2_RADIOMETRY_10M", json={"product_id": "sentinel2_subset", "bands": [{'band_id': 'B02'}, diff --git a/tests/test_usecase1.py b/tests/test_usecase1.py index acd9c1df7..2d3e1ec1a 100644 --- a/tests/test_usecase1.py +++ b/tests/test_usecase1.py @@ -25,11 +25,13 @@ def setUp(self): self.output_file = "/tmp/test.gtiff" def test_user_login(self, m): + m.get("http://localhost:8000/api/", json={"api_version": "0.4.0"}) m.get("http://localhost:8000/api/credentials/basic", json={"access_token": "blabla"}) con = openeo.connect(self.endpoint).authenticate_basic(username=self.auth_id, password=self.auth_pwd) assert isinstance(con.auth, BearerAuth) def test_viewing_userjobs(self, m): + m.get("http://localhost:8000/api/", json={"api_version": "0.4.0"}) m.get("http://localhost:8000/api/credentials/basic", json={"access_token": "blabla"}) m.get("http://localhost:8000/api/jobs", json={"jobs": [{"job_id": "748df7caa8c84a7ff6e"}]}) con = openeo.connect(self.endpoint).authenticate_basic(username=self.auth_id, password=self.auth_pwd) @@ -37,6 +39,7 @@ def test_viewing_userjobs(self, m): self.assertGreater(len(userjobs), 0) def test_viewing_data(self, m): + m.get("http://localhost:8000/api/", json={"api_version": "0.4.0"}) m.get("http://localhost:8000/api/collections", json={"collections": [{"product_id": "sentinel2_subset"}]}) m.get("http://localhost:8000/api/collections/sentinel2_subset", json={"product_id": "sentinel2_subset"}) @@ -50,15 +53,15 @@ def test_viewing_data(self, m): self.assertEqual(data_info["product_id"], self.data_id) def test_viewing_processes(self, m): - m.get("http://localhost:8000/api/processes", json={"processes": [{"process_id": "calculate_ndvi"}]}) - + m.get("http://localhost:8000/api/", json={"api_version": "0.4.0"}) con = openeo.connect(self.endpoint) - processes = con.list_processes() - self.assertGreater(str(processes).find(self.process_id), -1) + m.get("http://localhost:8000/api/processes", json={"processes": [{"process_id": "calculate_ndvi"}]}) + processes = con.list_processes() + assert self.process_id in set(p["process_id"] for p in processes) def test_job_creation(self, m): - m.get("http://localhost:8000/api/", json={"version": "0.4.0"}) + m.get("http://localhost:8000/api/", json={"api_version": "0.4.0"}) m.get("http://localhost:8000/api/credentials/basic", json={"access_token": "blabla"}) m.post("http://localhost:8000/api/jobs", status_code=201,headers={"OpenEO-Identifier": "748df7caa8c84a7ff6e"}) diff --git a/tests/test_zonal_stats.py b/tests/test_zonal_stats.py index 7a008ab64..391ff001b 100644 --- a/tests/test_zonal_stats.py +++ b/tests/test_zonal_stats.py @@ -12,11 +12,11 @@ class TestTimeSeries(TestCase): def test_polygon_timeseries(self, m): #configuration phase: define username, endpoint, parameters? + m.get("http://localhost:8000/api/", json={"api_version": "0.4.0"}) session = openeo.connect(url="http://localhost:8000/api") #session.post = MagicMock() #session.download = MagicMock() - m.get("http://localhost:8000/api/", json={"version": "0.4.0"}) m.get("http://localhost:8000/api/collections", json=[{"product_id": "sentinel2_subset"}]) m.get("http://localhost:8000/api/collections/SENTINEL2_FAPAR", json={"product_id": "sentinel2_subset", "bands": [{'band_id': 'FAPAR'}], @@ -44,9 +44,9 @@ def check_process_graph(request): #How to define a point? Ideally it should also have the CRS? def test_polygon_timeseries_from_vector_file(self, m): + m.get("http://localhost:8000/api/", json={"api_version": "0.4.0"}) session = openeo.connect(url="http://localhost:8000/api") - m.get("http://localhost:8000/api/", json={"version": "0.4.0"}) m.get("http://localhost:8000/api/collections/SENTINEL2_FAPAR", json={ "product_id": "SENTINEL2_FAPAR" })