Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/tests/loader/conftest.py
# Copyright (C) 2019 The Software Heritage developers | # Copyright (C) 2019-2020 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import re | import re | ||||
import os | |||||
import pytest | import pytest | ||||
import yaml | |||||
from functools import partial | from functools import partial | ||||
from swh.core.pytest_plugin import get_response_cb | from swh.core.pytest_plugin import get_response_cb | ||||
from swh.deposit.loader.checker import DepositChecker | from swh.deposit.loader.checker import DepositChecker | ||||
@pytest.fixture | @pytest.fixture | ||||
def swh_config(tmp_path, swh_storage_postgresql, monkeypatch): | def deposit_config(tmp_path): | ||||
storage_config = { | return { | ||||
"url": "https://deposit.softwareheritage.org/", | |||||
"storage": { | |||||
"cls": "local", | |||||
"args": { | |||||
"db": swh_storage_postgresql.dsn, | |||||
"objstorage": {"cls": "memory", "args": {}}, | |||||
vlorentz: how does the deposit know how to connect to pg in tests, now? | |||||
Done Inline ActionsThe tests in the "loader" folder don't connect to the db. They are passing through the request_mock_datadir fixture and other mocker things. Note: Historically called "loader/" but it used to be a loader in here, remains only the checker now. ardumont: The tests in the "loader" folder don't connect to the db.
Thus why they pass here.
They are… | |||||
}, | |||||
}, | |||||
} | |||||
conffile = os.path.join(tmp_path, "deposit.yml") | |||||
with open(conffile, "w") as f: | |||||
f.write(yaml.dump(storage_config)) | |||||
monkeypatch.setenv("SWH_CONFIG_FILENAME", conffile) | |||||
return conffile | |||||
@pytest.fixture | |||||
def deposit_checker(): | |||||
return DepositChecker( | |||||
config={ | |||||
"deposit": { | "deposit": { | ||||
"url": "https://deposit.softwareheritage.org/1/private/", | "url": "https://deposit.softwareheritage.org/1/private/", | ||||
"auth": {}, | "auth": {}, | ||||
} | } | ||||
} | } | ||||
) | |||||
@pytest.fixture | |||||
def deposit_checker(deposit_config_path): | |||||
return DepositChecker() | |||||
@pytest.fixture | @pytest.fixture | ||||
def requests_mock_datadir(datadir, requests_mock_datadir): | def requests_mock_datadir(datadir, requests_mock_datadir): | ||||
"""Override default behavior to deal with put method | """Override default behavior to deal with put method | ||||
""" | """ | ||||
cb = partial(get_response_cb, datadir=datadir) | cb = partial(get_response_cb, datadir=datadir) | ||||
requests_mock_datadir.put(re.compile("https://"), body=cb) | requests_mock_datadir.put(re.compile("https://"), body=cb) | ||||
return requests_mock_datadir | return requests_mock_datadir |
how does the deposit know how to connect to pg in tests, now?