|
| 1 | +# Copyright 2013 OpenStack, LLC. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | +# not use this file except in compliance with the License. You may obtain |
| 5 | +# a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | +# License for the specific language governing permissions and limitations |
| 13 | +# under the License. |
| 14 | +# |
| 15 | + |
| 16 | +import mock |
| 17 | + |
| 18 | +from openstackclient.common import clientmanager |
| 19 | +from openstackclient.compute import client as compute_client |
| 20 | +from tests import utils |
| 21 | + |
| 22 | + |
| 23 | +class FakeClient(object): |
| 24 | + def __init__(self, endpoint=None, **kwargs): |
| 25 | + self.client = mock.MagicMock() |
| 26 | + self.servers = mock.MagicMock() |
| 27 | + |
| 28 | + self.client.auth_url = kwargs['auth_url'] |
| 29 | + |
| 30 | + |
| 31 | +class TestCompute(utils.TestCase): |
| 32 | + def setUp(self): |
| 33 | + super(TestCompute, self).setUp() |
| 34 | + |
| 35 | + self.auth_token = "foobar" |
| 36 | + self.auth_url = "http://0.0.0.0" |
| 37 | + |
| 38 | + api_version = {"compute": "2"} |
| 39 | + |
| 40 | + compute_client.API_VERSIONS = { |
| 41 | + "2": "tests.compute.test_compute.FakeClient" |
| 42 | + } |
| 43 | + |
| 44 | + self.cm = clientmanager.ClientManager(token=self.auth_token, |
| 45 | + url=self.auth_url, |
| 46 | + auth_url=self.auth_url, |
| 47 | + api_version=api_version) |
| 48 | + |
| 49 | + def test_make_client(self): |
| 50 | + test_servers = [ |
| 51 | + ["id 1", "name 1", "status 1", "networks 1"], |
| 52 | + ["id 2", "name 2", "status 2", "networks 2"] |
| 53 | + ] |
| 54 | + |
| 55 | + self.cm.compute.servers.list.return_value = test_servers |
| 56 | + |
| 57 | + self.assertEqual(self.cm.compute.servers.list(), test_servers) |
| 58 | + self.assertEqual(self.cm.compute.client.auth_token, self.auth_token) |
| 59 | + self.assertEqual(self.cm.compute.client.auth_url, self.auth_url) |
0 commit comments