Changeset View
Standalone View
swh/storage/tests/test_storage.py
Show First 20 Lines • Show All 3,697 Lines • ▼ Show 20 Lines | def test_generate_content_get_metadata(self, contents): | ||||
# will check that all contents are retrieved correctly | # will check that all contents are retrieved correctly | ||||
one_content = contents[0] | one_content = contents[0] | ||||
# content_get_metadata does not return data | # content_get_metadata does not return data | ||||
keys_to_check = set(one_content.keys()) - {'data'} | keys_to_check = set(one_content.keys()) - {'data'} | ||||
self.assert_contents_ok(contents, actual_contents, | self.assert_contents_ok(contents, actual_contents, | ||||
keys_to_check=keys_to_check) | keys_to_check=keys_to_check) | ||||
@given(gen_contents(), | |||||
strategies.binary(min_size=20, max_size=20), | |||||
strategies.binary(min_size=20, max_size=20)) | |||||
def test_generate_content_get_range(self, contents, start, end): | |||||
"""content_get_range paginates results if limit exceeded""" | |||||
self.reset_storage_tables() | |||||
# add contents to storage | |||||
self.storage.content_add(contents) | |||||
actual_result = self.storage.content_get_range(start, end) | |||||
actual_contents = actual_result['contents'] | |||||
actual_next = actual_result['next'] | |||||
self.assertEqual(actual_next, None) | |||||
expected_contents = [c for c in contents | |||||
if start <= c['sha1'] <= end] | |||||
if expected_contents: | |||||
keys_to_check = set(contents[0].keys()) - {'data'} | |||||
self.assert_contents_ok(expected_contents, actual_contents, | |||||
keys_to_check) | |||||
else: | |||||
self.assertEqual(actual_contents, []) | |||||
def test_generate_content_get_range_limit_none(self): | def test_generate_content_get_range_limit_none(self): | ||||
"""content_get_range call with wrong limit input should fail""" | """content_get_range call with wrong limit input should fail""" | ||||
with self.assertRaises(ValueError) as e: | with self.assertRaises(ValueError) as e: | ||||
self.storage.content_get_range(start=None, end=None, limit=None) | self.storage.content_get_range(start=None, end=None, limit=None) | ||||
self.assertEqual(e.exception.args, ( | self.assertEqual(e.exception.args, ( | ||||
'Development error: limit should not be None',)) | 'Development error: limit should not be None',)) | ||||
▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Lines | def test_origin_get_range(self, new_origins): | ||||
origin_from = random.randint(1, nb_origins-1) | origin_from = random.randint(1, nb_origins-1) | ||||
origin_count = random.randint(1, nb_origins - origin_from) | origin_count = random.randint(1, nb_origins - origin_from) | ||||
actual_origins = list( | actual_origins = list( | ||||
self.storage.origin_get_range(origin_from=origin_from, | self.storage.origin_get_range(origin_from=origin_from, | ||||
origin_count=origin_count)) | origin_count=origin_count)) | ||||
for origin in actual_origins: | for origin in actual_origins: | ||||
del origin['id'] | del origin['id'] | ||||
douardda: probably a stupid question but why do we expect 3 here (instead of 4)? | |||||
Done Inline ActionsBecause we're getting contents in range get_sha1s[1] to get_sha1s[-1] inclusive, so that's all the contents (4) minus the first one. vlorentz: Because we're getting contents in range `get_sha1s[1]` to `get_sha1s[-1]` inclusive, so that's… | |||||
Not Done Inline Actionsoh yes indeed. Wouldn't it be useful (?) to raise the max_size and check the content_get_range against all situations wrt range limits: the beginning, middle and end of the range (like range(0, 2), range(n, n+2) and range(-3, -1) )? douardda: oh yes indeed.
Wouldn't it be useful (?) to raise the max_size and check the… | |||||
Done Inline ActionsThat's what the three tests are for (test_generate_content_get_range_start, test_generate_content_get_range_end, test_origin_get_range). I did not want to do a single test for all of them, because it means writing the same logic in the test as in the real code, so testing makes less sense vlorentz: That's what the three tests are for (test_generate_content_get_range_start… | |||||
Not Done Inline ActionsOh you mean I must read the whole diff when I review it? what a bama. So now, why does the range_start test uses sha1[1] as start value? douardda: Oh you mean I must read the whole diff when I review it? what a bama.
So now, why does the… | |||||
Done Inline Actionsrange_start tests that nothing before the start is returned, range_end tests that nothing after the end is returned. vlorentz: `range_start` tests that nothing before the start is returned, `range_end` tests that nothing… | |||||
Done Inline ActionsEh, you're right, I could merge these two tests vlorentz: Eh, you're right, I could merge these two tests | |||||
for origin in actual_origins: | for origin in actual_origins: | ||||
self.assertIn(origin, new_origins) | self.assertIn(origin, new_origins) | ||||
origin_from = -1 | origin_from = -1 | ||||
origin_count = 5 | origin_count = 5 | ||||
origins = list( | origins = list( | ||||
self.storage.origin_get_range(origin_from=origin_from, | self.storage.origin_get_range(origin_from=origin_from, | ||||
▲ Show 20 Lines • Show All 185 Lines • Show Last 20 Lines |
probably a stupid question but why do we expect 3 here (instead of 4)?