Merge branch '8784-dir-listings'
[arvados.git] / sdk / python / tests / test_pipeline_template.py
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: Apache-2.0
4
5 from __future__ import absolute_import
6 # usage example:
7 #
8 # ARVADOS_API_TOKEN=abc ARVADOS_API_HOST=arvados.local python -m unittest discover
9
10 import unittest
11 import arvados
12 import apiclient
13 from . import run_test_server
14
15 class PipelineTemplateTest(run_test_server.TestCaseWithServers):
16     MAIN_SERVER = {}
17     KEEP_SERVER = {}
18
19     def runTest(self):
20         run_test_server.authorize_with("admin")
21         pt_uuid = arvados.api('v1').pipeline_templates().create(
22             body={'name':__file__}
23             ).execute()['uuid']
24         self.assertEqual(len(pt_uuid), 27,
25                          'Unexpected format of pipeline template UUID ("%s")'
26                          % pt_uuid)
27         components = {
28             'x': 'x',
29             '-x-': [1,2,{'foo':'bar'}],
30             'Boggis': {'Bunce': '[\'Bean\']'},
31             'SpassBox': True,
32             'spass_box': False,
33             'spass-box': [True, 'Maybe', False]
34             }
35         update_response = arvados.api('v1').pipeline_templates().update(
36             uuid=pt_uuid,
37             body={'components':components}
38             ).execute()
39         self.assertEqual('uuid' in update_response, True,
40                          'update() response did not include a uuid')
41         self.assertEqual(update_response['uuid'], pt_uuid,
42                          'update() response has a different uuid (%s, not %s)'
43                          % (update_response['uuid'], pt_uuid))
44         self.assertEqual(update_response['name'], __file__,
45                          'update() response has a different name (%s, not %s)'
46                          % (update_response['name'], __file__))
47         get_response = arvados.api('v1').pipeline_templates().get(
48             uuid=pt_uuid
49             ).execute()
50         self.assertEqual(get_response['components'], components,
51                          'components got munged by server (%s -> %s)'
52                          % (components, update_response['components']))
53         delete_response = arvados.api('v1').pipeline_templates().delete(
54             uuid=pt_uuid
55             ).execute()
56         self.assertEqual(delete_response['uuid'], pt_uuid,
57                          'delete() response has wrong uuid (%s, not %s)'
58                          % (delete_response['uuid'], pt_uuid))
59         with self.assertRaises(apiclient.errors.HttpError):
60             geterror_response = arvados.api('v1').pipeline_templates().get(
61                 uuid=pt_uuid
62                 ).execute()