Do not blindly overwrite GOPATH if it exists.
[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 import run_test_server
9
10 class KeepTestCase(unittest.TestCase):
11     @classmethod
12     def setUpClass(cls):
13         try:
14             del os.environ['KEEP_LOCAL_STORE']
15         except KeyError:
16             pass
17         run_test_server.run()
18         run_test_server.run_keep()
19
20     @classmethod
21     def tearDownClass(cls):
22         run_test_server.stop()
23         run_test_server.stop_keep()
24
25     def test_KeepBasicRWTest(self):
26         foo_locator = arvados.Keep.put('foo')
27         self.assertEqual(foo_locator,
28                          'acbd18db4cc2f85cedef654fccc4a4d8+3',
29                          'wrong md5 hash from Keep.put("foo"): ' + foo_locator)
30         self.assertEqual(arvados.Keep.get(foo_locator),
31                          'foo',
32                          'wrong content from Keep.get(md5("foo"))')
33
34     def test_KeepBinaryRWTest(self):
35         blob_str = '\xff\xfe\xf7\x00\x01\x02'
36         blob_locator = arvados.Keep.put(blob_str)
37         self.assertEqual(blob_locator,
38                          '7fc7c53b45e53926ba52821140fef396+6',
39                          ('wrong locator from Keep.put(<binarydata>):' +
40                           blob_locator))
41         self.assertEqual(arvados.Keep.get(blob_locator),
42                          blob_str,
43                          'wrong content from Keep.get(md5(<binarydata>))')
44
45     def test_KeepLongBinaryRWTest(self):
46         blob_str = '\xff\xfe\xfd\xfc\x00\x01\x02\x03'
47         for i in range(0,23):
48             blob_str = blob_str + blob_str
49         blob_locator = arvados.Keep.put(blob_str)
50         self.assertEqual(blob_locator,
51                          '84d90fc0d8175dd5dcfab04b999bc956+67108864',
52                          ('wrong locator from Keep.put(<binarydata>): ' +
53                           blob_locator))
54         self.assertEqual(arvados.Keep.get(blob_locator),
55                          blob_str,
56                          'wrong content from Keep.get(md5(<binarydata>))')
57
58     def test_KeepSingleCopyRWTest(self):
59         blob_str = '\xff\xfe\xfd\xfc\x00\x01\x02\x03'
60         blob_locator = arvados.Keep.put(blob_str, copies=1)
61         self.assertEqual(blob_locator,
62                          'c902006bc98a3eb4a3663b65ab4a6fab+8',
63                          ('wrong locator from Keep.put(<binarydata>): ' +
64                           blob_locator))
65         self.assertEqual(arvados.Keep.get(blob_locator),
66                          blob_str,
67                          'wrong content from Keep.get(md5(<binarydata>))')