/usr/lib/python2.7/dist-packages/ironicclient/tests/unit/v1/test_client.py is in python-ironicclient 2.2.0-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | # Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import mock
from ironicclient.common import filecache
from ironicclient.common import http
from ironicclient import exc
from ironicclient.tests.unit import utils
from ironicclient.v1 import client
@mock.patch.object(http, '_construct_http_client', autospec=True)
class ClientTest(utils.BaseTestCase):
def test_client_user_api_version(self, http_client_mock):
endpoint = 'http://ironic:6385'
token = 'safe_token'
os_ironic_api_version = '1.15'
client.Client(endpoint, token=token,
os_ironic_api_version=os_ironic_api_version)
http_client_mock.assert_called_once_with(
endpoint, token=token,
os_ironic_api_version=os_ironic_api_version,
api_version_select_state='user')
def test_client_user_api_version_with_downgrade(self, http_client_mock):
endpoint = 'http://ironic:6385'
token = 'safe_token'
os_ironic_api_version = '1.15'
client.Client(endpoint, token=token,
os_ironic_api_version=os_ironic_api_version,
allow_api_version_downgrade=True)
http_client_mock.assert_called_once_with(
endpoint, token=token,
os_ironic_api_version=os_ironic_api_version,
api_version_select_state='default')
def test_client_user_api_version_latest_with_downgrade(self,
http_client_mock):
endpoint = 'http://ironic:6385'
token = 'safe_token'
os_ironic_api_version = 'latest'
self.assertRaises(ValueError, client.Client, endpoint,
token=token, allow_api_version_downgrade=True,
os_ironic_api_version=os_ironic_api_version)
@mock.patch.object(filecache, 'retrieve_data', autospec=True)
def test_client_cache_api_version(self, cache_mock, http_client_mock):
endpoint = 'http://ironic:6385'
token = 'safe_token'
os_ironic_api_version = '1.15'
cache_mock.return_value = os_ironic_api_version
client.Client(endpoint, token=token)
cache_mock.assert_called_once_with(host='ironic', port='6385')
http_client_mock.assert_called_once_with(
endpoint, token=token,
os_ironic_api_version=os_ironic_api_version,
api_version_select_state='cached')
@mock.patch.object(filecache, 'retrieve_data', autospec=True)
def test_client_default_api_version(self, cache_mock, http_client_mock):
endpoint = 'http://ironic:6385'
token = 'safe_token'
cache_mock.return_value = None
client.Client(endpoint, token=token)
cache_mock.assert_called_once_with(host='ironic', port='6385')
http_client_mock.assert_called_once_with(
endpoint, token=token,
os_ironic_api_version=client.DEFAULT_VER,
api_version_select_state='default')
def test_client_cache_version_no_endpoint_as_arg(self, http_client_mock):
self.assertRaises(exc.EndpointException,
client.Client,
session='fake_session',
insecure=True,
endpoint_override='http://ironic:6385')
def test_client_initialized_managers(self, http_client_mock):
cl = client.Client('http://ironic:6385', token='safe_token',
os_ironic_api_version='1.15')
self.assertIsInstance(cl.node, client.node.NodeManager)
self.assertIsInstance(cl.port, client.port.PortManager)
self.assertIsInstance(cl.driver, client.driver.DriverManager)
self.assertIsInstance(cl.chassis, client.chassis.ChassisManager)
def test_negotiate_api_version(self, http_client_mock):
endpoint = 'http://ironic:6385'
token = 'safe_token'
os_ironic_api_version = 'latest'
cl = client.Client(endpoint, token=token,
os_ironic_api_version=os_ironic_api_version)
cl.negotiate_api_version()
http_client_mock.assert_called_once_with(
endpoint, api_version_select_state='user',
os_ironic_api_version='latest', token=token)
# TODO(TheJulia): We should verify that negotiate_version
# is being called in the client and returns a version,
# although mocking might need to be restrutured to
# properly achieve that.
|