X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/f2c1db3480befa2c29a742313465e7cc9f2635b1..63cfe7a9b391e1a07c6c6c8b0fab10b1c875f1be:/sdk/python/tests/test_arv_get.py diff --git a/sdk/python/tests/test_arv_get.py b/sdk/python/tests/test_arv_get.py index 46c1a0e650..51746475da 100644 --- a/sdk/python/tests/test_arv_get.py +++ b/sdk/python/tests/test_arv_get.py @@ -1,6 +1,8 @@ from __future__ import absolute_import from future.utils import listitems import io +import os +import re import shutil import tempfile @@ -26,6 +28,7 @@ class ArvadosGetTestCase(run_test_server.TestCaseWithServers, shutil.rmtree(self.tempdir) def write_test_collection(self, + strip_manifest=False, contents = { 'foo.txt' : 'foo', 'bar.txt' : 'bar', @@ -36,7 +39,10 @@ class ArvadosGetTestCase(run_test_server.TestCaseWithServers, with c.open(path, 'wb') as f: f.write(data) c.save_new() - return (c.manifest_locator(), c.portable_data_hash(), c.manifest_text()) + + return (c.manifest_locator(), + c.portable_data_hash(), + c.manifest_text(strip=strip_manifest)) def run_get(self, args): self.stdout = tutil.BytesIO() @@ -64,19 +70,43 @@ class ArvadosGetTestCase(run_test_server.TestCaseWithServers, # Download the entire collection to the temp directory r = self.run_get(["{}/".format(self.col_loc), self.tempdir]) self.assertEqual(0, r) - with open("{}/foo.txt".format(self.tempdir), "r") as f: + with open(os.path.join(self.tempdir, "foo.txt"), "r") as f: self.assertEqual("foo", f.read()) - with open("{}/bar.txt".format(self.tempdir), "r") as f: + with open(os.path.join(self.tempdir, "bar.txt"), "r") as f: self.assertEqual("bar", f.read()) - with open("{}/subdir/baz.txt".format(self.tempdir), "r") as f: + with open(os.path.join(self.tempdir, "subdir", "baz.txt"), "r") as f: self.assertEqual("baz", f.read()) - def test_get_collection_manifest(self): - # Get the collection manifest + def test_get_collection_unstripped_manifest(self): + dummy_token = "+Axxxxxxx" + # Get the collection manifest by UUID r = self.run_get([self.col_loc, self.tempdir]) self.assertEqual(0, r) - with open("{}/{}".format(self.tempdir, self.col_loc), "r") as f: - self.assertEqual(self.col_manifest, f.read()) + m_from_collection = re.sub(r"\+A[0-9a-f@]+", dummy_token, self.col_manifest) + with open(os.path.join(self.tempdir, self.col_loc), "r") as f: + # Replace manifest tokens before comparison to avoid races + m_from_file = re.sub(r"\+A[0-9a-f@]+", dummy_token, f.read()) + self.assertEqual(m_from_collection, m_from_file) + # Get the collection manifest by PDH + r = self.run_get([self.col_pdh, self.tempdir]) + self.assertEqual(0, r) + with open(os.path.join(self.tempdir, self.col_pdh), "r") as f: + # Replace manifest tokens before comparison to avoid races + m_from_file = re.sub(r"\+A[0-9a-f@]+", dummy_token, f.read()) + self.assertEqual(m_from_collection, m_from_file) + + def test_get_collection_stripped_manifest(self): + col_loc, col_pdh, col_manifest = self.write_test_collection(strip_manifest=True) + # Get the collection manifest by UUID + r = self.run_get(['--strip-manifest', col_loc, self.tempdir]) + self.assertEqual(0, r) + with open(os.path.join(self.tempdir, col_loc), "r") as f: + self.assertEqual(col_manifest, f.read()) + # Get the collection manifest by PDH + r = self.run_get(['--strip-manifest', col_pdh, self.tempdir]) + self.assertEqual(0, r) + with open(os.path.join(self.tempdir, col_pdh), "r") as f: + self.assertEqual(col_manifest, f.read()) def test_invalid_collection(self): # Asking for an invalid collection should generate an error. @@ -97,10 +127,10 @@ class ArvadosGetTestCase(run_test_server.TestCaseWithServers, def test_preexistent_destination(self): # Asking to place a file with the same path as a local one should # generate an error and avoid overwrites. - with open("{}/foo.txt".format(self.tempdir), "w") as f: + with open(os.path.join(self.tempdir, "foo.txt"), "w") as f: f.write("another foo") r = self.run_get(["{}/foo.txt".format(self.col_loc), self.tempdir]) self.assertNotEqual(0, r) - with open("{}/foo.txt".format(self.tempdir), "r") as f: + with open(os.path.join(self.tempdir, "foo.txt"), "r") as f: self.assertEqual("another foo", f.read())