9118: Fix arv-put crash when finishing without output. 9118-arv-put-nameerror-fix-wip
authorBrett Smith <brett@curoverse.com>
Mon, 2 May 2016 21:47:45 +0000 (17:47 -0400)
committerBrett Smith <brett@curoverse.com>
Mon, 2 May 2016 22:54:17 +0000 (18:54 -0400)
sdk/python/arvados/commands/put.py
sdk/python/tests/test_arv_put.py

index d3510db7c5d52cf297f25ca3ac229f3b87c65056..dbf3c76013a3b371534e1c64c7ec0409387fb1cb 100644 (file)
@@ -548,9 +548,12 @@ def main(arguments=None, stdout=sys.stdout, stderr=sys.stderr):
             status = 1
 
     # Print the locator (uuid) of the new collection.
-    stdout.write(output)
-    if not output.endswith('\n'):
-        stdout.write('\n')
+    try:
+        stdout.write(output)
+        if not output.endswith('\n'):
+            stdout.write('\n')
+    except NameError:
+        status = status or 1
 
     for sigcode, orig_handler in orig_signal_handlers.items():
         signal.signal(sigcode, orig_handler)
index a6c1233067bc6c035a217fab5ed88174dd58ddd9..e64d91474170ce688780c3ab94ea3ae6bb69bbfb 100644 (file)
@@ -19,7 +19,7 @@ from cStringIO import StringIO
 import arvados
 import arvados.commands.put as arv_put
 
-from arvados_testutil import ArvadosBaseTestCase
+from arvados_testutil import ArvadosBaseTestCase, fake_httplib2_response
 import run_test_server
 
 class ArvadosPutResumeCacheTest(ArvadosBaseTestCase):
@@ -460,6 +460,20 @@ class ArvadosPutTest(run_test_server.TestCaseWithServers, ArvadosBaseTestCase):
                           self.call_main_with_args,
                           ['--project-uuid', self.Z_UUID, '--stream'])
 
+    def test_api_error_handling(self):
+        collections_mock = mock.Mock(name='arv.collections()')
+        coll_create_mock = collections_mock().create().execute
+        coll_create_mock.side_effect = arvados.errors.ApiError(
+            fake_httplib2_response(403), '{}')
+        arv_put.api_client = arvados.api('v1')
+        arv_put.api_client.collections = collections_mock
+        with self.assertRaises(SystemExit) as exc_test:
+            self.call_main_with_args(['/dev/null'])
+        self.assertLess(0, exc_test.exception.args[0])
+        self.assertLess(0, coll_create_mock.call_count)
+        self.assertEqual("", self.main_stdout.getvalue())
+
+
 class ArvPutIntegrationTest(run_test_server.TestCaseWithServers,
                             ArvadosBaseTestCase):
     def _getKeepServerConfig():