~ubuntu-branches/ubuntu/vivid/python-heatclient/vivid

« back to all changes in this revision

Viewing changes to heatclient/tests/test_software_configs.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2014-03-06 17:41:15 UTC
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: package-import@ubuntu.com-20140306174115-ecpzxbyb30tl5i7a
Tags: upstream-0.2.8
ImportĀ upstreamĀ versionĀ 0.2.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Licensed under the Apache License, Version 2.0 (the "License"); you may
 
2
# not use this file except in compliance with the License. You may obtain
 
3
# a copy of the License at
 
4
#
 
5
#      http://www.apache.org/licenses/LICENSE-2.0
 
6
#
 
7
# Unless required by applicable law or agreed to in writing, software
 
8
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
9
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
10
# License for the specific language governing permissions and limitations
 
11
# under the License.
 
12
 
 
13
import mock
 
14
import testtools
 
15
 
 
16
from heatclient.v1.software_configs import SoftwareConfig
 
17
from heatclient.v1.software_configs import SoftwareConfigManager
 
18
 
 
19
 
 
20
class SoftwareConfigTest(testtools.TestCase):
 
21
 
 
22
    def setUp(self):
 
23
        super(SoftwareConfigTest, self).setUp()
 
24
        config_id = 'bca6871d-86c0-4aff-b792-58a1f6947b57'
 
25
        self.config = SoftwareConfig(mock.MagicMock(), info={'id': config_id})
 
26
        self.config_id = config_id
 
27
 
 
28
    def test_delete(self):
 
29
        self.config.manager.delete.return_value = None
 
30
        self.assertIsNone(self.config.delete())
 
31
        kwargs = self.config.manager.delete.call_args[1]
 
32
        self.assertEqual(self.config_id, kwargs['config_id'])
 
33
 
 
34
    def test_data(self):
 
35
        self.assertEqual(
 
36
            "<SoftwareConfig {'id': '%s'}>" % self.config_id, str(self.config))
 
37
        self.config.manager.data.return_value = None
 
38
        self.config.data(name='config_mysql')
 
39
        kwargs = self.config.manager.data.call_args[1]
 
40
        self.assertEqual('config_mysql', kwargs['name'])
 
41
 
 
42
 
 
43
class SoftwareConfigManagerTest(testtools.TestCase):
 
44
 
 
45
    def setUp(self):
 
46
        super(SoftwareConfigManagerTest, self).setUp()
 
47
        self.manager = SoftwareConfigManager(mock.MagicMock())
 
48
 
 
49
    def test_get(self):
 
50
        config_id = 'bca6871d-86c0-4aff-b792-58a1f6947b57'
 
51
        data = {
 
52
            'id': config_id,
 
53
            'name': 'config_mysql',
 
54
            'group': 'Heat::Shell',
 
55
            'config': '#!/bin/bash',
 
56
            'inputs': [],
 
57
            'ouputs': [],
 
58
            'options': []}
 
59
 
 
60
        self.manager.client.json_request.return_value = (
 
61
            {}, {'software_config': data})
 
62
        result = self.manager.get(config_id=config_id)
 
63
        self.assertEqual(SoftwareConfig(self.manager, data), result)
 
64
        call_args = self.manager.client.json_request.call_args
 
65
        self.assertEqual(
 
66
            ('GET', '/software_configs/%s' % config_id), *call_args)
 
67
 
 
68
    def test_create(self):
 
69
        config_id = 'bca6871d-86c0-4aff-b792-58a1f6947b57'
 
70
        body = {
 
71
            'name': 'config_mysql',
 
72
            'group': 'Heat::Shell',
 
73
            'config': '#!/bin/bash',
 
74
            'inputs': [],
 
75
            'ouputs': [],
 
76
            'options': []}
 
77
        data = body.copy()
 
78
        data['id'] = config_id
 
79
        self.manager.client.json_request.return_value = (
 
80
            {}, {'software_config': data})
 
81
        result = self.manager.create(**body)
 
82
        self.assertEqual(SoftwareConfig(self.manager, data), result)
 
83
        args, kargs = self.manager.client.json_request.call_args
 
84
        self.assertEqual('POST', args[0])
 
85
        self.assertEqual('/software_configs', args[1])
 
86
        self.assertEqual({'data': body}, kargs)
 
87
 
 
88
    def test_delete(self):
 
89
        config_id = 'bca6871d-86c0-4aff-b792-58a1f6947b57'
 
90
        self.manager.delete(config_id)
 
91
        call_args = self.manager.client.delete.call_args
 
92
        self.assertEqual(
 
93
            ('/software_configs/%s' % config_id,), *call_args)