test API update semantics, confirm put/get cycle preserves components{} hash
[arvados.git] / sdk / python / test_pipeline_template.py
1 # usage example:
2 #
3 # ARVADOS_API_TOKEN=abc ARVADOS_API_HOST=arvados.local python -m unittest discover
4
5 import unittest
6 import arvados
7 import apiclient
8
9 class PipelineTemplateTest(unittest.TestCase):
10     def runTest(self):
11         pt_uuid = arvados.service.pipeline_templates().create(
12             body={'name':__file__}
13             ).execute()['uuid']
14         self.assertEqual(len(pt_uuid), 27,
15                          'Unexpected format of pipeline template UUID ("%s")'
16                          % pt_uuid)
17         components = {
18             'x': 'x',
19             '-x-': [1,2,{'foo':'bar'}],
20             'Boggis': {'Bunce': '[\'Bean\']'},
21             'SpassBox': True,
22             'spass_box': False,
23             'spass-box': [True, 'Maybe', False]
24             }
25         update_response = arvados.service.pipeline_templates().update(
26             uuid=pt_uuid,
27             body={'components':components}
28             ).execute()
29         self.assertEqual('uuid' in update_response, True,
30                          'update() response did not include a uuid')
31         self.assertEqual(update_response['uuid'], pt_uuid,
32                          'update() response has a different uuid (%s, not %s)'
33                          % (update_response['uuid'], pt_uuid))
34         self.assertEqual(update_response['name'], __file__,
35                          'update() response has a different name (%s, not %s)'
36                          % (update_response['name'], __file__))
37         get_response = arvados.service.pipeline_templates().get(
38             uuid=pt_uuid
39             ).execute()
40         self.assertEqual(get_response['components'], components,
41                          'components got munged by server (%s -> %s)'
42                          % (components, update_response['components']))
43         delete_response = arvados.service.pipeline_templates().delete(
44             uuid=pt_uuid
45             ).execute()
46         self.assertEqual(delete_response['uuid'], pt_uuid,
47                          'delete() response has wrong uuid (%s, not %s)'
48                          % (delete_response['uuid'], pt_uuid))
49         with self.assertRaises(apiclient.errors.HttpError):
50             geterror_response = arvados.service.pipeline_templates().get(
51                 uuid=pt_uuid
52                 ).execute()