Changeset View
Changeset View
Standalone View
Standalone View
swh/lister/cgit/tests/test_lister.py
Show First 20 Lines • Show All 190 Lines • ▼ Show 20 Lines | load_from_envvar.return_value = { | ||||
"scheduler": {"cls": "local", **swh_scheduler_config}, | "scheduler": {"cls": "local", **swh_scheduler_config}, | ||||
"url": "https://git.tizen/cgit/", | "url": "https://git.tizen/cgit/", | ||||
"instance": "tizen", | "instance": "tizen", | ||||
"credentials": {}, | "credentials": {}, | ||||
} | } | ||||
lister = CGitLister.from_configfile() | lister = CGitLister.from_configfile() | ||||
assert lister.scheduler is not None | assert lister.scheduler is not None | ||||
assert lister.credentials is not None | assert lister.credentials is not None | ||||
anlambert: maybe you could parametrize the test with more URLs (using edge case URLs listed in T2999). | |||||
Done Inline Actionsok, but that means more html sample files in that diff (currenty adding one other origin) ardumont: ok, but that means more html sample files in that diff (currenty adding one other origin) | |||||
Not Done Inline ActionsAh right, you could isolate the code to compute URLs in a method and only test that then. anlambert: Ah right, you could isolate the code to compute URLs in a method and only test that then. | |||||
Done Inline Actionswell, it's done now ¯\_(ツ)_/¯ :) ardumont: well, it's done now ¯\_(ツ)_/¯ :) | |||||
@pytest.mark.parametrize( | |||||
"url,base_git_url,expected_nb_origins", | |||||
[ | |||||
("https://git.eclipse.org/c", "https://eclipse.org/r", 5), | |||||
("https://git.baserock.org/cgit/", "https://git.baserock.org/git/", 3), | |||||
Done Inline Actionsnot that important but i meant it as /r here ;) ardumont: not that important but i meant it as `/r` here ;) | |||||
("https://jff.email/cgit/", "git://jff.email/opt/git/", 6), | |||||
], | |||||
) | |||||
def test_lister_cgit_with_base_git_url( | |||||
url, base_git_url, expected_nb_origins, requests_mock_datadir, swh_scheduler | |||||
): | |||||
"""With base git url provided, listed urls should be the computed origin urls | |||||
""" | |||||
lister_cgit = CGitLister(swh_scheduler, url=url, base_git_url=base_git_url,) | |||||
stats = lister_cgit.run() | |||||
assert stats == ListerStats(pages=1, origins=expected_nb_origins) | |||||
# test page parsing | |||||
scheduler_origins = swh_scheduler.get_listed_origins( | |||||
lister_cgit.lister_obj.id | |||||
).results | |||||
assert len(scheduler_origins) == expected_nb_origins | |||||
# test listed repositories | |||||
for listed_origin in scheduler_origins: | |||||
assert listed_origin.visit_type == "git" | |||||
assert listed_origin.url.startswith(base_git_url) | |||||
assert ( | |||||
listed_origin.url.startswith(url) is False | |||||
), f"url should be mapped to {base_git_url}" |
maybe you could parametrize the test with more URLs (using edge case URLs listed in T2999).