Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/functional/tests/test_functional.py
Show First 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | def test_loader_incremental(swh_config, requests_mock_datadir): | ||||
downloaded by the previous visit. | downloaded by the previous visit. | ||||
""" | """ | ||||
loader = FunctionalLoader(sources_url) | loader = FunctionalLoader(sources_url) | ||||
load_status = loader.load() | load_status = loader.load() | ||||
loader = FunctionalLoader(sources_url) | loader = FunctionalLoader(sources_url) | ||||
loader.load() | loader.load() | ||||
expected_snapshot_id = '2c7f01ef3115f7999a013979fa27bfa12dcb63eb' | expected_snapshot_id = '0c5881c74283793ebe9a09a105a9381e41380383' | ||||
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': { | |||||
'target': 'cc4e04c26672dd74e5fd0fecb78b435fb55368f7', | |||||
'target_type': 'revision' | |||||
}, | |||||
'https://github.com/owner-1/repository-1/revision-1.tgz': { | 'https://github.com/owner-1/repository-1/revision-1.tgz': { | ||||
'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 11 Lines | |||||
def test_loader_two_visits(swh_config, requests_mock_datadir_visits): | def test_loader_two_visits(swh_config, requests_mock_datadir_visits): | ||||
"""To ensure there is only one origin, but two visits, two revisions and | """To ensure there is only one origin, but two visits, two revisions and | ||||
two snapshots are created. | two snapshots are created. | ||||
""" | """ | ||||
loader = FunctionalLoader(sources_url, 'nixpkgs') | loader = FunctionalLoader(sources_url, 'nixpkgs') | ||||
load_status = loader.load() | load_status = loader.load() | ||||
expected_snapshot_id = '2c7f01ef3115f7999a013979fa27bfa12dcb63eb' | expected_snapshot_id = '0c5881c74283793ebe9a09a105a9381e41380383' | ||||
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': { | |||||
'target': 'cc4e04c26672dd74e5fd0fecb78b435fb55368f7', | |||||
'target_type': 'revision' | |||||
}, | |||||
'https://github.com/owner-1/repository-1/revision-1.tgz': { | 'https://github.com/owner-1/repository-1/revision-1.tgz': { | ||||
'target': '488ad4e7b8e2511258725063cf43a2b897c503b4', | 'target': '488ad4e7b8e2511258725063cf43a2b897c503b4', | ||||
'target_type': 'revision' | 'target_type': 'revision' | ||||
} | } | ||||
} | } | ||||
expected_snapshot = { | expected_snapshot = { | ||||
'id': expected_snapshot_id, | 'id': expected_snapshot_id, | ||||
Show All 11 Lines | assert { | ||||
'release': 0, | 'release': 0, | ||||
'revision': 1, | 'revision': 1, | ||||
'skipped_content': 0, | 'skipped_content': 0, | ||||
'snapshot': 1 | 'snapshot': 1 | ||||
} == stats | } == stats | ||||
loader = FunctionalLoader(sources_url, 'nixpkgs') | loader = FunctionalLoader(sources_url, 'nixpkgs') | ||||
load_status = loader.load() | load_status = loader.load() | ||||
expected_snapshot_id = '9c4fbfd991b35c7de876cd66bcda2967a8f476ac' | expected_snapshot_id = 'b0bfa75cbd0cc90aac3b9e95fb0f59c731176d97' | ||||
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': { | |||||
'target': '602140776b2ce6c9159bcf52ada73a297c063d5e', | |||||
'target_type': 'revision' | |||||
}, | |||||
'https://github.com/owner-1/repository-1/revision-1.tgz': { | 'https://github.com/owner-1/repository-1/revision-1.tgz': { | ||||
'target': '488ad4e7b8e2511258725063cf43a2b897c503b4', | 'target': '488ad4e7b8e2511258725063cf43a2b897c503b4', | ||||
'target_type': 'revision' | 'target_type': 'revision' | ||||
}, | }, | ||||
'https://github.com/owner-2/repository-1/revision-1.tgz': { | 'https://github.com/owner-2/repository-1/revision-1.tgz': { | ||||
'target': '85e0bad74e33e390aaeb74f139853ae3863ee544', | 'target': '85e0bad74e33e390aaeb74f139853ae3863ee544', | ||||
'target_type': 'revision' | 'target_type': 'revision' | ||||
} | } | ||||
Show All 26 Lines | known_artifacts = { | ||||
'id1': {'extrinsic': {'raw': {'url': "url1"}}}, | 'id1': {'extrinsic': {'raw': {'url': "url1"}}}, | ||||
'id2': {'extrinsic': {'raw': {'url': "url2"}}} | 'id2': {'extrinsic': {'raw': {'url': "url2"}}} | ||||
} | } | ||||
metadata = {'url': 'url1'} | metadata = {'url': 'url1'} | ||||
assert loader.resolve_revision_from(known_artifacts, metadata) == 'id1' | assert loader.resolve_revision_from(known_artifacts, metadata) == 'id1' | ||||
metadata = {'url': 'url3'} | metadata = {'url': 'url3'} | ||||
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): | |||||
loader = FunctionalLoader(sources_url, 'nixpkgs') | |||||
res = loader.load() | |||||
assert res['status'] == 'eventful' | |||||
expected_branches = { | |||||
'https://github.com/owner-1/repository-1/revision-1.tgz': { | |||||
'target': '488ad4e7b8e2511258725063cf43a2b897c503b4', | |||||
'target_type': 'revision', | |||||
}, | |||||
'evaluation': { | |||||
'target': 'cc4e04c26672dd74e5fd0fecb78b435fb55368f7', | |||||
'target_type': 'revision', | |||||
}, | |||||
} | |||||
expected_snapshot = { | |||||
'id': '0c5881c74283793ebe9a09a105a9381e41380383', | |||||
'branches': expected_branches, | |||||
} | |||||
check_snapshot(expected_snapshot, storage=loader.storage) |