-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add skeleton for integration tests
Issue #63
- Loading branch information
1 parent
d86b02e
commit e6046a6
Showing
3 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |