Make stateless lister constructors compatible with credentials
In effect, it just allows to add credentials to cgit, cran and pypi listers. This fixes instances of error [1] [1] https://sentry.softwareheritage.org/share/issue/2c35a9f129cf4982a2dd003a232d507a/ Related to T2998
This commit is contained in:
parent
72be074a79
commit
ae17b6b9a0
7 changed files with 123 additions and 15 deletions
|
@ -10,7 +10,7 @@ from typing import Dict, Iterator, List, Optional, Tuple
|
|||
|
||||
import pkg_resources
|
||||
|
||||
from swh.lister.pattern import StatelessLister
|
||||
from swh.lister.pattern import CredentialsType, StatelessLister
|
||||
from swh.scheduler.interface import SchedulerInterface
|
||||
from swh.scheduler.model import ListedOrigin
|
||||
|
||||
|
@ -29,9 +29,13 @@ class CRANLister(StatelessLister[PageType]):
|
|||
LISTER_NAME = "CRAN"
|
||||
|
||||
def __init__(
|
||||
self, scheduler: SchedulerInterface,
|
||||
self,
|
||||
scheduler: SchedulerInterface,
|
||||
credentials: Optional[CredentialsType] = None,
|
||||
):
|
||||
super().__init__(scheduler, url=CRAN_MIRROR, instance="cran")
|
||||
super().__init__(
|
||||
scheduler, url=CRAN_MIRROR, instance="cran", credentials=credentials
|
||||
)
|
||||
|
||||
def get_pages(self) -> Iterator[PageType]:
|
||||
"""
|
||||
|
|
|
@ -89,3 +89,34 @@ def test_cran_lister_cran(datadir, swh_scheduler, mocker):
|
|||
}
|
||||
|
||||
filtered_origins[0].last_update == parse_packaged_date(package_info)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"credentials, expected_credentials",
|
||||
[
|
||||
(None, []),
|
||||
({"key": "value"}, []),
|
||||
(
|
||||
{"CRAN": {"cran": [{"username": "user", "password": "pass"}]}},
|
||||
[{"username": "user", "password": "pass"}],
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_lister_cran_instantiation_with_credentials(
|
||||
credentials, expected_credentials, swh_scheduler
|
||||
):
|
||||
lister = CRANLister(swh_scheduler, credentials=credentials)
|
||||
|
||||
# Credentials are allowed in constructor
|
||||
assert lister.credentials == expected_credentials
|
||||
|
||||
|
||||
def test_lister_cran_from_configfile(swh_scheduler_config, mocker):
|
||||
load_from_envvar = mocker.patch("swh.lister.pattern.load_from_envvar")
|
||||
load_from_envvar.return_value = {
|
||||
"scheduler": {"cls": "local", **swh_scheduler_config},
|
||||
"credentials": {},
|
||||
}
|
||||
lister = CRANLister.from_configfile()
|
||||
assert lister.scheduler is not None
|
||||
assert lister.credentials is not None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue