Merge branch '1977-provenance-report' of git.clinicalfuture.com:arvados into 1977...
[arvados.git] / sdk / python / test_keep_client.py
1 # usage example:
2 #
3 # ARVADOS_API_TOKEN=abc ARVADOS_API_HOST=arvados.local python -m unittest discover
4
5 import unittest
6 import arvados
7 import os
8
9 class KeepTestCase(unittest.TestCase):
10     def setUp(self):
11         try:
12             del os.environ['KEEP_LOCAL_STORE']
13         except KeyError:
14             pass
15
16 class KeepBasicRWTest(KeepTestCase):
17     def runTest(self):
18         foo_locator = arvados.Keep.put('foo')
19         self.assertEqual(foo_locator,
20                          'acbd18db4cc2f85cedef654fccc4a4d8+3',
21                          'wrong md5 hash from Keep.put("foo"): ' + foo_locator)
22         self.assertEqual(arvados.Keep.get(foo_locator),
23                          'foo',
24                          'wrong content from Keep.get(md5("foo"))')
25
26 class KeepBinaryRWTest(KeepTestCase):
27     def runTest(self):
28         blob_str = '\xff\xfe\xf7\x00\x01\x02'
29         blob_locator = arvados.Keep.put(blob_str)
30         self.assertEqual(blob_locator,
31                          '7fc7c53b45e53926ba52821140fef396+6',
32                          ('wrong locator from Keep.put(<binarydata>):' +
33                           blob_locator))
34         self.assertEqual(arvados.Keep.get(blob_locator),
35                          blob_str,
36                          'wrong content from Keep.get(md5(<binarydata>))')
37
38 class KeepLongBinaryRWTest(KeepTestCase):
39     def runTest(self):
40         blob_str = '\xff\xfe\xfd\xfc\x00\x01\x02\x03'
41         for i in range(0,23):
42             blob_str = blob_str + blob_str
43         blob_locator = arvados.Keep.put(blob_str)
44         self.assertEqual(blob_locator,
45                          '84d90fc0d8175dd5dcfab04b999bc956+67108864',
46                          ('wrong locator from Keep.put(<binarydata>): ' +
47                           blob_locator))
48         self.assertEqual(arvados.Keep.get(blob_locator),
49                          blob_str,
50                          'wrong content from Keep.get(md5(<binarydata>))')
51
52 class KeepSingleCopyRWTest(KeepTestCase):
53     def runTest(self):
54         blob_str = '\xff\xfe\xfd\xfc\x00\x01\x02\x03'
55         blob_locator = arvados.Keep.put(blob_str, copies=1)
56         self.assertEqual(blob_locator,
57                          'c902006bc98a3eb4a3663b65ab4a6fab+8',
58                          ('wrong locator from Keep.put(<binarydata>): ' +
59                           blob_locator))
60         self.assertEqual(arvados.Keep.get(blob_locator),
61                          blob_str,
62                          'wrong content from Keep.get(md5(<binarydata>))')