lister.cgit.tests: Clarify lister configuration

This commit is contained in:
Antoine R. Dumont (@ardumont) 2020-10-29 17:28:55 +01:00
parent c5af0efbf4
commit 5d4b38999d
No known key found for this signature in database
GPG key ID: 52E2E9840D10C3B8
2 changed files with 42 additions and 30 deletions

View file

@ -0,0 +1,26 @@
# Copyright (C) 2019-2020 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
import pytest
@pytest.fixture
def lister_under_test():
return "cgit"
@pytest.fixture
def lister_cgit(swh_lister):
for task_type in [
{
"type": "load-git",
"description": "Load git repository",
"backend_name": "swh.loader.git.tasks.UpdateGitRepository",
"default_interval": "1 day",
},
]:
swh_lister.scheduler.create_task_type(task_type)
return swh_lister

View file

@ -2,22 +2,13 @@
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
import pytest
from swh.lister import __version__
@pytest.fixture
def lister_under_test():
return "cgit"
def test_lister_cgit_no_page(requests_mock_datadir, lister_cgit):
assert lister_cgit.url == "https://git.savannah.gnu.org/cgit/"
def test_lister_no_page(requests_mock_datadir, swh_lister):
lister = swh_lister
assert lister.url == "https://git.savannah.gnu.org/cgit/"
repos = list(lister.get_repos())
repos = list(lister_cgit.get_repos())
assert len(repos) == 977
assert repos[0] == "https://git.savannah.gnu.org/cgit/elisp-es.git/"
@ -27,12 +18,10 @@ def test_lister_no_page(requests_mock_datadir, swh_lister):
assert repos[-2] == "http://example.org/cgit/xstarcastle.git/"
def test_lister_model(requests_mock_datadir, swh_lister):
lister = swh_lister
def test_lister_cgit_model(requests_mock_datadir, lister_cgit):
repo = next(lister_cgit.get_repos())
repo = next(lister.get_repos())
model = lister.build_model(repo)
model = lister_cgit.build_model(repo)
assert model == {
"uid": "https://git.savannah.gnu.org/cgit/elisp-es.git/",
"name": "elisp-es.git",
@ -42,21 +31,19 @@ def test_lister_model(requests_mock_datadir, swh_lister):
}
def test_lister_with_pages(requests_mock_datadir, swh_lister):
lister = swh_lister
lister.url = "https://git.tizen/cgit/"
def test_lister_cgit_with_pages(requests_mock_datadir, lister_cgit):
lister_cgit.url = "https://git.tizen/cgit/"
repos = list(lister.get_repos())
repos = list(lister_cgit.get_repos())
# we should have 16 repos (listed on 3 pages)
assert len(repos) == 16
def test_lister_run(requests_mock_datadir, swh_lister):
lister = swh_lister
lister.url = "https://git.tizen/cgit/"
lister.run()
def test_lister_cgit_run(requests_mock_datadir, lister_cgit):
lister_cgit.url = "https://git.tizen/cgit/"
lister_cgit.run()
r = lister.scheduler.search_tasks(task_type="load-git")
r = lister_cgit.scheduler.search_tasks(task_type="load-git")
assert len(r) == 16
for row in r:
@ -75,10 +62,9 @@ def test_lister_run(requests_mock_datadir, swh_lister):
assert row["priority"] is None
def test_lister_requests(requests_mock_datadir, swh_lister):
lister = swh_lister
lister.url = "https://git.tizen/cgit/"
lister.run()
def test_lister_cgit_requests(requests_mock_datadir, lister_cgit):
lister_cgit.url = "https://git.tizen/cgit/"
lister_cgit.run()
assert len(requests_mock_datadir.request_history) != 0
for request in requests_mock_datadir.request_history: