Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/functional/tests/test_functional.py
- This file was added.
# Copyright (C) 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 | |||||
from swh.loader.package.functional.loader import ( | |||||
FunctionalLoader | |||||
) | |||||
from swh.loader.package.tests.common import ( | |||||
get_stats | |||||
) | |||||
sources_url = 'https://nix-community.github.io/nixpkgs-swh/sources.json' | |||||
def test_retrieve_sources(swh_config, requests_mock_datadir): | |||||
loader = FunctionalLoader(sources_url) | |||||
j = loader._retrieve_sources() | |||||
assert "sources" in j.keys() | |||||
assert len(j["sources"]) == 2 | |||||
def test_retrieve_non_existing(swh_config, requests_mock_datadir): | |||||
with pytest.raises(ValueError): | |||||
FunctionalLoader('https://non-existing-url') | |||||
def test_loader_one_visit(swh_config, requests_mock_datadir): | |||||
loader = FunctionalLoader(sources_url) | |||||
res = loader.load() | |||||
assert res['status'] == 'eventful' | |||||
stats = get_stats(loader.storage) | |||||
assert { | |||||
'content': 1, | |||||
'directory': 3, | |||||
'origin': 1, | |||||
'origin_visit': 1, | |||||
'person': 1, | |||||
'release': 0, | |||||
'revision': 1, | |||||
'skipped_content': 0, | |||||
'snapshot': 1 | |||||
} == stats | |||||
def test_loader_two_visits(swh_config, requests_mock_datadir_visits): | |||||
"""To ensure there is only one origin, but two visits, two revisions and | |||||
two snapshots are created. | |||||
""" | |||||
loader = FunctionalLoader(sources_url, 'nixpkgs') | |||||
res = loader.load() | |||||
assert res['status'] == 'eventful' | |||||
stats = get_stats(loader.storage) | |||||
assert { | |||||
'content': 1, | |||||
'directory': 3, | |||||
'origin': 1, | |||||
'origin_visit': 1, | |||||
'person': 1, | |||||
'release': 0, | |||||
'revision': 1, | |||||
'skipped_content': 0, | |||||
'snapshot': 1 | |||||
} == stats | |||||
# Reset internal state | |||||
loader._info = None | |||||
loader = FunctionalLoader(sources_url, 'nixpkgs') | |||||
res = loader.load() | |||||
assert res['status'] == 'eventful' | |||||
stats = get_stats(loader.storage) | |||||
assert { | |||||
'content': 2, | |||||
'directory': 5, | |||||
'origin': 1, | |||||
'origin_visit': 2, | |||||
'person': 1, | |||||
'release': 0, | |||||
'revision': 2, | |||||
'skipped_content': 0, | |||||
'snapshot': 2 | |||||
} == stats | |||||
def test_resolve_revision_from(swh_config, requests_mock_datadir): | |||||
ardumont: as we are instantiating another loader anyway, it's not useful.
Plus it's at least pypi… | |||||
Done Inline ActionsRemoved. lewo: Removed. | |||||
loader = FunctionalLoader(sources_url) | |||||
known_artifacts = { | |||||
'id1': {'extrinsic': {'raw': {'url': "url1"}}}, | |||||
'id2': {'extrinsic': {'raw': {'url': "url2"}}} | |||||
} | |||||
metadata = {'url': 'url1'} | |||||
assert loader.resolve_revision_from(known_artifacts, metadata) == 'id1' | |||||
metadata = {'url': 'url3'} | |||||
assert loader.resolve_revision_from(known_artifacts, metadata) == None # noqa | |||||
Done Inline Actions+1 (for that test scenario ;) ardumont: +1 (for that test scenario ;) | |||||
Done Inline ActionsThis should be removed as per my previous comment. ardumont: This should be removed as per my previous comment. | |||||
Done Inline ActionsDone lewo: Done | |||||
Done Inline ActionsComments should probably be more explicit about what changes between the two visits. I guess that the first visit only manages to fetch one tarball, and the second one manages to fetch both? olasd: Comments should probably be more explicit about what changes between the two visits. I guess… |
as we are instantiating another loader anyway, it's not useful.
Plus it's at least pypi specific :)