11 # ArvPutTest exercises arv-put behavior on the command line.
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.
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.
24 class ArvPutTest(unittest.TestCase):
28 del os.environ['KEEP_LOCAL_STORE']
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,
37 "application.yml")) as f:
38 rails_config = yaml.load(f.read())
39 config_blob_signing_key = rails_config["test"]["blob_signing_key"]
41 run_test_server.run_keep(blob_signing_key=config_blob_signing_key,
42 enforce_permissions=True)
45 def tearDownClass(cls):
46 run_test_server.stop()
47 run_test_server.stop_keep()
49 def test_ArvPutSignedManifest(self):
50 run_test_server.authorize_with('active')
51 for v in ["ARVADOS_API_HOST",
52 "ARVADOS_API_HOST_INSECURE",
54 os.environ[v] = arvados.config.settings()[v]
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()
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)
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(
78 r'^\. 08a008a01d498c404b0c30852b39d3b8\+44\+A[0-9a-f]+@[0-9a-f]+ 0:44:foo\n')
80 os.remove(os.path.join(datadir, "foo"))