diff --git a/integration-tests/conftest.py b/integration-tests/conftest.py new file mode 100644 index 00000000..5d115735 --- /dev/null +++ b/integration-tests/conftest.py @@ -0,0 +1,66 @@ +import os + +import openeo +import pytest +import requests +from openeo.capabilities import ComparableVersion + + +def get_openeo_base_url(version: str = "1.1.0"): + try: + endpoint = os.environ["ENDPOINT"].rstrip("/") + except Exception: + raise RuntimeError( + "Environment variable 'ENDPOINT' should be set" + " with URL pointing to OpenEO backend to test against" + " (e.g. 'http://localhost:8080/' or 'http://openeo-dev.vgt.vito.be/')" + ) + return "{e}/openeo/{v}".format(e=endpoint.rstrip("/"), v=version) + + +@pytest.fixture( + params=[ + "1.1.0", + ] +) +def api_version(request) -> ComparableVersion: + return ComparableVersion(request.param) + + +@pytest.fixture +def api_base_url(api_version): + return get_openeo_base_url(str(api_version)) + + +@pytest.fixture +def requests_session(request) -> requests.Session: + """ + Fixture to create a `requests.Session` that automatically injects a query parameter in API URLs + referencing the currently running test. + Simplifies cross-referencing between integration tests and flask/YARN logs + """ + session = requests.Session() + session.params["_origin"] = f"{request.session.name}/{request.node.name}" + return session + + +@pytest.fixture +def connection(api_base_url, requests_session) -> openeo.Connection: + return openeo.connect(api_base_url, session=requests_session) + + +@pytest.fixture +def connection100(requests_session) -> openeo.Connection: + return openeo.connect(get_openeo_base_url("1.0.0"), session=requests_session) + + +# TODO: real authentication? +TEST_USER = "jenkins" +TEST_PASSWORD = TEST_USER + "123" + + +@pytest.fixture +def auth_connection(connection) -> openeo.Connection: + """Connection fixture to a backend of given version with some image collections.""" + connection.authenticate_basic(TEST_USER, TEST_PASSWORD) + return connection diff --git a/integration-tests/test_integration.py b/integration-tests/test_integration.py new file mode 100644 index 00000000..2c7e132f --- /dev/null +++ b/integration-tests/test_integration.py @@ -0,0 +1,50 @@ +import logging + +import openeo +import pytest + +_log = logging.getLogger(__name__) + + +def test_openeo_cloud_root_return_sensible_response(connection: openeo.Connection): + """Check that ${ENDPOINT}/openeo/1.0/ returns something sensible.""" + path = "/" + response = connection.get(path) + + _log.info("As curl:\n" + connection.as_curl(data={}, path=path, method="GET")) + _log.info(f"{response=}") + _log.info(f"{response.json()=}") + + response_body = response.json() + assert response.status_code == 200 + + required_keys = [ + "api_version", + "backend_version", + "billing", + "description", + "endpoints", + "federation", + "id", + "links", + "processing:software", + "production", + "stac_extensions", + "stac_version", + "title", + "version", + ] + actual_keys_in_response = response_body.keys() + assert all([k in actual_keys_in_response for k in required_keys]) + + +@pytest.mark.xfail(reason="Not implemented yet") +def test_collections(): + """Does /collections look ok?""" + assert False + + +@pytest.mark.xfail(reason="Not implemented yet") +def test_processes(): + """Does /processes look ok?""" + assert False diff --git a/scripts/run-integration-tests.sh b/scripts/run-integration-tests.sh new file mode 100755 index 00000000..4fa8401e --- /dev/null +++ b/scripts/run-integration-tests.sh @@ -0,0 +1,2 @@ +export ENDPOINT=https://openeocloud.vito.be +pytest -ra -vv integration-tests/