2872: Make infinite scroll work with regular window scrollbars too.
[arvados.git] / sdk / python / test_cmdline.py
1 import os
2 import subprocess
3 import unittest
4 import tempfile
5 import yaml
6
7 import apiclient
8 import arvados
9 import run_test_server
10
11 # ArvPutTest exercises arv-put behavior on the command line.
12 #
13 # Existing tests:
14 #
15 # ArvPutSignedManifest runs "arv-put foo" and then attempts to get
16 #   the newly created manifest from the API server, testing to confirm
17 #   that the block locators in the returned manifest are signed.
18 #
19 # TODO(twp): decide whether this belongs better in test_collections,
20 # since it chiefly exercises behavior in arvados.collection.CollectionWriter.
21 # Leaving it here for the time being because we may want to add more
22 # tests for arv-put command line behavior.
23
24 class ArvPutTest(unittest.TestCase):
25     @classmethod
26     def setUpClass(cls):
27         try:
28             del os.environ['KEEP_LOCAL_STORE']
29         except KeyError:
30             pass
31
32         # Use the blob_signing_key from the Rails "test" configuration
33         # to provision the Keep server.
34         with open(os.path.join(os.path.dirname(__file__),
35                                run_test_server.ARV_API_SERVER_DIR,
36                                "config",
37                                "application.yml")) as f:
38             rails_config = yaml.load(f.read())
39         config_blob_signing_key = rails_config["test"]["blob_signing_key"]
40         run_test_server.run()
41         run_test_server.run_keep(blob_signing_key=config_blob_signing_key,
42                                  enforce_permissions=True)
43
44     @classmethod
45     def tearDownClass(cls):
46         run_test_server.stop()
47         run_test_server.stop_keep()
48
49     def test_ArvPutSignedManifest(self):
50         run_test_server.authorize_with('active')
51         for v in ["ARVADOS_API_HOST",
52                   "ARVADOS_API_HOST_INSECURE",
53                   "ARVADOS_API_TOKEN"]:
54             os.environ[v] = arvados.config.settings()[v]
55
56         # Before doing anything, demonstrate that the collection
57         # we're about to create is not present in our test fixture.
58         api = arvados.api('v1', cache=False)
59         manifest_uuid = "00b4e9f40ac4dd432ef89749f1c01e74+47"
60         with self.assertRaises(apiclient.errors.HttpError):
61             notfound = api.collections().get(uuid=manifest_uuid).execute()
62         
63         datadir = tempfile.mkdtemp()
64         with open(os.path.join(datadir, "foo"), "w") as f:
65             f.write("The quick brown fox jumped over the lazy dog")
66         p = subprocess.Popen(["./bin/arv-put", datadir],
67                              stdout=subprocess.PIPE)
68         (arvout, arverr) = p.communicate()
69         self.assertEqual(p.returncode, 0)
70         self.assertEqual(arverr, None)
71         self.assertEqual(arvout.strip(), manifest_uuid)
72
73         # The manifest text stored in the API server under the same
74         # manifest UUID must use signed locators.
75         c = api.collections().get(uuid=manifest_uuid).execute()
76         self.assertRegexpMatches(
77             c['manifest_text'],
78             r'^\. 08a008a01d498c404b0c30852b39d3b8\+44\+A[0-9a-f]+@[0-9a-f]+ 0:44:foo\n')
79
80         os.remove(os.path.join(datadir, "foo"))
81         os.rmdir(datadir)