Skip to content

Commit

Permalink
test: Add skeleton for integration tests
Browse files Browse the repository at this point in the history
Issue #63
  • Loading branch information
JohanKJSchreurs committed Apr 7, 2023
1 parent d86b02e commit e6046a6
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 0 deletions.
66 changes: 66 additions & 0 deletions integration-tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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
50 changes: 50 additions & 0 deletions integration-tests/test_integration.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions scripts/run-integration-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export ENDPOINT=https://openeocloud.vito.be
pytest -ra -vv integration-tests/

0 comments on commit e6046a6

Please sign in to comment.