Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/tests/test_storage.py
Show First 20 Lines • Show All 3,087 Lines • ▼ Show 20 Lines | def test_generate_content_get_range_limit(self, swh_storage, swh_contents): | ||||
actual_results2 = swh_storage.content_get_range(start=end, end=end) | actual_results2 = swh_storage.content_get_range(start=end, end=end) | ||||
assert actual_results2['next'] is None | assert actual_results2['next'] is None | ||||
actual_contents2 = actual_results2['contents'] | actual_contents2 = actual_results2['contents'] | ||||
assert len(actual_contents2) == 1 | assert len(actual_contents2) == 1 | ||||
self.assert_contents_ok( | self.assert_contents_ok( | ||||
[contents_map[get_sha1s[-1]]], actual_contents2, ['sha1']) | [contents_map[get_sha1s[-1]]], actual_contents2, ['sha1']) | ||||
def test_origin_get_range(self, swh_storage, swh_origins): | def test_origin_get_range_from_zero(self, swh_storage, swh_origins): | ||||
actual_origins = list( | actual_origins = list( | ||||
swh_storage.origin_get_range(origin_from=0, | swh_storage.origin_get_range(origin_from=0, | ||||
origin_count=0)) | origin_count=0)) | ||||
assert len(actual_origins) == 0 | assert len(actual_origins) == 0 | ||||
actual_origins = list( | actual_origins = list( | ||||
swh_storage.origin_get_range(origin_from=0, | swh_storage.origin_get_range(origin_from=0, | ||||
origin_count=1)) | origin_count=1)) | ||||
assert len(actual_origins) == 1 | assert len(actual_origins) == 1 | ||||
assert actual_origins[0]['id'] == 1 | assert actual_origins[0]['id'] == 1 | ||||
assert actual_origins[0]['url'] == swh_origins[0]['url'] | assert actual_origins[0]['url'] == swh_origins[0]['url'] | ||||
@pytest.mark.parametrize('origin_from,origin_count', [ | |||||
(1, 1), (1, 10), (1, 20), (1, 101), (11, 0), | |||||
(11, 10), (91, 11)]) | |||||
def test_origin_get_range( | |||||
self, swh_storage, swh_origins, origin_from, origin_count): | |||||
actual_origins = list( | actual_origins = list( | ||||
swh_storage.origin_get_range(origin_from=1, | swh_storage.origin_get_range(origin_from=origin_from, | ||||
origin_count=1)) | origin_count=origin_count)) | ||||
assert len(actual_origins) == 1 | |||||
assert actual_origins[0]['id'] == 1 | |||||
assert actual_origins[0]['url'] == swh_origins[0]['url'] | |||||
actual_origins = list( | origins_with_id = list(enumerate(swh_origins, start=1)) | ||||
swh_storage.origin_get_range(origin_from=1, | expected_origins = [ | ||||
origin_count=10)) | { | ||||
assert len(actual_origins) == 10 | 'url': origin['url'], | ||||
assert actual_origins[0]['id'] == 1 | 'id': origin_id, | ||||
assert actual_origins[0]['url'] == swh_origins[0]['url'] | } | ||||
assert actual_origins[-1]['id'] == 10 | for (origin_id, origin) | ||||
assert actual_origins[-1]['url'] == swh_origins[9]['url'] | in origins_with_id[origin_from-1:origin_from+origin_count-1] | ||||
] | |||||
actual_origins = list( | |||||
swh_storage.origin_get_range(origin_from=1, | |||||
origin_count=20)) | |||||
assert len(actual_origins) == 20 | |||||
assert actual_origins[0]['id'] == 1 | |||||
assert actual_origins[0]['url'] == swh_origins[0]['url'] | |||||
assert actual_origins[-1]['id'] == 20 | |||||
assert actual_origins[-1]['url'] == swh_origins[19]['url'] | |||||
actual_origins = list( | |||||
swh_storage.origin_get_range(origin_from=1, | |||||
origin_count=101)) | |||||
assert len(actual_origins) == 100 | |||||
assert actual_origins[0]['id'] == 1 | |||||
assert actual_origins[0]['url'] == swh_origins[0]['url'] | |||||
assert actual_origins[-1]['id'] == 100 | |||||
assert actual_origins[-1]['url'] == swh_origins[99]['url'] | |||||
actual_origins = list( | |||||
swh_storage.origin_get_range(origin_from=11, | |||||
origin_count=0)) | |||||
assert len(actual_origins) == 0 | |||||
actual_origins = list( | |||||
swh_storage.origin_get_range(origin_from=11, | |||||
origin_count=10)) | |||||
assert len(actual_origins) == 10 | |||||
assert actual_origins[0]['id'] == 11 | |||||
assert actual_origins[0]['url'] == swh_origins[10]['url'] | |||||
assert actual_origins[-1]['id'] == 20 | |||||
assert actual_origins[-1]['url'] == swh_origins[19]['url'] | |||||
actual_origins = list( | assert actual_origins == expected_origins | ||||
swh_storage.origin_get_range(origin_from=91, | |||||
origin_count=11)) | |||||
assert len(actual_origins) == 10 | |||||
assert actual_origins[0]['id'] == 91 | |||||
assert actual_origins[-1]['id'] == 100 | |||||
assert actual_origins[0]['id'] == 91 | |||||
assert actual_origins[0]['url'] == swh_origins[90]['url'] | |||||
assert actual_origins[-1]['id'] == 100 | |||||
assert actual_origins[-1]['url'] == swh_origins[99]['url'] | |||||
ORIGINS = [ | ORIGINS = [ | ||||
'https://github.com/user1/repo1', | 'https://github.com/user1/repo1', | ||||
'https://github.com/user2/repo1', | 'https://github.com/user2/repo1', | ||||
'https://github.com/user3/repo1', | 'https://github.com/user3/repo1', | ||||
'https://gitlab.com/user1/repo1', | 'https://gitlab.com/user1/repo1', | ||||
'https://gitlab.com/user2/repo1', | 'https://gitlab.com/user2/repo1', | ||||
'https://forge.softwareheritage.org/source/repo1', | 'https://forge.softwareheritage.org/source/repo1', | ||||
▲ Show 20 Lines • Show All 289 Lines • Show Last 20 Lines |