Changeset View
Changeset View
Standalone View
Standalone View
swh/lister/packagist/tests/test_lister.py
# Copyright (C) 2019-2022 The Software Heritage developers | # Copyright (C) 2019-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 | ||||
import datetime | import datetime | ||||
import json | import json | ||||
from pathlib import Path | from pathlib import Path | ||||
from swh.lister.packagist.lister import PackagistLister | from swh.lister.packagist.lister import PackagistLister | ||||
_packages_list = { | _packages_list = { | ||||
"packageNames": [ | "packageNames": [ | ||||
"ljjackson/linnworks", | "ljjackson/linnworks", | ||||
"lky/wx_article", | "lky/wx_article", | ||||
"spryker-eco/computop-api", | "spryker-eco/computop-api", | ||||
"idevlab/essential", | "idevlab/essential", # Git SSH URL | ||||
"payrix/payrix-php", | |||||
"with/invalid_url", # invalid URL | |||||
] | ] | ||||
} | } | ||||
def _package_metadata(datadir, package_name): | def _package_metadata(datadir, package_name): | ||||
return json.loads( | return json.loads( | ||||
Path(datadir, f"{package_name.replace('/', '_')}.json").read_text() | Path(datadir, f"{package_name.replace('/', '_')}.json").read_text() | ||||
) | ) | ||||
Show All 18 Lines | for package_name in _packages_list["packageNames"]: | ||||
requests_mock.get( | requests_mock.get( | ||||
f"{lister.PACKAGIST_REPO_BASE_URL}/{package_name}.json", | f"{lister.PACKAGIST_REPO_BASE_URL}/{package_name}.json", | ||||
json=metadata, | json=metadata, | ||||
additional_matcher=_request_without_if_modified_since, | additional_matcher=_request_without_if_modified_since, | ||||
) | ) | ||||
stats = lister.run() | stats = lister.run() | ||||
assert stats.pages == 1 | assert stats.pages == 1 | ||||
assert stats.origins == len(_packages_list["packageNames"]) | assert stats.origins == len(_packages_list["packageNames"]) - 2 | ||||
assert lister.updated | assert lister.updated | ||||
expected_origins = { | expected_origins = { | ||||
( | ( | ||||
"https://github.com/gitlky/wx_article", # standard case | "https://github.com/gitlky/wx_article", # standard case | ||||
"git", | "git", | ||||
datetime.datetime.fromisoformat("2018-08-30T07:37:09+00:00"), | datetime.datetime.fromisoformat("2018-08-30T07:37:09+00:00"), | ||||
), | ), | ||||
( | ( | ||||
"https://github.com/ljjackson/linnworks.git", # API goes 404 | "https://github.com/ljjackson/linnworks.git", # API goes 404 | ||||
"git", | "git", | ||||
datetime.datetime.fromisoformat("2018-11-01T21:45:50+00:00"), | datetime.datetime.fromisoformat("2018-11-01T21:45:50+00:00"), | ||||
), | ), | ||||
( | ( | ||||
"https://github.com/spryker-eco/computop-api", # SSH URL in manifest | "https://github.com/spryker-eco/computop-api", # SSH URL in manifest | ||||
"git", | "git", | ||||
datetime.datetime.fromisoformat("2020-06-22T15:50:29+00:00"), | datetime.datetime.fromisoformat("2020-06-22T15:50:29+00:00"), | ||||
), | ), | ||||
( | ( | ||||
"git@gitlab.com:idevlab/Essential.git", # not GitHub | "https://gitlab.com/payrix/public/payrix-php.git", # not GitHub | ||||
"git", | "git", | ||||
datetime.datetime.fromisoformat("2022-10-12T10:34:29+00:00"), | datetime.datetime.fromisoformat("2021-05-25T14:12:28+00:00"), | ||||
), | ), | ||||
} | } | ||||
assert expected_origins == { | assert expected_origins == { | ||||
(o.url, o.visit_type, o.last_update) | (o.url, o.visit_type, o.last_update) | ||||
for o in swh_scheduler.get_listed_origins(lister.lister_obj.id).results | for o in swh_scheduler.get_listed_origins(lister.lister_obj.id).results | ||||
} | } | ||||
▲ Show 20 Lines • Show All 117 Lines • Show Last 20 Lines |