~ubuntu-branches/ubuntu/wily/python-oslo.vmware/wily

« back to all changes in this revision

Viewing changes to tests/test_vim.py

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2015-08-11 09:25:22 UTC
  • mfrom: (1.1.12) (2.1.3 experimental)
  • Revision ID: package-import@ubuntu.com-20150811092522-6epbeuzn6a0jt750
Tags: 1.18.0-2ubuntu1
* Resync with Debian experimental.
* d/pydist-overrides: Map suds-jurko -> suds to ease backporting.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (c) 2014 VMware, Inc.
2
 
# All Rights Reserved.
3
 
#
4
 
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
5
 
#    not use this file except in compliance with the License. You may obtain
6
 
#    a copy of the License at
7
 
#
8
 
#         http://www.apache.org/licenses/LICENSE-2.0
9
 
#
10
 
#    Unless required by applicable law or agreed to in writing, software
11
 
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
 
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
 
#    License for the specific language governing permissions and limitations
14
 
#    under the License.
15
 
 
16
 
"""
17
 
Unit tests for classes to invoke VMware VI SOAP calls.
18
 
"""
19
 
 
20
 
import mock
21
 
from oslo_i18n import fixture as i18n_fixture
22
 
 
23
 
from oslo.vmware import exceptions
24
 
from oslo.vmware import vim
25
 
from oslo_vmware._i18n import _
26
 
from tests import base
27
 
 
28
 
 
29
 
class VimTest(base.TestCase):
30
 
    """Test class for Vim."""
31
 
 
32
 
    def setUp(self):
33
 
        super(VimTest, self).setUp()
34
 
        patcher = mock.patch('suds.client.Client')
35
 
        self.addCleanup(patcher.stop)
36
 
        self.SudsClientMock = patcher.start()
37
 
        self.useFixture(i18n_fixture.ToggleLazy(True))
38
 
 
39
 
    @mock.patch.object(vim.Vim, '__getattr__', autospec=True)
40
 
    def test_service_content(self, getattr_mock):
41
 
        getattr_ret = mock.Mock()
42
 
        getattr_mock.side_effect = lambda *args: getattr_ret
43
 
        vim_obj = vim.Vim()
44
 
        vim_obj.service_content
45
 
        getattr_mock.assert_called_once_with(vim_obj, 'RetrieveServiceContent')
46
 
        getattr_ret.assert_called_once_with('ServiceInstance')
47
 
        self.assertEqual(self.SudsClientMock.return_value, vim_obj.client)
48
 
        self.assertEqual(getattr_ret.return_value, vim_obj.service_content)
49
 
 
50
 
    def test_exception_summary_exception_as_list(self):
51
 
        # assert that if a list is fed to the VimException object
52
 
        # that it will error.
53
 
        self.assertRaises(ValueError,
54
 
                          exceptions.VimException,
55
 
                          [], ValueError('foo'))
56
 
 
57
 
    def test_exception_summary_string(self):
58
 
        e = exceptions.VimException(_("string"), ValueError("foo"))
59
 
        string = str(e)
60
 
        self.assertEqual("string\nCause: foo", string)
61
 
 
62
 
    def test_vim_fault_exception_string(self):
63
 
        self.assertRaises(ValueError,
64
 
                          exceptions.VimFaultException,
65
 
                          "bad", ValueError("argument"))
66
 
 
67
 
    def test_vim_fault_exception(self):
68
 
        vfe = exceptions.VimFaultException([ValueError("example")], _("cause"))
69
 
        string = str(vfe)
70
 
        self.assertEqual("cause\nFaults: [ValueError('example',)]", string)
71
 
 
72
 
    def test_vim_fault_exception_with_cause_and_details(self):
73
 
        vfe = exceptions.VimFaultException([ValueError("example")],
74
 
                                           "MyMessage",
75
 
                                           "FooBar",
76
 
                                           {'foo': 'bar'})
77
 
        string = str(vfe)
78
 
        self.assertEqual("MyMessage\n"
79
 
                         "Cause: FooBar\n"
80
 
                         "Faults: [ValueError('example',)]\n"
81
 
                         "Details: {'foo': 'bar'}",
82
 
                         string)
83
 
 
84
 
    def test_configure_non_default_host_port(self):
85
 
        vim_obj = vim.Vim('https', 'www.test.com', 12345)
86
 
        self.assertEqual('https://www.test.com:12345/sdk/vimService.wsdl',
87
 
                         vim_obj.wsdl_url)
88
 
        self.assertEqual('https://www.test.com:12345/sdk',
89
 
                         vim_obj.soap_url)
90
 
 
91
 
    def test_configure_ipv6(self):
92
 
        vim_obj = vim.Vim('https', '::1')
93
 
        self.assertEqual('https://[::1]/sdk/vimService.wsdl',
94
 
                         vim_obj.wsdl_url)
95
 
        self.assertEqual('https://[::1]/sdk',
96
 
                         vim_obj.soap_url)
97
 
 
98
 
    def test_configure_ipv6_and_non_default_host_port(self):
99
 
        vim_obj = vim.Vim('https', '::1', 12345)
100
 
        self.assertEqual('https://[::1]:12345/sdk/vimService.wsdl',
101
 
                         vim_obj.wsdl_url)
102
 
        self.assertEqual('https://[::1]:12345/sdk',
103
 
                         vim_obj.soap_url)
104
 
 
105
 
    def test_configure_with_wsdl_url_override(self):
106
 
        vim_obj = vim.Vim('https', 'www.example.com',
107
 
                          wsdl_url='https://test.com/sdk/vimService.wsdl')
108
 
        self.assertEqual('https://test.com/sdk/vimService.wsdl',
109
 
                         vim_obj.wsdl_url)
110
 
        self.assertEqual('https://www.example.com/sdk', vim_obj.soap_url)