Files
python-solumclient/solumclient/tests/common/test_auth.py
Noorul Islam K M 40ffc17c85 Fix client error handling
Whenever server returns error, an exception is thrown. This is because pecan is
returning json attributes that is not recongnized by apiclient. So fix apiclient
to accept pecan response.

Fixes-bug: #1293379

Change-Id: I5d8be574143c808a8e236d19c899358d784fc245
2014-03-26 09:04:40 +05:30

70 lines
2.6 KiB
Python

# Copyright 2013 - Noorul Islam K M
#
# 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.
from keystoneclient.v2_0 import client as ksclient
import mock
from solumclient.common import auth
from solumclient.common import client
from solumclient.tests import base
@mock.patch.object(ksclient, 'Client')
class KeystoneAuthPluginTest(base.TestCase):
def setUp(self):
super(KeystoneAuthPluginTest, self).setUp()
plugin = auth.KeystoneAuthPlugin(
username="fake-username",
password="fake-password",
tenant_name="fake-tenant-name",
auth_url="http://auth",
endpoint="http://solum")
self.cs = client.HTTPClient(auth_plugin=plugin)
def test_authenticate(self, mock_ksclient):
self.cs.authenticate()
mock_ksclient.assert_called_with(
username="fake-username",
password="fake-password",
tenant_name="fake-tenant-name",
auth_url="http://auth")
def test_token_and_endpoint(self, mock_ksclient):
self.cs.authenticate()
(token, endpoint) = self.cs.auth_plugin.token_and_endpoint(
"fake-endpoint-type", "fake-service-type")
self.assertIsInstance(token, mock.MagicMock)
self.assertEqual(endpoint, "http://solum")
def test_token_and_endpoint_before_auth(self, mock_ksclient):
(token, endpoint) = self.cs.auth_plugin.token_and_endpoint(
"fake-endpoint-type", "fake-service-type")
self.assertIsNone(token, None)
self.assertIsNone(endpoint, None)
@mock.patch.object(ksclient, 'Client')
class KeystoneAuthPluginTokenTest(base.TestCase):
def test_token_and_endpoint(self, mock_ksclient):
plugin = auth.KeystoneAuthPlugin(
token="fake-token",
endpoint="http://solum")
cs = client.HTTPClient(auth_plugin=plugin)
cs.authenticate()
(token, endpoint) = cs.auth_plugin.token_and_endpoint(
"fake-endpoint-type", "fake-service-type")
self.assertEqual(token, 'fake-token')
self.assertEqual(endpoint, 'http://solum')