Changeset View
Changeset View
Standalone View
Standalone View
swh/lister/tests/test_cli.py
# Copyright (C) 2019-2020 The Software Heritage developers | # Copyright (C) 2019-2021 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 pytest | import pytest | ||||
from swh.lister.cli import SUPPORTED_LISTERS, get_lister | from swh.lister.cli import SUPPORTED_LISTERS, get_lister | ||||
from .test_utils import init_db | |||||
lister_args = { | lister_args = { | ||||
"cgit": {"url": "https://git.eclipse.org/c/",}, | "cgit": {"url": "https://git.eclipse.org/c/",}, | ||||
"phabricator": { | "phabricator": { | ||||
"instance": "softwareheritage", | "instance": "softwareheritage", | ||||
"url": "https://forge.softwareheritage.org/api/diffusion.repository.search", | "url": "https://forge.softwareheritage.org/api/diffusion.repository.search", | ||||
"api_token": "bogus", | "api_token": "bogus", | ||||
}, | }, | ||||
"gitea": {"url": "https://try.gitea.io/api/v1/",}, | "gitea": {"url": "https://try.gitea.io/api/v1/",}, | ||||
"gitlab": {"url": "https://gitlab.ow2.org/api/v4", "instance": "ow2",}, | "gitlab": {"url": "https://gitlab.ow2.org/api/v4", "instance": "ow2",}, | ||||
} | } | ||||
def test_get_lister_wrong_input(): | def test_get_lister_wrong_input(): | ||||
"""Unsupported lister should raise""" | """Unsupported lister should raise""" | ||||
with pytest.raises(ValueError) as e: | with pytest.raises(ValueError) as e: | ||||
get_lister("unknown", "db-url") | get_lister("unknown", "db-url") | ||||
assert "Invalid lister" in str(e.value) | assert "Invalid lister" in str(e.value) | ||||
def test_get_lister(swh_scheduler_config): | def test_get_lister(swh_scheduler_config): | ||||
"""Instantiating a supported lister should be ok | """Instantiating a supported lister should be ok | ||||
""" | """ | ||||
db_url = init_db().url() | |||||
# Drop launchpad lister from the lister to check, its test setup is more involved | # Drop launchpad lister from the lister to check, its test setup is more involved | ||||
# than the other listers and it's not currently done here | # than the other listers and it's not currently done here | ||||
for lister_name in SUPPORTED_LISTERS: | for lister_name in SUPPORTED_LISTERS: | ||||
lst = get_lister( | lst = get_lister( | ||||
lister_name, | lister_name, | ||||
db_url, | |||||
scheduler={"cls": "local", **swh_scheduler_config}, | scheduler={"cls": "local", **swh_scheduler_config}, | ||||
**lister_args.get(lister_name, {}), | **lister_args.get(lister_name, {}), | ||||
) | ) | ||||
assert hasattr(lst, "run") | assert hasattr(lst, "run") |