Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/nixguix/tests/test_nixguix.py
- This file was moved from swh/loader/package/nixguix/tests/test_functional.py.
Show First 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | def test_uncompress_failure(swh_config, requests_mock_datadir): | ||||
However, even in this case of failure (because of the url | However, even in this case of failure (because of the url | ||||
https://example.com/file.txt), a snapshot and a visit has to be | https://example.com/file.txt), a snapshot and a visit has to be | ||||
created (with a status partial since all files are not archived). | created (with a status partial since all files are not archived). | ||||
""" | """ | ||||
loader = NixGuixLoader(sources_url) | loader = NixGuixLoader(sources_url) | ||||
loader_status = loader.load() | loader_status = loader.load() | ||||
urls = [s['url'][0] for s in loader.sources] | urls = [urls[0] for _, urls in loader.sources.items()] | ||||
assert "https://example.com/file.txt" in urls | assert "https://example.com/file.txt" in urls | ||||
assert loader_status['status'] == 'eventful' | assert loader_status['status'] == 'eventful' | ||||
origin_visit = loader.storage.origin_visit_get_latest(sources_url) | origin_visit = loader.storage.origin_visit_get_latest(sources_url) | ||||
# The visit is partial because urls pointing to non tarball files | # The visit is partial because urls pointing to non tarball files | ||||
# are not handled yet | # are not handled yet | ||||
assert origin_visit['status'] == 'partial' | assert origin_visit['status'] == 'partial' | ||||
def test_loader_incremental(swh_config, requests_mock_datadir): | def test_loader_incremental(swh_config, requests_mock_datadir): | ||||
"""Ensure a second visit do not download artifact already | """Ensure a second visit do not download artifact already | ||||
downloaded by the previous visit. | downloaded by the previous visit. | ||||
""" | """ | ||||
loader = NixGuixLoader(sources_url) | loader = NixGuixLoader(sources_url) | ||||
load_status = loader.load() | load_status = loader.load() | ||||
loader = NixGuixLoader(sources_url) | loader = NixGuixLoader(sources_url) | ||||
loader.load() | loader.load() | ||||
expected_snapshot_id = '0c5881c74283793ebe9a09a105a9381e41380383' | expected_snapshot_id = 'f12e63afc45221914f4d7122fc90dbaf68de323e' | ||||
assert load_status == { | assert load_status == { | ||||
'status': 'eventful', | 'status': 'eventful', | ||||
'snapshot_id': expected_snapshot_id | 'snapshot_id': expected_snapshot_id | ||||
} | } | ||||
expected_branches = { | expected_branches = { | ||||
'evaluation': { | 'evaluation': { | ||||
'target': 'cc4e04c26672dd74e5fd0fecb78b435fb55368f7', | 'target': 'cc4e04c26672dd74e5fd0fecb78b435fb55368f7', | ||||
'target_type': 'revision' | 'target_type': 'revision' | ||||
}, | }, | ||||
'https://github.com/owner-1/repository-1/revision-1.tgz': { | 'sha256-3vm2Nt+O4zHf3Ovd/qsv1gKTEUwodX9FLxlrQdry0zs=': { | ||||
'target': '488ad4e7b8e2511258725063cf43a2b897c503b4', | 'target': '488ad4e7b8e2511258725063cf43a2b897c503b4', | ||||
'target_type': 'revision' | 'target_type': 'revision' | ||||
}, | }, | ||||
} | } | ||||
expected_snapshot = { | expected_snapshot = { | ||||
'id': expected_snapshot_id, | 'id': expected_snapshot_id, | ||||
'branches': expected_branches, | 'branches': expected_branches, | ||||
} | } | ||||
Show All 15 Lines | def test_loader_two_visits(swh_config, requests_mock_datadir_visits): | ||||
The first visit creates a snapshot containing one tarball. The | The first visit creates a snapshot containing one tarball. The | ||||
second visit creates a snapshot containing the same tarball and | second visit creates a snapshot containing the same tarball and | ||||
another tarball. | another tarball. | ||||
""" | """ | ||||
loader = NixGuixLoader(sources_url) | loader = NixGuixLoader(sources_url) | ||||
load_status = loader.load() | load_status = loader.load() | ||||
expected_snapshot_id = '0c5881c74283793ebe9a09a105a9381e41380383' | expected_snapshot_id = 'f12e63afc45221914f4d7122fc90dbaf68de323e' | ||||
assert load_status == { | assert load_status == { | ||||
'status': 'eventful', | 'status': 'eventful', | ||||
'snapshot_id': expected_snapshot_id | 'snapshot_id': expected_snapshot_id | ||||
} | } | ||||
expected_branches = { | expected_branches = { | ||||
'evaluation': { | 'evaluation': { | ||||
'target': 'cc4e04c26672dd74e5fd0fecb78b435fb55368f7', | 'target': 'cc4e04c26672dd74e5fd0fecb78b435fb55368f7', | ||||
'target_type': 'revision' | 'target_type': 'revision' | ||||
}, | }, | ||||
'https://github.com/owner-1/repository-1/revision-1.tgz': { | 'sha256-3vm2Nt+O4zHf3Ovd/qsv1gKTEUwodX9FLxlrQdry0zs=': { | ||||
'target': '488ad4e7b8e2511258725063cf43a2b897c503b4', | 'target': '488ad4e7b8e2511258725063cf43a2b897c503b4', | ||||
'target_type': 'revision' | 'target_type': 'revision' | ||||
} | } | ||||
} | } | ||||
expected_snapshot = { | expected_snapshot = { | ||||
'id': expected_snapshot_id, | 'id': expected_snapshot_id, | ||||
'branches': expected_branches, | 'branches': expected_branches, | ||||
Show All 10 Lines | assert { | ||||
'release': 0, | 'release': 0, | ||||
'revision': 1, | 'revision': 1, | ||||
'skipped_content': 0, | 'skipped_content': 0, | ||||
'snapshot': 1 | 'snapshot': 1 | ||||
} == stats | } == stats | ||||
loader = NixGuixLoader(sources_url) | loader = NixGuixLoader(sources_url) | ||||
load_status = loader.load() | load_status = loader.load() | ||||
expected_snapshot_id = 'b0bfa75cbd0cc90aac3b9e95fb0f59c731176d97' | expected_snapshot_id = 'db04ce695f0e436a817a9c27ada343a2b475b511' | ||||
assert load_status == { | assert load_status == { | ||||
'status': 'eventful', | 'status': 'eventful', | ||||
'snapshot_id': expected_snapshot_id | 'snapshot_id': expected_snapshot_id | ||||
} | } | ||||
# This ensures visits are incremental. Indeed, if we request a | # This ensures visits are incremental. Indeed, if we request a | ||||
# second time an url, because of the requests_mock_datadir_visits | # second time an url, because of the requests_mock_datadir_visits | ||||
# fixture, the file has to end with `_visit1`. | # fixture, the file has to end with `_visit1`. | ||||
expected_branches = { | expected_branches = { | ||||
'evaluation': { | 'evaluation': { | ||||
'target': '602140776b2ce6c9159bcf52ada73a297c063d5e', | 'target': '602140776b2ce6c9159bcf52ada73a297c063d5e', | ||||
'target_type': 'revision' | 'target_type': 'revision' | ||||
}, | }, | ||||
'https://github.com/owner-1/repository-1/revision-1.tgz': { | 'sha256-3vm2Nt+O4zHf3Ovd/qsv1gKTEUwodX9FLxlrQdry0zs=': { | ||||
'target': '488ad4e7b8e2511258725063cf43a2b897c503b4', | 'target': '488ad4e7b8e2511258725063cf43a2b897c503b4', | ||||
'target_type': 'revision' | 'target_type': 'revision' | ||||
}, | }, | ||||
'https://github.com/owner-2/repository-1/revision-1.tgz': { | 'sha256-+vRlzTcnhMlynJGGMuAgMnUGdjpSqGabhcQ/SlRplAE=': { | ||||
'target': '85e0bad74e33e390aaeb74f139853ae3863ee544', | 'target': '85e0bad74e33e390aaeb74f139853ae3863ee544', | ||||
'target_type': 'revision' | 'target_type': 'revision' | ||||
} | } | ||||
} | } | ||||
expected_snapshot = { | expected_snapshot = { | ||||
'id': expected_snapshot_id, | 'id': expected_snapshot_id, | ||||
'branches': expected_branches, | 'branches': expected_branches, | ||||
Show All 13 Lines | assert { | ||||
'snapshot': 2 | 'snapshot': 2 | ||||
} == stats | } == stats | ||||
def test_resolve_revision_from(swh_config, requests_mock_datadir): | def test_resolve_revision_from(swh_config, requests_mock_datadir): | ||||
loader = NixGuixLoader(sources_url) | loader = NixGuixLoader(sources_url) | ||||
known_artifacts = { | known_artifacts = { | ||||
'id1': {'extrinsic': {'raw': {'url': "url1"}}}, | 'id1': {'extrinsic': {'raw': { | ||||
'id2': {'extrinsic': {'raw': {'url': "url2"}}} | 'url': "url1", | ||||
'integrity': 'integrity1'}}}, | |||||
'id2': {'extrinsic': {'raw': { | |||||
'url': "url2", | |||||
'integrity': 'integrity2'}}}, | |||||
} | } | ||||
metadata = {'url': 'url1'} | metadata = {'url': 'url1', 'integrity': 'integrity1'} | ||||
assert loader.resolve_revision_from(known_artifacts, metadata) == 'id1' | assert loader.resolve_revision_from(known_artifacts, metadata) == 'id1' | ||||
metadata = {'url': 'url3'} | metadata = {'url': 'url3', 'integrity': 'integrity3'} | ||||
assert loader.resolve_revision_from(known_artifacts, metadata) == None # noqa | assert loader.resolve_revision_from(known_artifacts, metadata) == None # noqa | ||||
def test_evaluation_branch(swh_config, requests_mock_datadir): | def test_evaluation_branch(swh_config, requests_mock_datadir): | ||||
loader = NixGuixLoader(sources_url) | loader = NixGuixLoader(sources_url) | ||||
res = loader.load() | res = loader.load() | ||||
assert res['status'] == 'eventful' | assert res['status'] == 'eventful' | ||||
expected_branches = { | expected_branches = { | ||||
'https://github.com/owner-1/repository-1/revision-1.tgz': { | 'sha256-3vm2Nt+O4zHf3Ovd/qsv1gKTEUwodX9FLxlrQdry0zs=': { | ||||
'target': '488ad4e7b8e2511258725063cf43a2b897c503b4', | 'target': '488ad4e7b8e2511258725063cf43a2b897c503b4', | ||||
'target_type': 'revision', | 'target_type': 'revision', | ||||
}, | }, | ||||
'evaluation': { | 'evaluation': { | ||||
'target': 'cc4e04c26672dd74e5fd0fecb78b435fb55368f7', | 'target': 'cc4e04c26672dd74e5fd0fecb78b435fb55368f7', | ||||
'target_type': 'revision', | 'target_type': 'revision', | ||||
}, | }, | ||||
} | } | ||||
expected_snapshot = { | expected_snapshot = { | ||||
'id': '0c5881c74283793ebe9a09a105a9381e41380383', | 'id': 'f12e63afc45221914f4d7122fc90dbaf68de323e', | ||||
'branches': expected_branches, | 'branches': expected_branches, | ||||
} | } | ||||
check_snapshot(expected_snapshot, storage=loader.storage) | check_snapshot(expected_snapshot, storage=loader.storage) | ||||
def test_eoferror(swh_config, requests_mock_datadir): | def test_eoferror(swh_config, requests_mock_datadir): | ||||
"""Load a truncated archive which is invalid to make the uncompress | """Load a truncated archive which is invalid to make the uncompress | ||||
Show All 20 Lines |