Changeset View
Changeset View
Standalone View
Standalone View
swh/lister/puppet/tests/test_lister.py
# Copyright (C) 2022 The Software Heritage developers | # Copyright (C) 2022 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 | ||||
from datetime import datetime, timedelta, timezone | |||||
from swh.lister.puppet.lister import PuppetLister | from swh.lister.puppet.lister import PuppetLister | ||||
# flake8: noqa: B950 | # flake8: noqa: B950 | ||||
expected_origins = [ | expected_origins = [ | ||||
{ | { | ||||
"url": "https://forge.puppet.com/modules/electrical/file_concat", | "url": "https://forge.puppet.com/modules/electrical/file_concat", | ||||
"artifacts": [ | "artifacts": [ | ||||
▲ Show 20 Lines • Show All 99 Lines • ▼ Show 20 Lines | def test_puppet_lister(datadir, requests_mock_datadir, swh_scheduler): | ||||
] == [ | ] == [ | ||||
( | ( | ||||
"puppet", | "puppet", | ||||
expected["url"], | expected["url"], | ||||
expected["artifacts"], | expected["artifacts"], | ||||
) | ) | ||||
for expected in sorted(expected_origins, key=lambda expected: expected["url"]) | for expected in sorted(expected_origins, key=lambda expected: expected["url"]) | ||||
] | ] | ||||
def test_puppet_lister_incremental(datadir, requests_mock_datadir, swh_scheduler): | |||||
# First run | |||||
lister = PuppetLister(scheduler=swh_scheduler) | |||||
res = lister.run() | |||||
assert res.pages == 2 | |||||
assert res.origins == 1 + 1 + 1 | |||||
scheduler_origins = swh_scheduler.get_listed_origins(lister.lister_obj.id).results | |||||
assert len(scheduler_origins) == len(expected_origins) | |||||
assert [ | |||||
( | |||||
scheduled.visit_type, | |||||
scheduled.url, | |||||
scheduled.extra_loader_arguments["artifacts"], | |||||
) | |||||
for scheduled in sorted(scheduler_origins, key=lambda scheduled: scheduled.url) | |||||
] == [ | |||||
( | |||||
"puppet", | |||||
expected["url"], | |||||
expected["artifacts"], | |||||
) | |||||
for expected in sorted(expected_origins, key=lambda expected: expected["url"]) | |||||
] | |||||
# Second run | |||||
lister = PuppetLister(scheduler=swh_scheduler) | |||||
# Force lister.state.last_listing_date for correct fixture loading | |||||
lister.state.last_listing_date = datetime(2022, 9, 26, 18, 0).astimezone( | |||||
timezone(timedelta(hours=-7)) | |||||
) | |||||
res = lister.run() | |||||
assert res.pages == 1 | |||||
assert res.origins == 1 |