X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/0888e3a31a1af2041e316a2e7b3db74af1cea373..d87717b4ec885059183ef6d7fa6780c343338455:/sdk/python/tests/test_keep_locator.py diff --git a/sdk/python/tests/test_keep_locator.py b/sdk/python/tests/test_keep_locator.py index e9d635673c..a7e9cb1bc3 100644 --- a/sdk/python/tests/test_keep_locator.py +++ b/sdk/python/tests/test_keep_locator.py @@ -8,7 +8,7 @@ import unittest from arvados.keep import KeepLocator -class ArvadosPutResumeCacheTest(unittest.TestCase): +class ArvadosKeepLocatorTest(unittest.TestCase): DEFAULT_TEST_COUNT = 10 def numstrs(fmtstr, base, exponent): @@ -22,13 +22,17 @@ class ArvadosPutResumeCacheTest(unittest.TestCase): signatures = numstrs('{:040x}', 16, 40) timestamps = numstrs('{:08x}', 16, 8) + def base_locators(self, count=DEFAULT_TEST_COUNT): + return ('+'.join(pair) for pair in + itertools.izip(self.checksums(count), self.sizes(count))) + def perm_hints(self, count=DEFAULT_TEST_COUNT): for sig, ts in itertools.izip(self.signatures(count), self.timestamps(count)): yield 'A{}@{}'.format(sig, ts) def test_good_locators_returned(self): - for hint_gens in [(), (self.sizes(),), (self.perm_hints(),), + for hint_gens in [(), (self.sizes(),), (self.sizes(), self.perm_hints())]: for loc_data in itertools.izip(self.checksums(), *hint_gens): locator = '+'.join(loc_data) @@ -40,24 +44,36 @@ class ArvadosPutResumeCacheTest(unittest.TestCase): '3+8f9e68d957b504a29ba76c526c3145d9']: self.assertRaises(ValueError, KeepLocator, badstr) + def test_unknown_hints_accepted(self): + base = next(self.base_locators(1)) + for weirdhint in ['Zfoo', 'Ybar234', 'Xa@b_c-372', 'W99']: + locator = '+'.join([base, weirdhint]) + self.assertEquals(locator, str(KeepLocator(locator))) + def test_bad_hints_rejected(self): - checksum = next(self.checksums(1)) - for badhint in ['', 'nonsense', '+32', checksum]: + base = next(self.base_locators(1)) + for badhint in ['', 'A', 'lowercase', '+32']: self.assertRaises(ValueError, KeepLocator, - '+'.join([checksum, badhint])) + '+'.join([base, badhint])) + + def test_multiple_locator_hints_accepted(self): + base = next(self.base_locators(1)) + for loc_hints in itertools.permutations(['Kab1cd', 'Kef2gh', 'Kij3kl']): + locator = '+'.join((base,) + loc_hints) + self.assertEquals(locator, str(KeepLocator(locator))) def test_expiry_passed(self): - checksum = next(self.checksums(1)) + base = next(self.base_locators(1)) signature = next(self.signatures(1)) dt1980 = datetime.datetime(1980, 1, 1) dt2000 = datetime.datetime(2000, 2, 2) dt2080 = datetime.datetime(2080, 3, 3) - locator = KeepLocator(checksum) + locator = KeepLocator(base) self.assertFalse(locator.permission_expired()) self.assertFalse(locator.permission_expired(dt1980)) self.assertFalse(locator.permission_expired(dt2080)) # Timestamped to 1987-01-05 18:48:32. - locator = KeepLocator('{}+A{}@20000000'.format(checksum, signature)) + locator = KeepLocator('{}+A{}@20000000'.format(base, signature)) self.assertTrue(locator.permission_expired()) self.assertTrue(locator.permission_expired(dt2000)) self.assertFalse(locator.permission_expired(dt1980))