diff --git a/swh/storage/tests/test_storage.py b/swh/storage/tests/test_storage.py --- a/swh/storage/tests/test_storage.py +++ b/swh/storage/tests/test_storage.py @@ -1846,6 +1846,7 @@ self.assertIsNotNone(o_m1) +@pytest.mark.property_based class PropBasedTestStorage(BaseTestStorage, unittest.TestCase): def assert_contents_ok(self, expected_contents, actual_contents, keys_to_check={'sha1', 'data'}): @@ -1893,6 +1894,7 @@ keys_to_check=keys_to_check) def test_generate_content_get_range_limit_none(self): + """content_get_range call with wrong limit input should fail""" with self.assertRaises(ValueError) as e: self.storage.content_get_range(start=None, end=None, limit=None) @@ -1901,6 +1903,7 @@ @given(gen_contents(min_size=1, max_size=4)) def test_generate_content_get_range_no_limit(self, contents): + """content_get_range returns contents within range provided""" self.reset_storage_tables() # add contents to storage self.storage.content_add(contents) @@ -1909,7 +1912,6 @@ get_sha1s = [c['sha1'] for c in contents] get_sha1s.sort() - print('input sha1s: %s' % get_sha1s) start = get_sha1s[0] end = get_sha1s[-1] @@ -1926,9 +1928,9 @@ keys_to_check = set(one_content.keys()) - {'data'} self.assert_contents_ok(contents, actual_contents, keys_to_check) - @pytest.mark.property_based @given(gen_contents(min_size=4, max_size=4)) def test_generate_content_get_range_limit(self, contents): + """content_get_range paginates results if limit exceeded""" self.reset_storage_tables() contents_map = {c['sha1']: c for c in contents} @@ -1939,7 +1941,6 @@ get_sha1s = [c['sha1'] for c in contents] get_sha1s.sort() - print('input sha1s: %s' % get_sha1s) start = get_sha1s[0] end = get_sha1s[-1] @@ -1960,6 +1961,17 @@ self.assert_contents_ok(expected_contents, actual_contents, keys_to_check) + # retrieve next part + actual_results2 = self.storage.content_get_range(start=end, end=end) + actual_contents2 = actual_results2['contents'] + actual_next2 = actual_results2['next'] + + self.assertEqual(1, len(actual_contents2)) + self.assertIsNone(actual_next2) + + self.assert_contents_ok([contents_map[actual_next]], actual_contents2, + keys_to_check) + class TestLocalStorage(CommonTestStorage, unittest.TestCase): """Test the local storage"""