Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/arch/tests/test_arch.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 | ||||
import pytest | import pytest | ||||
from swh.loader.package.arch.loader import ArchLoader | from swh.loader.package.arch.loader import ArchLoader | ||||
from swh.loader.tests import assert_last_visit_matches, check_snapshot, get_stats | from swh.loader.tests import assert_last_visit_matches, check_snapshot, get_stats | ||||
from swh.model.hashutil import hash_to_bytes | from swh.model.hashutil import hash_to_bytes | ||||
from swh.model.model import ( | from swh.model.model import ( | ||||
ObjectType, | ObjectType, | ||||
Person, | Person, | ||||
Release, | Release, | ||||
Snapshot, | Snapshot, | ||||
SnapshotBranch, | SnapshotBranch, | ||||
TargetType, | TargetType, | ||||
TimestampWithTimezone, | TimestampWithTimezone, | ||||
) | ) | ||||
EXPECTED_PACKAGES = [ | EXPECTED_PACKAGES = [ | ||||
{ | { | ||||
"url": "https://archive.archlinux.org/packages/d/dialog/", | "url": "https://archive.archlinux.org/packages/d/dialog/", | ||||
"artifacts": [ | "artifacts": { | ||||
{ | "1:1.3_20190211-1": { | ||||
"url": "https://archive.archlinux.org/packages/d/dialog/dialog-1:1.3_20190211-1-x86_64.pkg.tar.xz", # noqa: B950 | "url": "https://archive.archlinux.org/packages/d/dialog/dialog-1:1.3_20190211-1-x86_64.pkg.tar.xz", # noqa: B950 | ||||
"version": "1:1.3_20190211-1", | "version": "1:1.3_20190211-1", | ||||
"length": 180000, | "length": 180000, | ||||
"filename": "dialog-1:1.3_20190211-1-x86_64.pkg.tar.xz", | "filename": "dialog-1:1.3_20190211-1-x86_64.pkg.tar.xz", | ||||
}, | }, | ||||
{ | "1:1.3_20220414-1": { | ||||
"url": "https://archive.archlinux.org/packages/d/dialog/dialog-1:1.3_20220414-1-x86_64.pkg.tar.zst", # noqa: B950 | "url": "https://archive.archlinux.org/packages/d/dialog/dialog-1:1.3_20220414-1-x86_64.pkg.tar.zst", # noqa: B950 | ||||
"version": "1:1.3_20220414-1", | "version": "1:1.3_20220414-1", | ||||
"length": 198000, | "length": 198000, | ||||
"filename": "dialog-1:1.3_20220414-1-x86_64.pkg.tar.zst", | "filename": "dialog-1:1.3_20220414-1-x86_64.pkg.tar.zst", | ||||
}, | }, | ||||
], | }, | ||||
"arch_metadata": [ | "arch_metadata": { | ||||
{ | "1:1.3_20190211-1": { | ||||
"arch": "x86_64", | "arch": "x86_64", | ||||
"repo": "core", | "repo": "core", | ||||
"name": "dialog", | "name": "dialog", | ||||
"version": "1:1.3_20190211-1", | "version": "1:1.3_20190211-1", | ||||
"last_modified": "2019-02-13T08:36:00", | "last_modified": "2019-02-13T08:36:00", | ||||
}, | }, | ||||
{ | "1:1.3_20220414-1": { | ||||
"arch": "x86_64", | "arch": "x86_64", | ||||
"repo": "core", | "repo": "core", | ||||
"name": "dialog", | "name": "dialog", | ||||
"version": "1:1.3_20220414-1", | "version": "1:1.3_20220414-1", | ||||
"last_modified": "2022-04-16T03:59:00", | "last_modified": "2022-04-16T03:59:00", | ||||
}, | }, | ||||
], | }, | ||||
}, | }, | ||||
{ | { | ||||
"url": "https://archlinuxarm.org/packages/aarch64/gzip", | "url": "https://archlinuxarm.org/packages/aarch64/gzip", | ||||
"artifacts": [ | "artifacts": { | ||||
{ | "1.12-1": { | ||||
"url": "https://uk.mirror.archlinuxarm.org/aarch64/core/gzip-1.12-1-aarch64.pkg.tar.xz", # noqa: B950 | "url": "https://uk.mirror.archlinuxarm.org/aarch64/core/gzip-1.12-1-aarch64.pkg.tar.xz", # noqa: B950 | ||||
"length": 79640, | "length": 79640, | ||||
"version": "1.12-1", | "version": "1.12-1", | ||||
"filename": "gzip-1.12-1-aarch64.pkg.tar.xz", | "filename": "gzip-1.12-1-aarch64.pkg.tar.xz", | ||||
} | } | ||||
], | }, | ||||
"arch_metadata": [ | "arch_metadata": { | ||||
{ | "1.12-1": { | ||||
"arch": "aarch64", | "arch": "aarch64", | ||||
"name": "gzip", | "name": "gzip", | ||||
"repo": "core", | "repo": "core", | ||||
"version": "1.12-1", | "version": "1.12-1", | ||||
"last_modified": "2022-04-07T21:08:14", | "last_modified": "2022-04-07T21:08:14", | ||||
} | } | ||||
], | }, | ||||
}, | }, | ||||
] | ] | ||||
def test_get_versions(swh_storage): | def test_get_versions(swh_storage): | ||||
loader = ArchLoader( | loader = ArchLoader( | ||||
swh_storage, | swh_storage, | ||||
url=EXPECTED_PACKAGES[0]["url"], | url=EXPECTED_PACKAGES[0]["url"], | ||||
▲ Show 20 Lines • Show All 142 Lines • ▼ Show 20 Lines | def test_arch_loader_load_n_versions(datadir, requests_mock_datadir, swh_storage): | ||||
) | ) | ||||
def test_arch_invalid_origin_archive_not_found(swh_storage, requests_mock_datadir): | def test_arch_invalid_origin_archive_not_found(swh_storage, requests_mock_datadir): | ||||
url = "https://nowhere/packages/42" | url = "https://nowhere/packages/42" | ||||
loader = ArchLoader( | loader = ArchLoader( | ||||
swh_storage, | swh_storage, | ||||
url, | url, | ||||
artifacts=[ | artifacts={ | ||||
{ | "0.0.1": { | ||||
"filename": "42-0.0.1.pkg.xz", | "filename": "42-0.0.1.pkg.xz", | ||||
"url": "https://mirror2.nowhere/pkg/42-0.0.1.pkg.xz", | "url": "https://mirror2.nowhere/pkg/42-0.0.1.pkg.xz", | ||||
"version": "0.0.1", | "version": "0.0.1", | ||||
"length": 42, | "length": 42, | ||||
}, | }, | ||||
], | }, | ||||
arch_metadata=[ | arch_metadata={ | ||||
{ | "0.0.1": { | ||||
"version": "0.0.1", | "version": "0.0.1", | ||||
"arch": "aarch64", | "arch": "aarch64", | ||||
"name": "42", | "name": "42", | ||||
"repo": "community", | "repo": "community", | ||||
"last_modified": "2022-04-07T21:08:14", | "last_modified": "2022-04-07T21:08:14", | ||||
}, | }, | ||||
], | }, | ||||
) | ) | ||||
with pytest.raises(Exception): | with pytest.raises(Exception): | ||||
assert loader.load() == {"status": "failed"} | assert loader.load() == {"status": "failed"} | ||||
assert_last_visit_matches( | assert_last_visit_matches( | ||||
swh_storage, url, status="not_found", type="arch", snapshot=None | swh_storage, url, status="not_found", type="arch", snapshot=None | ||||
) | ) |