20640: Test keyset_list_all + computed_permissions + select usage.
authorTom Clegg <tom@curii.com>
Thu, 20 Jun 2024 20:40:04 +0000 (16:40 -0400)
committerTom Clegg <tom@curii.com>
Thu, 20 Jun 2024 20:40:04 +0000 (16:40 -0400)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curii.com>

sdk/python/tests/test_util.py

index 4122c6e87a43ae383ecadfdf798d84d0e4b66c2a..aa6d57c26c58994770e38e2123c5b63f47a549cd 100644 (file)
@@ -37,6 +37,12 @@ _SELECT_FAKE_ITEM = {
     'created_at': '2023-08-28T12:34:56.123456Z',
 }
 
+_FAKE_COMPUTED_PERMISSIONS_ITEM = {
+    'user_uuid': 'zzzzz-zyyyz-zzzzzyyyyywwwww',
+    'target_uuid': 'zzzzz-ttttt-xxxxxyyyyyzzzzz',
+    'perm_level': 'can_write',
+}
+
 class KeysetListAllTestCase(unittest.TestCase):
     def test_empty(self):
         ks = KeysetTestHelper([[
@@ -158,20 +164,25 @@ class KeysetListAllTestCase(unittest.TestCase):
         ls = list(arvados.util.keyset_list_all(ks.fn, ascending=False))
         self.assertEqual(ls, [{"created_at": "2", "uuid": "2"}, {"created_at": "1", "uuid": "1"}])
 
-    @parameterized.parameterized.expand(zip(
-        itertools.cycle(_SELECT_FAKE_ITEM),
+    @parameterized.parameterized.expand(
         itertools.chain.from_iterable(
-            itertools.combinations(_SELECT_FAKE_ITEM, count)
-            for count in range(len(_SELECT_FAKE_ITEM) + 1)
+            (zip(
+                itertools.repeat(fake_item),
+                itertools.cycle(fake_item),
+                itertools.chain.from_iterable(
+                    itertools.combinations(fake_item, count)
+                    for count in range(len(fake_item) + 1)
+                ),
+            ) for fake_item in [_SELECT_FAKE_ITEM, _FAKE_COMPUTED_PERMISSIONS_ITEM]),
         ),
-    ))
-    def test_select(self, order_key, select):
+    )
+    def test_select(self, fake_item, order_key, select):
         # keyset_list_all must have both uuid and order_key to function.
         # Test that it selects those fields along with user-specified ones.
         expect_select = {'uuid', order_key, *select}
         item = {
             key: value
-            for key, value in _SELECT_FAKE_ITEM.items()
+            for key, value in fake_item.items()
             if key in expect_select
         }
         list_func = mock.Mock()