Skip to content

Commit

Permalink
fixup! fixup! Issue #112 Eliminate unused AggregatorConfig arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
soxofaan committed Mar 1, 2024
1 parent bc62765 commit 317c58f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 41 deletions.
8 changes: 2 additions & 6 deletions src/openeo_aggregator/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import logging
import os
from pathlib import Path
from typing import Any, List, Optional, Union
from typing import List, Optional, Union

import flask
import openeo_driver.views
from openeo_driver.config.load import ConfigGetter
from openeo_driver.util.logging import (
LOG_HANDLER_STDERR_JSON,
LOGGING_CONTEXT_FLASK,
Expand All @@ -22,12 +21,11 @@
AggregatorBackendImplementation,
MultiBackendConnection,
)
from openeo_aggregator.config import AggregatorConfig, get_config, get_config_dir

_log = logging.getLogger(__name__)


def create_app(config: Any = None, auto_logging_setup: bool = True, flask_error_handling: bool = True) -> flask.Flask:
def create_app(auto_logging_setup: bool = True, flask_error_handling: bool = True) -> flask.Flask:
"""
Flask application factory function.
"""
Expand All @@ -39,8 +37,6 @@ def create_app(config: Any = None, auto_logging_setup: bool = True, flask_error_

log_version_info(logger=_log)

config: AggregatorConfig = get_config(config)
_log.info(f"Using config: {config.config_source=!r}")

backends = MultiBackendConnection.from_config()

Expand Down
13 changes: 5 additions & 8 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import os
from pathlib import Path
from typing import List

import flask
import pytest
from openeo_driver.testing import ApiTester
from openeo_driver.users.oidc import OidcProvider

from openeo_aggregator.app import create_app
from openeo_aggregator.backend import (
Expand Down Expand Up @@ -107,9 +105,8 @@ def multi_backend_connection(backend1, backend2) -> MultiBackendConnection:
return MultiBackendConnection.from_config()


def get_flask_app(config: AggregatorConfig) -> flask.Flask:
def get_flask_app() -> flask.Flask:
app = create_app(
config=config,
auto_logging_setup=False,
# flask_error_handling=False, # Failing test debug tip: set to False for deeper stack trace insights
)
Expand All @@ -119,8 +116,8 @@ def get_flask_app(config: AggregatorConfig) -> flask.Flask:


@pytest.fixture
def flask_app(config: AggregatorConfig) -> flask.Flask:
app = get_flask_app(config)
def flask_app(backend1, backend2) -> flask.Flask:
app = get_flask_app()
with app.app_context():
yield app

Expand All @@ -141,11 +138,11 @@ def api100(flask_app: flask.Flask) -> ApiTester:


@pytest.fixture
def api100_with_entitlement_check(config: AggregatorConfig) -> ApiTester:
def api100_with_entitlement_check() -> ApiTester:
with config_overrides(
auth_entitlement_check={"oidc_issuer_whitelist": {"https://egi.test", "https://egi.test/oidc"}}
):
yield get_api100(get_flask_app(config))
yield get_api100(get_flask_app())


def assert_dict_subset(d1: dict, d2: dict):
Expand Down
19 changes: 11 additions & 8 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@
from .conftest import get_api100, get_flask_app


def test_create_app(config: AggregatorConfig):
app = create_app(config)
def test_create_app():
app = create_app()
assert isinstance(app, flask.Flask)


@pytest.mark.parametrize(["partitioned_job_tracking", "expected"], [
(None, False),
({"zk_client": "dummy"}, True),
])
def test_create_app_no_partitioned_job_tracking(config: AggregatorConfig, partitioned_job_tracking, expected):
@pytest.mark.parametrize(
["partitioned_job_tracking", "expected"],
[
(None, False),
({"zk_client": "dummy"}, True),
],
)
def test_create_app_no_partitioned_job_tracking(partitioned_job_tracking, expected):
with config_overrides(partitioned_job_tracking=partitioned_job_tracking):
api100 = get_api100(get_flask_app(config))
api100 = get_api100(get_flask_app())
res = api100.get("/").assert_status_code(200).json
assert res["_partitioned_job_tracking"] is expected
32 changes: 13 additions & 19 deletions tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import logging
import re
import time
from typing import List, Tuple

import openeo_driver.config.load
import pytest
import requests
from openeo.rest import OpenEoApiError, OpenEoRestError
from openeo.rest.connection import url_join
from openeo.util import ContextTimer, rfc3339
from openeo.util import rfc3339
from openeo_driver.backend import ServiceMetadata
from openeo_driver.errors import (
JobNotFinishedException,
Expand All @@ -28,7 +26,6 @@
from openeo_driver.users.oidc import OidcProvider

import openeo_aggregator.about
from openeo_aggregator.config import AggregatorConfig, get_config_dir
from openeo_aggregator.constants import JOB_OPTION_FORCE_BACKEND
from openeo_aggregator.metadata import (
STAC_PROPERTY_FEDERATION_BACKENDS,
Expand Down Expand Up @@ -484,10 +481,7 @@ def test_oidc_enrolled(self, api100_with_entitlement_check, requests_mock, edupe
(["https://egi.test/foo"], "https://egi.test/bar", False),
],
)
def test_issuer_url_normalization(
self, config, requests_mock, backend1, backend2, whitelist, oidc_issuer, success, caplog
):

def test_issuer_url_normalization(self, requests_mock, backend1, backend2, whitelist, oidc_issuer, success, caplog):
requests_mock.get(
backend1 + "/credentials/oidc", json={"providers": [{"id": "egi", "issuer": oidc_issuer, "title": "EGI"}]}
)
Expand All @@ -507,7 +501,7 @@ def test_issuer_url_normalization(
oidc_providers=[OidcProvider(id="egi", issuer=oidc_issuer, title="EGI")],
auth_entitlement_check={"oidc_issuer_whitelist": whitelist},
):
api100 = get_api100(get_flask_app(config))
api100 = get_api100(get_flask_app())

api100.set_auth_bearer_token(token="oidc/egi/funiculifunicula")

Expand Down Expand Up @@ -788,8 +782,8 @@ def test_result_basic_math_error(self, api100, requests_mock, backend1, backend2
res.assert_error(500, "Internal", message="Failed to process synchronously on backend b1")

@pytest.mark.parametrize(["chunk_size"], [(16,), (128,)])
def test_result_large_response_streaming(self, config, chunk_size, requests_mock, backend1, backend2):
api100 = get_api100(get_flask_app(config))
def test_result_large_response_streaming(self, chunk_size, requests_mock, backend1, backend2):
api100 = get_api100(get_flask_app())

def post_result(request: requests.Request, context):
assert request.headers["Authorization"] == TEST_USER_AUTH_HEADER["Authorization"]
Expand Down Expand Up @@ -1357,12 +1351,12 @@ def b2_get_jobs(request, context):
}

@pytest.mark.parametrize("b2_oidc_pid", ["egi", "aho"])
def test_list_jobs_oidc_pid_mapping(self, config, requests_mock, backend1, backend2, b2_oidc_pid):
def test_list_jobs_oidc_pid_mapping(self, requests_mock, backend1, backend2, b2_oidc_pid):
# Override /credentials/oidc of backend2 before building flask app and ApiTester
requests_mock.get(backend2 + "/credentials/oidc", json={"providers": [
{"id": b2_oidc_pid, "issuer": "https://egi.test", "title": "EGI"}
]})
api100 = get_api100(get_flask_app(config))
api100 = get_api100(get_flask_app())

# OIDC setup
def get_userinfo(request: requests.Request, context):
Expand Down Expand Up @@ -2752,13 +2746,13 @@ def broken_backend2(self, requests_mock) -> Tuple[str, "requests_mock.adapter._M
root_mock = requests_mock.get(backend2 + "/", status_code=500)
return backend2, root_mock

def test_startup_during_backend_downtime(self, config, backend1, broken_backend2, requests_mock, caplog):
def test_startup_during_backend_downtime(self, backend1, broken_backend2, requests_mock, caplog):
caplog.set_level(logging.WARNING)

# Initial backend setup with broken backend2
requests_mock.get(backend1 + "/health", text="OK")
backend2, b2_root = broken_backend2
api100 = get_api100(get_flask_app(config))
api100 = get_api100(get_flask_app())

api100.get("/").assert_status_code(200)

Expand All @@ -2770,11 +2764,11 @@ def test_startup_during_backend_downtime(self, config, backend1, broken_backend2
"status_code": 200,
}

def test_startup_during_backend_downtime_and_recover(self, config, backend1, broken_backend2, requests_mock):
def test_startup_during_backend_downtime_and_recover(self, backend1, broken_backend2, requests_mock):
# Initial backend setup with broken backend2
requests_mock.get(backend1 + "/health", text="OK")
backend2, b2_root = broken_backend2
api100 = get_api100(get_flask_app(config))
api100 = get_api100(get_flask_app())

assert api100.get("/health").assert_status_code(200).json["backend_status"] == {
"b1": {"status_code": 200, "text": "OK", "response_time": pytest.approx(0.1, abs=0.1)},
Expand All @@ -2798,10 +2792,10 @@ def test_startup_during_backend_downtime_and_recover(self, config, backend1, bro
}

@pytest.mark.parametrize("b2_oidc_provider_id", ["egi", "aho"])
def test_oidc_mapping_after_recover(self, config, backend1, broken_backend2, requests_mock, b2_oidc_provider_id):
def test_oidc_mapping_after_recover(self, backend1, broken_backend2, requests_mock, b2_oidc_provider_id):
# Initial backend setup with broken backend2
backend2, b2_root = broken_backend2
api100 = get_api100(get_flask_app(config))
api100 = get_api100(get_flask_app())

# OIDC setup
def get_userinfo(request: requests.Request, context):
Expand Down

0 comments on commit 317c58f

Please sign in to comment.