diff --git a/requirements-swh-server.txt b/requirements-swh-server.txt --- a/requirements-swh-server.txt +++ b/requirements-swh-server.txt @@ -1,4 +1,4 @@ -swh.core[http] +swh.core[http] >= 0.4 swh.loader.core >= 0.0.71 swh.scheduler >= 0.0.39 swh.model >= 0.3.8 diff --git a/requirements-swh.txt b/requirements-swh.txt --- a/requirements-swh.txt +++ b/requirements-swh.txt @@ -1 +1 @@ -swh.core[http] >= 0.3 +swh.core[http] >= 0.4 diff --git a/swh/deposit/client.py b/swh/deposit/client.py --- a/swh/deposit/client.py +++ b/swh/deposit/client.py @@ -17,7 +17,7 @@ import requests import xmltodict -from swh.core.config import config_basepath, read_raw_config +from swh.core.config import load_from_envvar logger = logging.getLogger(__name__) @@ -79,12 +79,7 @@ """ def __init__(self, config=None, _client=requests): - if config is None: - config_file = os.environ["SWH_CONFIG_FILENAME"] - self.config: Dict[str, Any] = read_raw_config(config_basepath(config_file)) - else: - self.config = config - + self.config: Dict[str, Any] = config or load_from_envvar() self._client = _client self.base_url = self.config["url"].strip("/") + "/" auth = self.config["auth"] diff --git a/swh/deposit/config.py b/swh/deposit/config.py --- a/swh/deposit/config.py +++ b/swh/deposit/config.py @@ -94,9 +94,7 @@ """ def __init__(self): - config_file = os.environ["SWH_CONFIG_FILENAME"] - conf = config.read_raw_config(config.config_basepath(config_file)) - self.config: Dict[str, Any] = config.merge_configs(DEFAULT_CONFIG, conf) + self.config: Dict[str, Any] = config.load_from_envvar(DEFAULT_CONFIG) self.scheduler: SchedulerInterface = get_scheduler(**self.config["scheduler"]) self.tool = { "name": "swh-deposit", diff --git a/swh/deposit/loader/checker.py b/swh/deposit/loader/checker.py --- a/swh/deposit/loader/checker.py +++ b/swh/deposit/loader/checker.py @@ -4,7 +4,6 @@ # See top-level LICENSE file for more information import logging -import os from typing import Any, Dict from swh.core import config @@ -21,10 +20,7 @@ """ def __init__(self): - config_file = os.environ["SWH_CONFIG_FILENAME"] - self.config: Dict[str, Any] = config.read_raw_config( - config.config_basepath(config_file) - ) + self.config: Dict[str, Any] = config.load_from_envvar() self.client = PrivateApiDepositClient(config=self.config["deposit"]) def check(self, collection: str, deposit_id: str) -> Dict[str, str]: diff --git a/swh/deposit/tests/loader/test_client.py b/swh/deposit/tests/loader/test_client.py --- a/swh/deposit/tests/loader/test_client.py +++ b/swh/deposit/tests/loader/test_client.py @@ -1,4 +1,4 @@ -# Copyright (C) 2017-2019 The Software Heritage developers +# Copyright (C) 2017-2020 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information @@ -14,12 +14,28 @@ from swh.deposit.client import PrivateApiDepositClient from swh.deposit.config import DEPOSIT_STATUS_LOAD_FAILURE, DEPOSIT_STATUS_LOAD_SUCCESS + CLIENT_TEST_CONFIG = { "url": "https://nowhere.org/", "auth": {}, # no authentication in test scenario } +@pytest.fixture +def deposit_config(): + return CLIENT_TEST_CONFIG + + +def test_client_config(deposit_config_path): + for client in [ + # config passed as constructor parameter + PrivateApiDepositClient(config=CLIENT_TEST_CONFIG), + # config loaded from environment + PrivateApiDepositClient() + ]: + assert client.config == CLIENT_TEST_CONFIG + + def build_expected_path(datadir, base_url: str, api_url: str) -> str: """Build expected path from api to served file @@ -77,7 +93,7 @@ """ api_url = "/1/private/test/1/raw/" - client = PrivateApiDepositClient(config=CLIENT_TEST_CONFIG) + client = PrivateApiDepositClient(CLIENT_TEST_CONFIG) expected_content = read_served_path(datadir, client.base_url, api_url)