Changeset View
Standalone View
swh/lister/launchpad/tests/test_lister.py
- This file was added.
import logging | |||||
from datetime import datetime | |||||
from ..lister import LaunchpadLister | |||||
logger = logging.getLogger(__name__) | |||||
def test_launchpad_lister(swh_listers, requests_mock_datadir): | |||||
ardumont: I did not fully realize earlier.
Does that test currently load a real launchpad instance?
(i… | |||||
legauAuthorUnsubmitted Done Inline ActionsYes it does, what would you recommend to use to mock launchpadlib data ? legau: Yes it does, what would you recommend to use to mock launchpadlib data ? | |||||
ardumontUnsubmitted Done Inline ActionsWe are using pytest and this allows to define fixtures like requests_mock_datadir. So as a first step, i'd look if there is any existing fixture around launchpadlib [1] If there is no fixture yet, you can try to define one which would mock the launchpadlib calls to return a fixed dataset of repositories to list. Just define a json file in the "tests/data/launchpadlib/dataset.json" and make the fixture returns it. Then in the tests, you can further ensure the data listed and the test dataset are consistent together. We use pytest-mocker for that, for example [2] [1] https://pytest.readthedocs.io/en/2.7.3/plugins_index/index.html ardumont: We are using pytest and this allows to define fixtures like requests_mock_datadir.
So as a… | |||||
lister: LaunchpadLister = swh_listers['launchpad'] | |||||
lister.ingest_data(None) | |||||
lister.run(max_bound=datetime.now()) | |||||
r = lister.scheduler.search_tasks(task_type='load-git') | |||||
assert len(r) == 75 | |||||
for row in r: | |||||
assert row['type'] == 'load-git' | |||||
# arguments check | |||||
args = row['arguments']['args'] | |||||
assert len(args) == 0 | |||||
# kwargs | |||||
kwargs = row['arguments']['kwargs'] | |||||
assert set(kwargs.keys()) == {'url'} | |||||
Not Done Inline Actionswe have a datadir fixture [1] for that, "inject" datadir in the test signature and: response_filepath = os.path.join(datadir, f'response{page}.json') with open(response_filepath, encoding='utf-8') as f: ... ` [1] https://forge.softwareheritage.org/source/swh-core/browse/master/swh/core/pytest_plugin.py$0-121 ardumont: we have a `datadir` fixture [1] for that, "inject" datadir in the test signature and:
```… | |||||
url = kwargs['url'] | |||||
assert url.startswith('https://git.launchpad.net') | |||||
assert row['policy'] == 'recurring' | |||||
assert row['priority'] is None | |||||
assert row['retries_left'] == 0 |
I did not fully realize earlier.
Does that test currently load a real launchpad instance?
(i believe so and the diff description seems to agree ;)
I don't see the data test file.
requests_mock_datadir is a fixture to transform http requests into lookup within the ./data/<https_server-name>/remaining-file-named-after-remaining-http-query-parameters...