Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/debian/tests/test_debian.py
# Copyright (C) 2019 The Software Heritage developers | # Copyright (C) 2019 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 copy | import copy | ||||
import logging | import logging | ||||
import pytest | import pytest | ||||
from os import path | from os import path | ||||
from swh.loader.package.debian.loader import ( | from swh.loader.package.debian.loader import ( | ||||
DebianLoader, download_package, dsc_information, uid_to_person, | DebianLoader, download_package, dsc_information, uid_to_person, | ||||
prepare_person, get_package_metadata, extract_package | prepare_person, get_package_metadata, extract_package | ||||
) | ) | ||||
from swh.loader.package.tests.common import check_snapshot, get_stats | from swh.loader.package.tests.common import check_snapshot, get_stats | ||||
from swh.loader.package.debian.loader import resolve_revision_from | |||||
logger = logging.getLogger(__name__) | logger = logging.getLogger(__name__) | ||||
PACKAGE_FILES = { | PACKAGE_FILES = { | ||||
'name': 'cicero', | 'name': 'cicero', | ||||
'version': '0.7.2-3', | 'version': '0.7.2-3', | ||||
▲ Show 20 Lines • Show All 356 Lines • ▼ Show 20 Lines | expected_snapshot = { | ||||
'releases/buster/contrib/0.7.2-4': { | 'releases/buster/contrib/0.7.2-4': { | ||||
'target_type': 'revision', | 'target_type': 'revision', | ||||
'target': '8224139c274c984147ef4b09aa0e462c55a10bd3', | 'target': '8224139c274c984147ef4b09aa0e462c55a10bd3', | ||||
} | } | ||||
}, | }, | ||||
} | } | ||||
check_snapshot(expected_snapshot, loader.storage) | check_snapshot(expected_snapshot, loader.storage) | ||||
def test_resolve_revision_from_edge_cases(): | |||||
"""Solving revision with empty data will result in unknown revision | |||||
""" | |||||
for package_artifacts in [{}, PACKAGE_FILES]: | |||||
actual_revision = resolve_revision_from( | |||||
package_artifacts, {}) | |||||
assert actual_revision is None | |||||
for known_artifacts in [{}, PACKAGE_FILES]: | |||||
actual_revision = resolve_revision_from( | |||||
{}, known_artifacts) | |||||
assert actual_revision is None | |||||
expected_revision_id = b"(\x07\xf5\xb3\xf8Ch\xb4\x88\x9a\x9a\xe8'\xfe\x85\x85O\xfe\xcf\x07" # noqa | |||||
def test_resolve_revision_from_edge_cases_hit_and_miss(): | |||||
"""Solving revision with inconsistent data will result in unknown revision | |||||
""" | |||||
artifact_metadata = PACKAGE_FILES2 | |||||
expected_revision_id = b"(\x07\xf5\xb3\xf8Ch\xb4\x88\x9a\x9a\xe8'\xfe\x85\x85O\xfe\xcf\x07" # noqa | |||||
known_package_artifacts = { | |||||
expected_revision_id: { | |||||
'extrinsic': { | |||||
'provider': 'http://deb.debian.org/debian/pool/contrib/c/cicero/cicero_0.7.2-3.dsc', # noqa | |||||
'raw': PACKAGE_FILES, | |||||
'when': '2019-12-19T17:04:32.161965+00:00' | |||||
}, | |||||
# ... removed the unnecessary intermediary data | |||||
} | |||||
} | |||||
actual_revision = resolve_revision_from( | |||||
known_package_artifacts, artifact_metadata | |||||
) | |||||
assert actual_revision is None | |||||
def test_resolve_revision_from(): | |||||
"""Solving revision with consistent data will solve the revision | |||||
""" | |||||
artifact_metadata = PACKAGE_FILES | |||||
expected_revision_id = b"(\x07\xf5\xb3\xf8Ch\xb4\x88\x9a\x9a\xe8'\xfe\x85\x85O\xfe\xcf\x07" # noqa | |||||
known_package_artifacts = { | |||||
expected_revision_id: { | |||||
'extrinsic': { | |||||
'provider': 'http://deb.debian.org/debian/pool/contrib/c/cicero/cicero_0.7.2-3.dsc', # noqa | |||||
'raw': PACKAGE_FILES, | |||||
'when': '2019-12-19T17:04:32.161965+00:00' | |||||
}, | |||||
# ... removed the unnecessary intermediary data | |||||
} | |||||
} | |||||
actual_revision = resolve_revision_from( | |||||
known_package_artifacts, artifact_metadata | |||||
) | |||||
assert actual_revision == expected_revision_id |