Ignore fewer PEP8/flake8 rules
Reasons: - code should be pythonicaly clean, that is why number of ignored rules should reduced Changes: - E125, F811, H102, H103, F201, H23, H302, F841, H301, H702, H703 rules are now enabled Change-Id: Ibf4025162244d3c2f1278b49a76ec1527a729042
This commit is contained in:
parent
7499015e51
commit
69c865695f
@ -1,3 +1,21 @@
|
||||
# Copyright 2011 OpenStack Foundation
|
||||
# Copyright 2013 Rackspace Hosting
|
||||
# Copyright 2013 Hewlett-Packard Development Company, L.P.
|
||||
# Copyright 2013 Mirantis Inc.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
extensions = [
|
||||
|
5
tox.ini
5
tox.ini
@ -36,6 +36,7 @@ commands = python setup.py testr --coverage --testr-args='{posargs}'
|
||||
sphinx-build -b html {toxinidir}/docs/source {envtmpdir}/html
|
||||
|
||||
[flake8]
|
||||
ignore = E125,F403,F811,F821,F841,H102,H103,H201,H202,H23,H301,H306,H401,H402,H403,H404,H702,H703
|
||||
|
||||
ignore = F401,F403,F821,H202,H306,H401,H402,H403,H404
|
||||
show-source = True
|
||||
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build
|
||||
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build,
|
||||
|
@ -36,9 +36,9 @@ except ImportError:
|
||||
import urllib.parse as urlparse
|
||||
|
||||
try:
|
||||
from eventlet import sleep
|
||||
import eventlet as sleep_lib
|
||||
except ImportError:
|
||||
from time import sleep
|
||||
import time as sleep_lib
|
||||
|
||||
try:
|
||||
import json
|
||||
@ -201,7 +201,7 @@ class HTTPClient(object):
|
||||
self._logger.debug(
|
||||
"Failed attempt(%s of %s), retrying in %s seconds" %
|
||||
(attempts, self.retries, backoff))
|
||||
sleep(backoff)
|
||||
sleep_lib.sleep(backoff)
|
||||
backoff *= 2
|
||||
|
||||
def get(self, url, **kwargs):
|
||||
|
@ -13,7 +13,7 @@
|
||||
# under the License.
|
||||
|
||||
from __future__ import print_function
|
||||
from six import string_types
|
||||
import six
|
||||
from troveclient.compat import exceptions
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@ def get_authenticator_cls(cls_or_name):
|
||||
"""Factory method to retrieve Authenticator class."""
|
||||
if isinstance(cls_or_name, type):
|
||||
return cls_or_name
|
||||
elif isinstance(cls_or_name, string_types):
|
||||
elif isinstance(cls_or_name, six.string_types):
|
||||
if cls_or_name == "keystone":
|
||||
return KeyStoneV2Authenticator
|
||||
elif cls_or_name == "rax":
|
||||
|
@ -64,7 +64,7 @@ class InstanceCommands(common.AuthedCommandsBase):
|
||||
def delete(self):
|
||||
"""Delete the specified instance"""
|
||||
self._require('id')
|
||||
print self.dbaas.instances.delete(self.id)
|
||||
print(self.dbaas.instances.delete(self.id))
|
||||
|
||||
def get(self):
|
||||
"""Get details for the specified instance"""
|
||||
@ -126,12 +126,12 @@ class DatabaseCommands(common.AuthedCommandsBase):
|
||||
"""Create a database"""
|
||||
self._require('id', 'name')
|
||||
databases = [{'name': self.name}]
|
||||
print self.dbaas.databases.create(self.id, databases)
|
||||
print(self.dbaas.databases.create(self.id, databases))
|
||||
|
||||
def delete(self):
|
||||
"""Delete a database"""
|
||||
self._require('id', 'name')
|
||||
print self.dbaas.databases.delete(self.id, self.name)
|
||||
print(self.dbaas.databases.delete(self.id, self.name))
|
||||
|
||||
def list(self):
|
||||
"""List the databases"""
|
||||
@ -235,9 +235,9 @@ class RootCommands(common.AuthedCommandsBase):
|
||||
self._require('id')
|
||||
try:
|
||||
user, password = self.dbaas.root.create(self.id)
|
||||
print "User:\t\t%s\nPassword:\t%s" % (user, password)
|
||||
except:
|
||||
print sys.exc_info()[1]
|
||||
print("User:\t\t%s\nPassword:\t%s" % (user, password))
|
||||
except Exception:
|
||||
print(sys.exc_info()[1])
|
||||
|
||||
def enabled(self):
|
||||
"""Check the instance for root access"""
|
||||
@ -387,7 +387,7 @@ def main():
|
||||
except Exception as ex:
|
||||
if options.debug:
|
||||
raise
|
||||
print ex
|
||||
print(ex)
|
||||
else:
|
||||
getattr(command_object, action)()
|
||||
else:
|
||||
|
@ -146,7 +146,7 @@ class TroveHTTPClient(httplib2.Http):
|
||||
try:
|
||||
req_body = json.dumps(json.loads(kwargs['body']),
|
||||
sort_keys=True, indent=4)
|
||||
except:
|
||||
except Exception:
|
||||
req_body = kwargs['body']
|
||||
_logger.debug("BODY: %s\n" % (req_body))
|
||||
else:
|
||||
@ -154,7 +154,7 @@ class TroveHTTPClient(httplib2.Http):
|
||||
|
||||
try:
|
||||
resp_body = json.dumps(json.loads(body), sort_keys=True, indent=4)
|
||||
except:
|
||||
except Exception:
|
||||
resp_body = body
|
||||
_logger.debug("RESPONSE HEADERS: %s" % resp)
|
||||
_logger.debug("RESPONSE BODY : %s" % resp_body)
|
||||
@ -229,7 +229,7 @@ class TroveHTTPClient(httplib2.Http):
|
||||
# re-authenticate and try again. If it still fails, bail.
|
||||
try:
|
||||
return request()
|
||||
except exceptions.Unauthorized as ex:
|
||||
except exceptions.Unauthorized:
|
||||
self.authenticate()
|
||||
return request()
|
||||
|
||||
@ -296,26 +296,23 @@ class Dbaas(object):
|
||||
service_type='database', service_name=None,
|
||||
service_url=None, insecure=False, auth_strategy='keystone',
|
||||
region_name=None, client_cls=TroveHTTPClient):
|
||||
from troveclient.compat.versions import Versions
|
||||
from troveclient.v1.databases import Databases
|
||||
from troveclient.v1.flavors import Flavors
|
||||
from troveclient.v1.instances import Instances
|
||||
from troveclient.v1.limits import Limits
|
||||
from troveclient.v1.users import Users
|
||||
from troveclient.v1.root import Root
|
||||
from troveclient.v1.hosts import Hosts
|
||||
from troveclient.v1.quota import Quotas
|
||||
from troveclient.v1.backups import Backups
|
||||
from troveclient.v1.security_groups import SecurityGroups
|
||||
from troveclient.v1.security_groups import SecurityGroupRules
|
||||
from troveclient.v1.datastores import Datastores
|
||||
from troveclient.v1.datastores import DatastoreVersions
|
||||
from troveclient.v1.storage import StorageInfo
|
||||
from troveclient.v1.management import Management
|
||||
from troveclient.v1.management import MgmtFlavors
|
||||
from troveclient.v1.accounts import Accounts
|
||||
from troveclient.v1.diagnostics import DiagnosticsInterrogator
|
||||
from troveclient.v1.diagnostics import HwInfoInterrogator
|
||||
|
||||
from troveclient.compat import versions
|
||||
from troveclient.v1 import accounts
|
||||
from troveclient.v1 import backups
|
||||
from troveclient.v1 import databases
|
||||
from troveclient.v1 import datastores
|
||||
from troveclient.v1 import diagnostics
|
||||
from troveclient.v1 import flavors
|
||||
from troveclient.v1 import hosts
|
||||
from troveclient.v1 import instances
|
||||
from troveclient.v1 import limits
|
||||
from troveclient.v1 import management
|
||||
from troveclient.v1 import quota
|
||||
from troveclient.v1 import root
|
||||
from troveclient.v1 import security_groups
|
||||
from troveclient.v1 import storage
|
||||
from troveclient.v1 import users
|
||||
|
||||
self.client = client_cls(username, api_key, tenant, auth_url,
|
||||
service_type=service_type,
|
||||
@ -324,26 +321,26 @@ class Dbaas(object):
|
||||
insecure=insecure,
|
||||
auth_strategy=auth_strategy,
|
||||
region_name=region_name)
|
||||
self.versions = Versions(self)
|
||||
self.databases = Databases(self)
|
||||
self.flavors = Flavors(self)
|
||||
self.instances = Instances(self)
|
||||
self.limits = Limits(self)
|
||||
self.users = Users(self)
|
||||
self.root = Root(self)
|
||||
self.hosts = Hosts(self)
|
||||
self.quota = Quotas(self)
|
||||
self.backups = Backups(self)
|
||||
self.security_groups = SecurityGroups(self)
|
||||
self.security_group_rules = SecurityGroupRules(self)
|
||||
self.datastores = Datastores(self)
|
||||
self.datastore_versions = DatastoreVersions(self)
|
||||
self.storage = StorageInfo(self)
|
||||
self.management = Management(self)
|
||||
self.mgmt_flavor = MgmtFlavors(self)
|
||||
self.accounts = Accounts(self)
|
||||
self.diagnostics = DiagnosticsInterrogator(self)
|
||||
self.hwinfo = HwInfoInterrogator(self)
|
||||
self.versions = versions.Versions(self)
|
||||
self.databases = databases.Databases(self)
|
||||
self.flavors = flavors.Flavors(self)
|
||||
self.instances = instances.Instances(self)
|
||||
self.limits = limits.Limits(self)
|
||||
self.users = users.Users(self)
|
||||
self.root = root.Root(self)
|
||||
self.hosts = hosts.Hosts(self)
|
||||
self.quota = quota.Quotas(self)
|
||||
self.backups = backups.Backups(self)
|
||||
self.security_groups = security_groups.SecurityGroups(self)
|
||||
self.security_group_rules = security_groups.SecurityGroupRules(self)
|
||||
self.datastores = datastores.Datastores(self)
|
||||
self.datastore_versions = datastores.DatastoreVersions(self)
|
||||
self.storage = storage.StorageInfo(self)
|
||||
self.management = management.Management(self)
|
||||
self.mgmt_flavor = management.MgmtFlavors(self)
|
||||
self.accounts = accounts.Accounts(self)
|
||||
self.diagnostics = diagnostics.DiagnosticsInterrogator(self)
|
||||
self.hwinfo = diagnostics.HwInfoInterrogator(self)
|
||||
|
||||
class Mgmt(object):
|
||||
def __init__(self, dbaas):
|
||||
|
@ -21,7 +21,7 @@ import six
|
||||
import sys
|
||||
|
||||
from troveclient.compat import client
|
||||
from troveclient.compat.xml import TroveXmlClient
|
||||
from troveclient.compat import xml
|
||||
from troveclient.compat import exceptions
|
||||
|
||||
from troveclient.openstack.common.py3kcompat import urlutils
|
||||
@ -44,7 +44,7 @@ def check_for_exceptions(resp, body):
|
||||
|
||||
def print_actions(cmd, actions):
|
||||
"""Print help for the command with list of options and description"""
|
||||
print(("Available actions for '%s' cmd:") % cmd)
|
||||
print("Available actions for '%s' cmd:" % cmd)
|
||||
for k, v in six.iteritems(actions):
|
||||
print("\t%-20s%s" % (k, v.__doc__))
|
||||
sys.exit(2)
|
||||
@ -119,7 +119,7 @@ class CliOptions(object):
|
||||
return pickle.load(token)
|
||||
except IOError:
|
||||
pass # File probably not found.
|
||||
except:
|
||||
except Exception:
|
||||
print("ERROR: Token file found at %s was corrupt." % cls.APITOKEN)
|
||||
return cls.default()
|
||||
|
||||
@ -217,7 +217,7 @@ class CommandsBase(object):
|
||||
"""Creates the all important client object."""
|
||||
try:
|
||||
if self.xml:
|
||||
client_cls = TroveXmlClient
|
||||
client_cls = xml.TroveXmlClient
|
||||
else:
|
||||
client_cls = client.TroveHTTPClient
|
||||
if self.verbose:
|
||||
@ -232,7 +232,7 @@ class CommandsBase(object):
|
||||
service_url=self.service_url,
|
||||
insecure=self.insecure,
|
||||
client_cls=client_cls)
|
||||
except:
|
||||
except Exception:
|
||||
if self.debug:
|
||||
raise
|
||||
print(sys.exc_info()[1])
|
||||
@ -241,7 +241,7 @@ class CommandsBase(object):
|
||||
if not self.debug:
|
||||
try:
|
||||
return func(*args, **kwargs)
|
||||
except:
|
||||
except Exception:
|
||||
print(sys.exc_info()[1])
|
||||
return None
|
||||
else:
|
||||
@ -328,7 +328,7 @@ class CommandsBase(object):
|
||||
print(self._dumps((link)))
|
||||
else:
|
||||
print("OK")
|
||||
except:
|
||||
except Exception:
|
||||
if self.debug:
|
||||
raise
|
||||
print(sys.exc_info()[1])
|
||||
@ -366,7 +366,7 @@ class Auth(CommandsBase):
|
||||
print("Token aquired! Saving to %s..." % CliOptions.APITOKEN)
|
||||
print(" service_url = %s" % self.service_url)
|
||||
print(" token = %s" % self.token)
|
||||
except:
|
||||
except Exception:
|
||||
if self.debug:
|
||||
raise
|
||||
print(sys.exc_info()[1])
|
||||
|
@ -39,7 +39,7 @@ oparser = None
|
||||
|
||||
|
||||
def _pretty_print(info):
|
||||
print json.dumps(info, sort_keys=True, indent=4)
|
||||
print(json.dumps(info, sort_keys=True, indent=4))
|
||||
|
||||
|
||||
class HostCommands(common.AuthedCommandsBase):
|
||||
@ -260,7 +260,7 @@ def main():
|
||||
except Exception as ex:
|
||||
if options.debug:
|
||||
raise
|
||||
print ex
|
||||
print(ex)
|
||||
else:
|
||||
common.print_actions(cmd, actions)
|
||||
else:
|
||||
|
@ -17,9 +17,9 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from testtools import TestCase
|
||||
import testtools
|
||||
from troveclient.compat import auth
|
||||
from mock import Mock
|
||||
import mock
|
||||
|
||||
from troveclient.compat import exceptions
|
||||
|
||||
@ -39,7 +39,7 @@ def check_url_none(test_case, auth_class):
|
||||
pass
|
||||
|
||||
|
||||
class AuthenticatorTest(TestCase):
|
||||
class AuthenticatorTest(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(AuthenticatorTest, self).setUp()
|
||||
@ -72,58 +72,62 @@ class AuthenticatorTest(TestCase):
|
||||
self.assertRaises(ValueError, auth.get_authenticator_cls, cls_or_name)
|
||||
|
||||
def test__authenticate(self):
|
||||
authObj = auth.Authenticator(Mock(), auth.KeyStoneV2Authenticator,
|
||||
Mock(), Mock(), Mock(), Mock())
|
||||
authObj = auth.Authenticator(mock.Mock(), auth.KeyStoneV2Authenticator,
|
||||
mock.Mock(), mock.Mock(),
|
||||
mock.Mock(), mock.Mock())
|
||||
# test response code 200
|
||||
resp = Mock()
|
||||
resp = mock.Mock()
|
||||
resp.status = 200
|
||||
body = "test_body"
|
||||
|
||||
auth.ServiceCatalog._load = Mock(return_value=1)
|
||||
authObj.client._time_request = Mock(return_value=(resp, body))
|
||||
auth.ServiceCatalog._load = mock.Mock(return_value=1)
|
||||
authObj.client._time_request = mock.Mock(return_value=(resp, body))
|
||||
|
||||
sc = authObj._authenticate(Mock(), Mock())
|
||||
sc = authObj._authenticate(mock.Mock(), mock.Mock())
|
||||
self.assertEqual(body, sc.catalog)
|
||||
|
||||
# test AmbiguousEndpoints exception
|
||||
auth.ServiceCatalog.__init__ = \
|
||||
Mock(side_effect=exceptions.AmbiguousEndpoints)
|
||||
auth.ServiceCatalog.__init__ = mock.Mock(
|
||||
side_effect=exceptions.AmbiguousEndpoints
|
||||
)
|
||||
self.assertRaises(exceptions.AmbiguousEndpoints,
|
||||
authObj._authenticate, Mock(), Mock())
|
||||
authObj._authenticate, mock.Mock(), mock.Mock())
|
||||
|
||||
# test handling KeyError and raising AuthorizationFailure exception
|
||||
auth.ServiceCatalog.__init__ = Mock(side_effect=KeyError)
|
||||
auth.ServiceCatalog.__init__ = mock.Mock(side_effect=KeyError)
|
||||
self.assertRaises(exceptions.AuthorizationFailure,
|
||||
authObj._authenticate, Mock(), Mock())
|
||||
authObj._authenticate, mock.Mock(), mock.Mock())
|
||||
|
||||
# test EndpointNotFound exception
|
||||
mock = Mock(side_effect=exceptions.EndpointNotFound)
|
||||
auth.ServiceCatalog.__init__ = mock
|
||||
mock_obj = mock.Mock(side_effect=exceptions.EndpointNotFound)
|
||||
auth.ServiceCatalog.__init__ = mock_obj
|
||||
self.assertRaises(exceptions.EndpointNotFound,
|
||||
authObj._authenticate, Mock(), Mock())
|
||||
mock.side_effect = None
|
||||
authObj._authenticate, mock.Mock(), mock.Mock())
|
||||
mock_obj.side_effect = None
|
||||
|
||||
# test response code 305
|
||||
resp.__getitem__ = Mock(return_value='loc')
|
||||
resp.__getitem__ = mock.Mock(return_value='loc')
|
||||
resp.status = 305
|
||||
body = "test_body"
|
||||
authObj.client._time_request = Mock(return_value=(resp, body))
|
||||
authObj.client._time_request = mock.Mock(return_value=(resp, body))
|
||||
|
||||
l = authObj._authenticate(Mock(), Mock())
|
||||
l = authObj._authenticate(mock.Mock(), mock.Mock())
|
||||
self.assertEqual('loc', l)
|
||||
|
||||
# test any response code other than 200 and 305
|
||||
resp.status = 404
|
||||
exceptions.from_response = Mock(side_effect=ValueError)
|
||||
self.assertRaises(ValueError, authObj._authenticate, Mock(), Mock())
|
||||
exceptions.from_response = mock.Mock(side_effect=ValueError)
|
||||
self.assertRaises(ValueError, authObj._authenticate,
|
||||
mock.Mock(), mock.Mock())
|
||||
|
||||
def test_authenticate(self):
|
||||
authObj = auth.Authenticator(Mock(), auth.KeyStoneV2Authenticator,
|
||||
Mock(), Mock(), Mock(), Mock())
|
||||
authObj = auth.Authenticator(mock.Mock(), auth.KeyStoneV2Authenticator,
|
||||
mock.Mock(), mock.Mock(),
|
||||
mock.Mock(), mock.Mock())
|
||||
self.assertRaises(NotImplementedError, authObj.authenticate)
|
||||
|
||||
|
||||
class KeyStoneV2AuthenticatorTest(TestCase):
|
||||
class KeyStoneV2AuthenticatorTest(testtools.TestCase):
|
||||
|
||||
def test_authenticate(self):
|
||||
# url is None
|
||||
@ -139,9 +143,9 @@ class KeyStoneV2AuthenticatorTest(TestCase):
|
||||
def side_effect_func(url):
|
||||
return url
|
||||
|
||||
mock = Mock()
|
||||
mock.side_effect = side_effect_func
|
||||
authObj._v2_auth = mock
|
||||
mock_obj = mock.Mock()
|
||||
mock_obj.side_effect = side_effect_func
|
||||
authObj._v2_auth = mock_obj
|
||||
r = authObj.authenticate()
|
||||
self.assertEqual(url, r)
|
||||
|
||||
@ -158,10 +162,10 @@ class KeyStoneV2AuthenticatorTest(TestCase):
|
||||
|
||||
def side_effect_func(url, body):
|
||||
return body
|
||||
mock = Mock()
|
||||
mock.side_effect = side_effect_func
|
||||
authObj._authenticate = mock
|
||||
body = authObj._v2_auth(Mock())
|
||||
mock_obj = mock.Mock()
|
||||
mock_obj.side_effect = side_effect_func
|
||||
authObj._authenticate = mock_obj
|
||||
body = authObj._v2_auth(mock.Mock())
|
||||
self.assertEqual(username,
|
||||
body['auth']['passwordCredentials']['username'])
|
||||
self.assertEqual(password,
|
||||
@ -169,7 +173,7 @@ class KeyStoneV2AuthenticatorTest(TestCase):
|
||||
self.assertEqual(tenant, body['auth']['tenantName'])
|
||||
|
||||
|
||||
class Auth1_1Test(TestCase):
|
||||
class Auth1_1Test(testtools.TestCase):
|
||||
|
||||
def test_authenticate(self):
|
||||
# handle when url is None
|
||||
@ -187,9 +191,9 @@ class Auth1_1Test(TestCase):
|
||||
def side_effect_func(auth_url, body, root_key):
|
||||
return auth_url, body, root_key
|
||||
|
||||
mock = Mock()
|
||||
mock.side_effect = side_effect_func
|
||||
authObj._authenticate = mock
|
||||
mock_obj = mock.Mock()
|
||||
mock_obj.side_effect = side_effect_func
|
||||
authObj._authenticate = mock_obj
|
||||
auth_url, body, root_key = authObj.authenticate()
|
||||
|
||||
self.assertEqual(username, body['credentials']['username'])
|
||||
@ -198,7 +202,7 @@ class Auth1_1Test(TestCase):
|
||||
self.assertEqual('auth', root_key)
|
||||
|
||||
|
||||
class RaxAuthenticatorTest(TestCase):
|
||||
class RaxAuthenticatorTest(testtools.TestCase):
|
||||
|
||||
def test_authenticate(self):
|
||||
# url is None
|
||||
@ -214,9 +218,9 @@ class RaxAuthenticatorTest(TestCase):
|
||||
def side_effect_func(url):
|
||||
return url
|
||||
|
||||
mock = Mock()
|
||||
mock.side_effect = side_effect_func
|
||||
authObj._rax_auth = mock
|
||||
mock_obj = mock.Mock()
|
||||
mock_obj.side_effect = side_effect_func
|
||||
authObj._rax_auth = mock_obj
|
||||
r = authObj.authenticate()
|
||||
self.assertEqual(url, r)
|
||||
|
||||
@ -232,10 +236,10 @@ class RaxAuthenticatorTest(TestCase):
|
||||
def side_effect_func(url, body):
|
||||
return body
|
||||
|
||||
mock = Mock()
|
||||
mock.side_effect = side_effect_func
|
||||
authObj._authenticate = mock
|
||||
body = authObj._rax_auth(Mock())
|
||||
mock_obj = mock.Mock()
|
||||
mock_obj.side_effect = side_effect_func
|
||||
authObj._authenticate = mock_obj
|
||||
body = authObj._rax_auth(mock.Mock())
|
||||
|
||||
v = body['auth']['RAX-KSKEY:apiKeyCredentials']['username']
|
||||
self.assertEqual(username, v)
|
||||
@ -247,7 +251,7 @@ class RaxAuthenticatorTest(TestCase):
|
||||
self.assertEqual(tenant, v)
|
||||
|
||||
|
||||
class FakeAuthTest(TestCase):
|
||||
class FakeAuthTest(testtools.TestCase):
|
||||
|
||||
def test_authenticate(self):
|
||||
tenant = "tenant"
|
||||
@ -262,13 +266,13 @@ class FakeAuthTest(TestCase):
|
||||
self.assertEqual(tenant, fc.get_token())
|
||||
|
||||
|
||||
class ServiceCatalogTest(TestCase):
|
||||
class ServiceCatalogTest(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(ServiceCatalogTest, self).setUp()
|
||||
self.orig_url_for = auth.ServiceCatalog._url_for
|
||||
self.orig__init__ = auth.ServiceCatalog.__init__
|
||||
auth.ServiceCatalog.__init__ = Mock(return_value=None)
|
||||
auth.ServiceCatalog.__init__ = mock.Mock(return_value=None)
|
||||
self.test_url = "http://localhost:1234/test"
|
||||
|
||||
def tearDown(self):
|
||||
@ -278,7 +282,7 @@ class ServiceCatalogTest(TestCase):
|
||||
|
||||
def test__load(self):
|
||||
url = "random_url"
|
||||
auth.ServiceCatalog._url_for = Mock(return_value=url)
|
||||
auth.ServiceCatalog._url_for = mock.Mock(return_value=url)
|
||||
|
||||
# when service_url is None
|
||||
scObj = auth.ServiceCatalog()
|
||||
@ -347,10 +351,10 @@ class ServiceCatalogTest(TestCase):
|
||||
return "test_attr_value"
|
||||
|
||||
# simulating dict
|
||||
endpoint = Mock()
|
||||
mock = Mock()
|
||||
mock.side_effect = side_effect_func_ep
|
||||
endpoint.__getitem__ = mock
|
||||
endpoint = mock.Mock()
|
||||
mock_obj = mock.Mock()
|
||||
mock_obj.side_effect = side_effect_func_ep
|
||||
endpoint.__getitem__ = mock_obj
|
||||
scObj.catalog['endpoints'].append(endpoint)
|
||||
|
||||
# not-empty list but not matching endpoint
|
||||
@ -370,7 +374,7 @@ class ServiceCatalogTest(TestCase):
|
||||
scObj.catalog[scObj.root_key]['serviceCatalog'] = list()
|
||||
|
||||
endpoint = scObj.catalog['endpoints'][0]
|
||||
endpoint.get = Mock(return_value=self.test_url)
|
||||
endpoint.get = mock.Mock(return_value=self.test_url)
|
||||
r_url = scObj._url_for(attr="test_attr",
|
||||
filter_value="test_attr_value")
|
||||
self.assertEqual(self.test_url, r_url)
|
||||
@ -386,13 +390,13 @@ class ServiceCatalogTest(TestCase):
|
||||
return "test_service_name"
|
||||
return None
|
||||
|
||||
mock1 = Mock()
|
||||
mock1 = mock.Mock()
|
||||
mock1.side_effect = side_effect_func_service
|
||||
service1 = Mock()
|
||||
service1 = mock.Mock()
|
||||
service1.get = mock1
|
||||
|
||||
endpoint2 = {"test_attr": "test_attr_value"}
|
||||
service1.__getitem__ = Mock(return_value=[endpoint2])
|
||||
service1.__getitem__ = mock.Mock(return_value=[endpoint2])
|
||||
scObj.catalog[scObj.root_key]['serviceCatalog'] = [service1]
|
||||
self.assertRaises(exceptions.AmbiguousEndpoints, scObj._url_for,
|
||||
attr="test_attr", filter_value="test_attr_value")
|
||||
|
@ -1,10 +1,25 @@
|
||||
# Copyright (c) 2011 OpenStack Foundation
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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 sys
|
||||
import optparse
|
||||
import json
|
||||
import collections
|
||||
|
||||
from testtools import TestCase
|
||||
from mock import Mock
|
||||
import testtools
|
||||
import mock
|
||||
|
||||
from troveclient.compat import common
|
||||
|
||||
@ -13,12 +28,12 @@ from troveclient.compat import common
|
||||
"""
|
||||
|
||||
|
||||
class CommonTest(TestCase):
|
||||
class CommonTest(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(CommonTest, self).setUp()
|
||||
self.orig_sys_exit = sys.exit
|
||||
sys.exit = Mock(return_value=None)
|
||||
sys.exit = mock.Mock(return_value=None)
|
||||
|
||||
def tearDown(self):
|
||||
super(CommonTest, self).tearDown()
|
||||
@ -38,14 +53,14 @@ class CommonTest(TestCase):
|
||||
def test_check_for_exceptions(self):
|
||||
status = [400, 422, 500]
|
||||
for s in status:
|
||||
resp = Mock()
|
||||
resp = mock.Mock()
|
||||
#compat still uses status
|
||||
resp.status = s
|
||||
self.assertRaises(Exception,
|
||||
common.check_for_exceptions, resp, "body")
|
||||
|
||||
# a no-exception case
|
||||
resp = Mock()
|
||||
resp = mock.Mock()
|
||||
resp.status_code = 200
|
||||
common.check_for_exceptions(resp, "body")
|
||||
|
||||
@ -73,7 +88,7 @@ class CommonTest(TestCase):
|
||||
common.limit_url(url, limit=limit, marker=marker))
|
||||
|
||||
|
||||
class CliOptionsTest(TestCase):
|
||||
class CliOptionsTest(testtools.TestCase):
|
||||
|
||||
def check_default_options(self, co):
|
||||
self.assertEqual(None, co.username)
|
||||
@ -125,7 +140,7 @@ class CliOptionsTest(TestCase):
|
||||
self.check_option(oparser, option_name)
|
||||
|
||||
|
||||
class ArgumentRequiredTest(TestCase):
|
||||
class ArgumentRequiredTest(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(ArgumentRequiredTest, self).setUp()
|
||||
@ -140,12 +155,12 @@ class ArgumentRequiredTest(TestCase):
|
||||
self.assertEqual(expected, self.arg_req.__str__())
|
||||
|
||||
|
||||
class CommandsBaseTest(TestCase):
|
||||
class CommandsBaseTest(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(CommandsBaseTest, self).setUp()
|
||||
self.orig_sys_exit = sys.exit
|
||||
sys.exit = Mock(return_value=None)
|
||||
sys.exit = mock.Mock(return_value=None)
|
||||
self.orig_sys_argv = sys.argv
|
||||
sys.argv = ['fakecmd']
|
||||
parser = common.CliOptions().create_optparser(False)
|
||||
@ -160,7 +175,7 @@ class CommandsBaseTest(TestCase):
|
||||
self.assertNotEqual(None, self.cmd_base)
|
||||
|
||||
def test__safe_exec(self):
|
||||
func = Mock(return_value="test")
|
||||
func = mock.Mock(return_value="test")
|
||||
self.cmd_base.debug = True
|
||||
r = self.cmd_base._safe_exec(func)
|
||||
self.assertEqual("test", r)
|
||||
@ -169,7 +184,7 @@ class CommandsBaseTest(TestCase):
|
||||
r = self.cmd_base._safe_exec(func)
|
||||
self.assertEqual("test", r)
|
||||
|
||||
func = Mock(side_effect=ValueError) # an arbitrary exception
|
||||
func = mock.Mock(side_effect=ValueError) # an arbitrary exception
|
||||
r = self.cmd_base._safe_exec(func)
|
||||
self.assertEqual(None, r)
|
||||
|
||||
@ -209,30 +224,30 @@ class CommandsBaseTest(TestCase):
|
||||
self.assertEqual(["v3"], self.cmd_base.attr1)
|
||||
|
||||
def test__pretty_print(self):
|
||||
func = Mock(return_value=None)
|
||||
func = mock.Mock(return_value=None)
|
||||
self.cmd_base.verbose = True
|
||||
self.assertEqual(None, self.cmd_base._pretty_print(func))
|
||||
self.cmd_base.verbose = False
|
||||
self.assertEqual(None, self.cmd_base._pretty_print(func))
|
||||
|
||||
def test__dumps(self):
|
||||
json.dumps = Mock(return_value="test-dump")
|
||||
json.dumps = mock.Mock(return_value="test-dump")
|
||||
self.assertEqual("test-dump", self.cmd_base._dumps("item"))
|
||||
|
||||
def test__pretty_list(self):
|
||||
func = Mock(return_value=None)
|
||||
func = mock.Mock(return_value=None)
|
||||
self.cmd_base.verbose = True
|
||||
self.assertEqual(None, self.cmd_base._pretty_list(func))
|
||||
self.cmd_base.verbose = False
|
||||
self.assertEqual(None, self.cmd_base._pretty_list(func))
|
||||
item = Mock(return_value="test")
|
||||
item = mock.Mock(return_value="test")
|
||||
item._info = "info"
|
||||
func = Mock(return_value=[item])
|
||||
func = mock.Mock(return_value=[item])
|
||||
self.assertEqual(None, self.cmd_base._pretty_list(func))
|
||||
|
||||
def test__pretty_paged(self):
|
||||
self.cmd_base.limit = "5"
|
||||
func = Mock(return_value=None)
|
||||
func = mock.Mock(return_value=None)
|
||||
self.cmd_base.verbose = True
|
||||
self.assertEqual(None, self.cmd_base._pretty_paged(func))
|
||||
|
||||
@ -246,28 +261,28 @@ class CommandsBaseTest(TestCase):
|
||||
return ["item1"]
|
||||
|
||||
def __len__(self):
|
||||
return count
|
||||
return self.count
|
||||
|
||||
ret = MockIterable()
|
||||
func = Mock(return_value=ret)
|
||||
func = mock.Mock(return_value=ret)
|
||||
self.assertEqual(None, self.cmd_base._pretty_paged(func))
|
||||
|
||||
ret.count = 0
|
||||
self.assertEqual(None, self.cmd_base._pretty_paged(func))
|
||||
|
||||
func = Mock(side_effect=ValueError)
|
||||
func = mock.Mock(side_effect=ValueError)
|
||||
self.assertEqual(None, self.cmd_base._pretty_paged(func))
|
||||
self.cmd_base.debug = True
|
||||
self.cmd_base.marker = Mock()
|
||||
self.cmd_base.marker = mock.Mock()
|
||||
self.assertRaises(ValueError, self.cmd_base._pretty_paged, func)
|
||||
|
||||
|
||||
class AuthTest(TestCase):
|
||||
class AuthTest(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(AuthTest, self).setUp()
|
||||
self.orig_sys_exit = sys.exit
|
||||
sys.exit = Mock(return_value=None)
|
||||
sys.exit = mock.Mock(return_value=None)
|
||||
self.orig_sys_argv = sys.argv
|
||||
sys.argv = ['fakecmd']
|
||||
self.parser = common.CliOptions().create_optparser(False)
|
||||
@ -287,28 +302,28 @@ class AuthTest(TestCase):
|
||||
self.auth.apikey = "apikey"
|
||||
self.auth.tenant_id = "tenant_id"
|
||||
self.auth.auth_url = "auth_url"
|
||||
dbaas = Mock()
|
||||
dbaas.authenticate = Mock(return_value=None)
|
||||
dbaas.client = Mock()
|
||||
dbaas.client.auth_token = Mock()
|
||||
dbaas.client.service_url = Mock()
|
||||
self.auth._get_client = Mock(return_value=dbaas)
|
||||
dbaas = mock.Mock()
|
||||
dbaas.authenticate = mock.Mock(return_value=None)
|
||||
dbaas.client = mock.Mock()
|
||||
dbaas.client.auth_token = mock.Mock()
|
||||
dbaas.client.service_url = mock.Mock()
|
||||
self.auth._get_client = mock.Mock(return_value=dbaas)
|
||||
self.auth.login()
|
||||
|
||||
self.auth.debug = True
|
||||
self.auth._get_client = Mock(side_effect=ValueError)
|
||||
self.auth._get_client = mock.Mock(side_effect=ValueError)
|
||||
self.assertRaises(ValueError, self.auth.login)
|
||||
|
||||
self.auth.debug = False
|
||||
self.auth.login()
|
||||
|
||||
|
||||
class AuthedCommandsBaseTest(TestCase):
|
||||
class AuthedCommandsBaseTest(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(AuthedCommandsBaseTest, self).setUp()
|
||||
self.orig_sys_exit = sys.exit
|
||||
sys.exit = Mock(return_value=None)
|
||||
sys.exit = mock.Mock(return_value=None)
|
||||
self.orig_sys_argv = sys.argv
|
||||
sys.argv = ['fakecmd']
|
||||
|
||||
@ -320,17 +335,17 @@ class AuthedCommandsBaseTest(TestCase):
|
||||
def test___init__(self):
|
||||
parser = common.CliOptions().create_optparser(False)
|
||||
common.AuthedCommandsBase.debug = True
|
||||
dbaas = Mock()
|
||||
dbaas.authenticate = Mock(return_value=None)
|
||||
dbaas.client = Mock()
|
||||
dbaas.client.auth_token = Mock()
|
||||
dbaas.client.service_url = Mock()
|
||||
dbaas.client.authenticate_with_token = Mock()
|
||||
common.AuthedCommandsBase._get_client = Mock(return_value=dbaas)
|
||||
authed_cmd = common.AuthedCommandsBase(parser)
|
||||
dbaas = mock.Mock()
|
||||
dbaas.authenticate = mock.Mock(return_value=None)
|
||||
dbaas.client = mock.Mock()
|
||||
dbaas.client.auth_token = mock.Mock()
|
||||
dbaas.client.service_url = mock.Mock()
|
||||
dbaas.client.authenticate_with_token = mock.Mock()
|
||||
common.AuthedCommandsBase._get_client = mock.Mock(return_value=dbaas)
|
||||
common.AuthedCommandsBase(parser)
|
||||
|
||||
|
||||
class PaginatedTest(TestCase):
|
||||
class PaginatedTest(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(PaginatedTest, self).setUp()
|
||||
@ -372,7 +387,6 @@ class PaginatedTest(TestCase):
|
||||
|
||||
def test___reversed__(self):
|
||||
itr = self.pgn.__reversed__()
|
||||
expected = ["item2", "item1"]
|
||||
self.assertEqual("item2", next(itr))
|
||||
self.assertEqual("item1", next(itr))
|
||||
self.assertRaises(StopIteration, next, itr)
|
||||
|
@ -1,9 +1,25 @@
|
||||
# Copyright (c) 2011 OpenStack Foundation
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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 testtools
|
||||
from lxml import etree
|
||||
#from troveclient import xml
|
||||
from troveclient.compat import xml
|
||||
|
||||
|
||||
# Killing this until xml support is brought back.
|
||||
#class XmlTest(TestCase):
|
||||
#class XmlTest(testtools.TestCase):
|
||||
class XmlTest(object):
|
||||
ELEMENT = '''
|
||||
<instances>
|
||||
|
@ -1,8 +1,23 @@
|
||||
# Copyright (c) 2011 OpenStack Foundation
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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 lxml import etree
|
||||
from numbers import Number
|
||||
import numbers
|
||||
|
||||
from troveclient.compat import exceptions
|
||||
from troveclient.compat.client import TroveHTTPClient
|
||||
from troveclient.compat import client
|
||||
|
||||
XML_NS = {None: "http://docs.openstack.org/database/api/v1.0"}
|
||||
|
||||
@ -227,7 +242,7 @@ def populate_element_from_dict(element, dict):
|
||||
for key, value in dict.items():
|
||||
if isinstance(value, basestring):
|
||||
element.set(key, value)
|
||||
elif isinstance(value, Number):
|
||||
elif isinstance(value, numbers.Number):
|
||||
element.set(key, str(value))
|
||||
elif isinstance(value, None.__class__):
|
||||
element.set(key, '')
|
||||
@ -263,7 +278,7 @@ def modify_response_types(value, type_translator):
|
||||
for element in value]
|
||||
|
||||
|
||||
class TroveXmlClient(TroveHTTPClient):
|
||||
class TroveXmlClient(client.TroveHTTPClient):
|
||||
|
||||
@classmethod
|
||||
def morph_request(self, kwargs):
|
||||
|
@ -37,7 +37,7 @@ import troveclient
|
||||
from troveclient import client
|
||||
from troveclient.openstack.common import strutils
|
||||
from troveclient.openstack.common.apiclient import exceptions as exc
|
||||
from troveclient.openstack.common.gettextutils import _
|
||||
from troveclient.openstack.common import gettextutils as gtu
|
||||
from troveclient import utils
|
||||
from troveclient.v1 import shell as shell_v1
|
||||
|
||||
@ -548,7 +548,7 @@ class OpenStackHelpFormatter(argparse.HelpFormatter):
|
||||
'trove create <name> <flavor_id> --databases <db_name>'
|
||||
"""
|
||||
if prefix is None:
|
||||
prefix = _('usage: ')
|
||||
prefix = gtu._('usage: ')
|
||||
|
||||
# if usage is specified, use that
|
||||
if usage is not None:
|
||||
|
@ -17,8 +17,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from testtools import TestCase
|
||||
from mock import Mock
|
||||
import testtools
|
||||
import mock
|
||||
|
||||
from troveclient.v1 import accounts
|
||||
from troveclient import base
|
||||
@ -28,12 +28,12 @@ Unit tests for accounts.py
|
||||
"""
|
||||
|
||||
|
||||
class AccountTest(TestCase):
|
||||
class AccountTest(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(AccountTest, self).setUp()
|
||||
self.orig__init = accounts.Account.__init__
|
||||
accounts.Account.__init__ = Mock(return_value=None)
|
||||
accounts.Account.__init__ = mock.Mock(return_value=None)
|
||||
self.account = accounts.Account()
|
||||
|
||||
def tearDown(self):
|
||||
@ -45,15 +45,15 @@ class AccountTest(TestCase):
|
||||
self.assertEqual('<Account: account-1>', self.account.__repr__())
|
||||
|
||||
|
||||
class AccountsTest(TestCase):
|
||||
class AccountsTest(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(AccountsTest, self).setUp()
|
||||
self.orig__init = accounts.Accounts.__init__
|
||||
accounts.Accounts.__init__ = Mock(return_value=None)
|
||||
accounts.Accounts.__init__ = mock.Mock(return_value=None)
|
||||
self.accounts = accounts.Accounts()
|
||||
self.accounts.api = Mock()
|
||||
self.accounts.api.client = Mock()
|
||||
self.accounts.api = mock.Mock()
|
||||
self.accounts.api.client = mock.Mock()
|
||||
|
||||
def tearDown(self):
|
||||
super(AccountsTest, self).tearDown()
|
||||
@ -63,33 +63,33 @@ class AccountsTest(TestCase):
|
||||
def side_effect_func(self, val):
|
||||
return val
|
||||
|
||||
self.accounts.resource_class = Mock(side_effect=side_effect_func)
|
||||
self.accounts.resource_class = mock.Mock(side_effect=side_effect_func)
|
||||
key_ = 'key'
|
||||
body_ = {key_: "test-value"}
|
||||
self.accounts.api.client.get = Mock(return_value=('resp', body_))
|
||||
self.accounts.api.client.get = mock.Mock(return_value=('resp', body_))
|
||||
self.assertEqual("test-value", self.accounts._list('url', key_))
|
||||
|
||||
self.accounts.api.client.get = Mock(return_value=('resp', None))
|
||||
self.accounts.api.client.get = mock.Mock(return_value=('resp', None))
|
||||
self.assertRaises(Exception, self.accounts._list, 'url', None)
|
||||
|
||||
def test_index(self):
|
||||
resp = Mock()
|
||||
resp = mock.Mock()
|
||||
resp.status_code = 400
|
||||
body = {"Accounts": {}}
|
||||
self.accounts.api.client.get = Mock(return_value=(resp, body))
|
||||
self.accounts.api.client.get = mock.Mock(return_value=(resp, body))
|
||||
self.assertRaises(Exception, self.accounts.index)
|
||||
resp.status_code = 200
|
||||
self.assertTrue(isinstance(self.accounts.index(), base.Resource))
|
||||
self.accounts.api.client.get = Mock(return_value=(resp, None))
|
||||
self.accounts.api.client.get = mock.Mock(return_value=(resp, None))
|
||||
self.assertRaises(Exception, self.accounts.index)
|
||||
|
||||
def test_show(self):
|
||||
def side_effect_func(acct_name, acct):
|
||||
return acct_name, acct
|
||||
|
||||
account_ = Mock()
|
||||
account_ = mock.Mock()
|
||||
account_.name = "test-account"
|
||||
self.accounts._list = Mock(side_effect=side_effect_func)
|
||||
self.accounts._list = mock.Mock(side_effect=side_effect_func)
|
||||
self.assertEqual(('/mgmt/accounts/test-account', 'account'),
|
||||
self.accounts.show(account_))
|
||||
|
||||
@ -97,7 +97,7 @@ class AccountsTest(TestCase):
|
||||
account_ = 'account with no name'
|
||||
self.assertEqual(account_,
|
||||
accounts.Accounts._get_account_name(account_))
|
||||
account_ = Mock()
|
||||
account_ = mock.Mock()
|
||||
account_.name = "account-name"
|
||||
self.assertEqual("account-name",
|
||||
accounts.Accounts._get_account_name(account_))
|
||||
|
@ -20,8 +20,8 @@
|
||||
import contextlib
|
||||
import os
|
||||
|
||||
from testtools import TestCase
|
||||
from mock import Mock
|
||||
import testtools
|
||||
import mock
|
||||
|
||||
from troveclient import base
|
||||
from troveclient.openstack.common.apiclient import exceptions
|
||||
@ -38,26 +38,24 @@ def obj_class(self, res, loaded=True):
|
||||
return res
|
||||
|
||||
|
||||
class BaseTest(TestCase):
|
||||
|
||||
class BaseTest(testtools.TestCase):
|
||||
def test_getid(self):
|
||||
obj = "test"
|
||||
r = base.getid(obj)
|
||||
self.assertEqual(obj, r)
|
||||
|
||||
test_id = "test_id"
|
||||
obj = Mock()
|
||||
obj = mock.Mock()
|
||||
obj.id = test_id
|
||||
r = base.getid(obj)
|
||||
self.assertEqual(test_id, r)
|
||||
|
||||
|
||||
class ManagerTest(TestCase):
|
||||
|
||||
class ManagerTest(testtools.TestCase):
|
||||
def setUp(self):
|
||||
super(ManagerTest, self).setUp()
|
||||
self.orig__init = base.Manager.__init__
|
||||
base.Manager.__init__ = Mock(return_value=None)
|
||||
base.Manager.__init__ = mock.Mock(return_value=None)
|
||||
self.orig_os_makedirs = os.makedirs
|
||||
|
||||
def tearDown(self):
|
||||
@ -66,7 +64,7 @@ class ManagerTest(TestCase):
|
||||
os.makedirs = self.orig_os_makedirs
|
||||
|
||||
def test___init__(self):
|
||||
api = Mock()
|
||||
api = mock.Mock()
|
||||
base.Manager.__init__ = self.orig__init
|
||||
manager = base.Manager(api)
|
||||
self.assertEqual(api, manager.api)
|
||||
@ -77,11 +75,11 @@ class ManagerTest(TestCase):
|
||||
# handling exceptions
|
||||
mode = "w"
|
||||
cache_type = "unittest"
|
||||
obj_class = Mock
|
||||
obj_class = mock.Mock
|
||||
with manager.completion_cache(cache_type, obj_class, mode):
|
||||
pass
|
||||
|
||||
os.makedirs = Mock(side_effect=OSError)
|
||||
os.makedirs = mock.Mock(side_effect=OSError)
|
||||
with manager.completion_cache(cache_type, obj_class, mode):
|
||||
pass
|
||||
|
||||
@ -94,20 +92,20 @@ class ManagerTest(TestCase):
|
||||
def side_effect_func(val):
|
||||
return val
|
||||
|
||||
manager._mock_cache = Mock()
|
||||
manager._mock_cache.write = Mock(return_value=None)
|
||||
manager._mock_cache = mock.Mock()
|
||||
manager._mock_cache.write = mock.Mock(return_value=None)
|
||||
manager.write_to_completion_cache("mock", "val")
|
||||
self.assertEqual(1, manager._mock_cache.write.call_count)
|
||||
|
||||
def _get_mock(self):
|
||||
manager = base.Manager()
|
||||
manager.api = Mock()
|
||||
manager.api.client = Mock()
|
||||
manager.api = mock.Mock()
|
||||
manager.api.client = mock.Mock()
|
||||
|
||||
def side_effect_func(self, body, loaded=True):
|
||||
return body
|
||||
|
||||
manager.resource_class = Mock(side_effect=side_effect_func)
|
||||
manager.resource_class = mock.Mock(side_effect=side_effect_func)
|
||||
return manager
|
||||
|
||||
def test__get_with_response_key_none(self):
|
||||
@ -115,7 +113,7 @@ class ManagerTest(TestCase):
|
||||
url_ = "test-url"
|
||||
body_ = "test-body"
|
||||
resp_ = "test-resp"
|
||||
manager.api.client.get = Mock(return_value=(resp_, body_))
|
||||
manager.api.client.get = mock.Mock(return_value=(resp_, body_))
|
||||
r = manager._get(url=url_, response_key=None)
|
||||
self.assertEqual(body_, r)
|
||||
|
||||
@ -124,20 +122,20 @@ class ManagerTest(TestCase):
|
||||
response_key = "response_key"
|
||||
body_ = {response_key: "test-resp-key-body"}
|
||||
url_ = "test_url_get"
|
||||
manager.api.client.get = Mock(return_value=(url_, body_))
|
||||
manager.api.client.get = mock.Mock(return_value=(url_, body_))
|
||||
r = manager._get(url=url_, response_key=response_key)
|
||||
self.assertEqual(body_[response_key], r)
|
||||
|
||||
def test__create(self):
|
||||
manager = base.Manager()
|
||||
manager.api = Mock()
|
||||
manager.api.client = Mock()
|
||||
manager.api = mock.Mock()
|
||||
manager.api.client = mock.Mock()
|
||||
|
||||
response_key = "response_key"
|
||||
data_ = "test-data"
|
||||
body_ = {response_key: data_}
|
||||
url_ = "test_url_post"
|
||||
manager.api.client.post = Mock(return_value=(url_, body_))
|
||||
manager.api.client.post = mock.Mock(return_value=(url_, body_))
|
||||
|
||||
return_raw = True
|
||||
r = manager._create(url_, body_, response_key, return_raw)
|
||||
@ -149,18 +147,18 @@ class ManagerTest(TestCase):
|
||||
def completion_cache_mock(*arg, **kwargs):
|
||||
yield
|
||||
|
||||
mock = Mock()
|
||||
mock.side_effect = completion_cache_mock
|
||||
manager.completion_cache = mock
|
||||
mockl = mock.Mock()
|
||||
mockl.side_effect = completion_cache_mock
|
||||
manager.completion_cache = mockl
|
||||
|
||||
manager.resource_class = Mock(return_value="test-class")
|
||||
manager.resource_class = mock.Mock(return_value="test-class")
|
||||
r = manager._create(url_, body_, response_key, return_raw)
|
||||
self.assertEqual("test-class", r)
|
||||
|
||||
def get_mock_mng_api_client(self):
|
||||
manager = base.Manager()
|
||||
manager.api = Mock()
|
||||
manager.api.client = Mock()
|
||||
manager.api = mock.Mock()
|
||||
manager.api.client = mock.Mock()
|
||||
return manager
|
||||
|
||||
def test__delete(self):
|
||||
@ -168,7 +166,7 @@ class ManagerTest(TestCase):
|
||||
body_ = "test-body"
|
||||
|
||||
manager = self.get_mock_mng_api_client()
|
||||
manager.api.client.delete = Mock(return_value=(resp_, body_))
|
||||
manager.api.client.delete = mock.Mock(return_value=(resp_, body_))
|
||||
# _delete just calls api.client.delete, and does nothing
|
||||
# the correctness should be tested in api class
|
||||
manager._delete("test-url")
|
||||
@ -179,13 +177,12 @@ class ManagerTest(TestCase):
|
||||
body_ = "test-body"
|
||||
|
||||
manager = self.get_mock_mng_api_client()
|
||||
manager.api.client.put = Mock(return_value=(resp_, body_))
|
||||
manager.api.client.put = mock.Mock(return_value=(resp_, body_))
|
||||
body = manager._update("test-url", body_)
|
||||
self.assertEqual(body_, body)
|
||||
|
||||
|
||||
class ManagerListTest(ManagerTest):
|
||||
|
||||
def setUp(self):
|
||||
super(ManagerListTest, self).setUp()
|
||||
|
||||
@ -194,25 +191,26 @@ class ManagerListTest(ManagerTest):
|
||||
yield
|
||||
|
||||
self.manager = base.Manager()
|
||||
self.manager.api = Mock()
|
||||
self.manager.api.client = Mock()
|
||||
self.manager.api = mock.Mock()
|
||||
self.manager.api.client = mock.Mock()
|
||||
|
||||
self.response_key = "response_key"
|
||||
self.data_p = ["p1", "p2"]
|
||||
self.body_p = {self.response_key: self.data_p}
|
||||
self.url_p = "test_url_post"
|
||||
self.manager.api.client.post = Mock(return_value=(self.url_p,
|
||||
self.body_p))
|
||||
|
||||
self.manager.api.client.post = mock.Mock(
|
||||
return_value=(self.url_p, self.body_p)
|
||||
)
|
||||
self.data_g = ["g1", "g2", "g3"]
|
||||
self.body_g = {self.response_key: self.data_g}
|
||||
self.url_g = "test_url_get"
|
||||
self.manager.api.client.get = Mock(return_value=(self.url_g,
|
||||
self.body_g))
|
||||
self.manager.api.client.get = mock.Mock(
|
||||
return_value=(self.url_g, self.body_g)
|
||||
)
|
||||
|
||||
mock = Mock()
|
||||
mock.side_effect = completion_cache_mock
|
||||
self.manager.completion_cache = mock
|
||||
mockl = mock.Mock()
|
||||
mockl.side_effect = completion_cache_mock
|
||||
self.manager.completion_cache = mockl
|
||||
|
||||
def tearDown(self):
|
||||
super(ManagerListTest, self).tearDown()
|
||||
@ -238,7 +236,7 @@ class ManagerListTest(ManagerTest):
|
||||
data_ = {"values": ["p1", "p2"]}
|
||||
body_ = {self.response_key: data_}
|
||||
url_ = "test_url_post"
|
||||
self.manager.api.client.post = Mock(return_value=(url_, body_))
|
||||
self.manager.api.client.post = mock.Mock(return_value=(url_, body_))
|
||||
l = self.manager._list("url", self.response_key,
|
||||
obj_class, "something")
|
||||
data = data_["values"]
|
||||
@ -250,14 +248,13 @@ class ManagerListTest(ManagerTest):
|
||||
data_ = {"v1": "1", "v2": "2"}
|
||||
body_ = {self.response_key: data_}
|
||||
url_ = "test_url_post"
|
||||
self.manager.api.client.post = Mock(return_value=(url_, body_))
|
||||
self.manager.api.client.post = mock.Mock(return_value=(url_, body_))
|
||||
l = self.manager._list("url", self.response_key,
|
||||
obj_class, "something")
|
||||
self.assertEqual(len(data_), len(l))
|
||||
|
||||
|
||||
class FakeResource(object):
|
||||
|
||||
def __init__(self, _id, properties):
|
||||
self.id = _id
|
||||
try:
|
||||
@ -271,7 +268,6 @@ class FakeResource(object):
|
||||
|
||||
|
||||
class FakeManager(base.ManagerWithFind):
|
||||
|
||||
resource_class = FakeResource
|
||||
|
||||
resources = [
|
||||
@ -291,8 +287,7 @@ class FakeManager(base.ManagerWithFind):
|
||||
return self.resources
|
||||
|
||||
|
||||
class FindResourceTestCase(TestCase):
|
||||
|
||||
class FindResourceTestCase(testtools.TestCase):
|
||||
def setUp(self):
|
||||
super(FindResourceTestCase, self).setUp()
|
||||
self.manager = FakeManager(None)
|
||||
@ -324,8 +319,7 @@ class FindResourceTestCase(TestCase):
|
||||
self.assertEqual(output, self.manager.get('4242'))
|
||||
|
||||
|
||||
class ResourceTest(TestCase):
|
||||
|
||||
class ResourceTest(testtools.TestCase):
|
||||
def setUp(self):
|
||||
super(ResourceTest, self).setUp()
|
||||
self.orig___init__ = base.Resource.__init__
|
||||
@ -335,8 +329,8 @@ class ResourceTest(TestCase):
|
||||
base.Resource.__init__ = self.orig___init__
|
||||
|
||||
def test___init__(self):
|
||||
manager = Mock()
|
||||
manager.write_to_completion_cache = Mock(return_value=None)
|
||||
manager = mock.Mock()
|
||||
manager.write_to_completion_cache = mock.Mock(return_value=None)
|
||||
|
||||
info_ = {}
|
||||
robj = base.Resource(manager, info_)
|
||||
@ -370,8 +364,8 @@ class ResourceTest(TestCase):
|
||||
self.assertEqual(4, manager.write_to_completion_cache.call_count)
|
||||
|
||||
def test_human_id(self):
|
||||
manager = Mock()
|
||||
manager.write_to_completion_cache = Mock(return_value=None)
|
||||
manager = mock.Mock()
|
||||
manager.write_to_completion_cache = mock.Mock(return_value=None)
|
||||
|
||||
info_ = {"name": "test-human-id"}
|
||||
robj = base.Resource(manager, info_)
|
||||
@ -384,7 +378,7 @@ class ResourceTest(TestCase):
|
||||
self.assertEqual("new-human-id", robj.human_id)
|
||||
|
||||
def get_mock_resource_obj(self):
|
||||
base.Resource.__init__ = Mock(return_value=None)
|
||||
base.Resource.__init__ = mock.Mock(return_value=None)
|
||||
robj = base.Resource()
|
||||
return robj
|
||||
|
||||
@ -414,19 +408,19 @@ class ResourceTest(TestCase):
|
||||
|
||||
def test_get(self):
|
||||
robj = self.get_mock_resource_obj()
|
||||
manager = Mock()
|
||||
manager = mock.Mock()
|
||||
manager.get = None
|
||||
|
||||
robj.manager = object()
|
||||
robj.get()
|
||||
|
||||
manager = Mock()
|
||||
robj.manager = Mock()
|
||||
manager = mock.Mock()
|
||||
robj.manager = mock.Mock()
|
||||
|
||||
robj.id = "id"
|
||||
new = Mock()
|
||||
new = mock.Mock()
|
||||
new._info = {"name": "test-human-id", "test_attr": 5}
|
||||
robj.manager.get = Mock(return_value=new)
|
||||
robj.manager.get = mock.Mock(return_value=new)
|
||||
robj.get()
|
||||
self.assertEqual("test-human-id", robj.name)
|
||||
self.assertEqual(5, robj.test_attr)
|
||||
@ -451,7 +445,7 @@ class ResourceTest(TestCase):
|
||||
self.assertTrue(robj.__eq__(other))
|
||||
|
||||
# not instance of the same class
|
||||
other = Mock()
|
||||
other = mock.Mock()
|
||||
self.assertNotTrue(robj.__eq__(other))
|
||||
|
||||
def test_is_loaded(self):
|
||||
|
@ -17,24 +17,25 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from testtools import TestCase
|
||||
import testtools
|
||||
|
||||
import troveclient.v1.client
|
||||
from troveclient.client import get_version_map
|
||||
|
||||
from troveclient import client as other_client
|
||||
from troveclient.openstack.common.apiclient import client
|
||||
from troveclient.openstack.common.apiclient import exceptions
|
||||
|
||||
|
||||
class ClientTest(TestCase):
|
||||
class ClientTest(testtools.TestCase):
|
||||
|
||||
def test_get_client_class_v1(self):
|
||||
version_map = get_version_map()
|
||||
version_map = other_client.get_version_map()
|
||||
output = client.BaseClient.get_class('database',
|
||||
'1.0', version_map)
|
||||
self.assertEqual(output, troveclient.v1.client.Client)
|
||||
|
||||
def test_get_client_class_unknown(self):
|
||||
version_map = get_version_map()
|
||||
version_map = other_client.get_version_map()
|
||||
self.assertRaises(exceptions.UnsupportedVersion,
|
||||
client.BaseClient.get_class, 'database',
|
||||
'0', version_map)
|
||||
|
@ -17,18 +17,18 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from testtools import TestCase
|
||||
from mock import Mock
|
||||
import testtools
|
||||
import mock
|
||||
|
||||
from troveclient import common
|
||||
|
||||
|
||||
class CommonTest(TestCase):
|
||||
class CommonTest(testtools.TestCase):
|
||||
|
||||
def test_check_for_exceptions(self):
|
||||
status = [400, 422, 500]
|
||||
for s in status:
|
||||
resp = Mock()
|
||||
resp = mock.Mock()
|
||||
resp.status_code = s
|
||||
self.assertRaises(Exception,
|
||||
common.check_for_exceptions, resp, "body")
|
||||
@ -46,7 +46,7 @@ class CommonTest(TestCase):
|
||||
common.limit_url(url, limit=limit, marker=marker))
|
||||
|
||||
|
||||
class PaginatedTest(TestCase):
|
||||
class PaginatedTest(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(PaginatedTest, self).setUp()
|
||||
@ -88,7 +88,6 @@ class PaginatedTest(TestCase):
|
||||
|
||||
def test___reversed__(self):
|
||||
itr = self.pgn.__reversed__()
|
||||
expected = ["item2", "item1"]
|
||||
self.assertEqual("item2", next(itr))
|
||||
self.assertEqual("item1", next(itr))
|
||||
self.assertRaises(StopIteration, next, itr)
|
||||
|
@ -17,8 +17,8 @@
|
||||
# under the License.
|
||||
|
||||
|
||||
from testtools import TestCase
|
||||
from mock import Mock
|
||||
import testtools
|
||||
import mock
|
||||
|
||||
from troveclient.v1 import datastores
|
||||
from troveclient import base
|
||||
@ -29,14 +29,14 @@ Unit tests for datastores.py
|
||||
"""
|
||||
|
||||
|
||||
class DatastoreTest(TestCase):
|
||||
class DatastoreTest(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(DatastoreTest, self).setUp()
|
||||
self.orig__init = datastores.Datastore.__init__
|
||||
datastores.Datastore.__init__ = Mock(return_value=None)
|
||||
datastores.Datastore.__init__ = mock.Mock(return_value=None)
|
||||
self.datastore = datastores.Datastore()
|
||||
self.datastore.manager = Mock()
|
||||
self.datastore.manager = mock.Mock()
|
||||
|
||||
def tearDown(self):
|
||||
super(DatastoreTest, self).tearDown()
|
||||
@ -48,19 +48,19 @@ class DatastoreTest(TestCase):
|
||||
self.datastore.__repr__())
|
||||
|
||||
|
||||
class DatastoresTest(TestCase):
|
||||
class DatastoresTest(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(DatastoresTest, self).setUp()
|
||||
self.orig__init = datastores.Datastores.__init__
|
||||
datastores.Datastores.__init__ = Mock(return_value=None)
|
||||
datastores.Datastores.__init__ = mock.Mock(return_value=None)
|
||||
self.datastores = datastores.Datastores()
|
||||
self.datastores.api = Mock()
|
||||
self.datastores.api.client = Mock()
|
||||
self.datastores.resource_class = Mock(return_value="ds-1")
|
||||
self.datastores.api = mock.Mock()
|
||||
self.datastores.api.client = mock.Mock()
|
||||
self.datastores.resource_class = mock.Mock(return_value="ds-1")
|
||||
|
||||
self.orig_base_getid = base.getid
|
||||
base.getid = Mock(return_value="datastore1")
|
||||
base.getid = mock.Mock(return_value="datastore1")
|
||||
|
||||
def tearDown(self):
|
||||
super(DatastoresTest, self).tearDown()
|
||||
@ -71,7 +71,7 @@ class DatastoresTest(TestCase):
|
||||
def side_effect_func(path, inst, limit, marker):
|
||||
return path, inst, limit, marker
|
||||
|
||||
self.datastores._list = Mock(side_effect=side_effect_func)
|
||||
self.datastores._list = mock.Mock(side_effect=side_effect_func)
|
||||
limit = "test-limit"
|
||||
marker = "test-marker"
|
||||
expected = ("/datastores", "datastores", limit, marker)
|
||||
@ -81,26 +81,26 @@ class DatastoresTest(TestCase):
|
||||
def side_effect_func(path, inst):
|
||||
return path, inst
|
||||
|
||||
self.datastores._get = Mock(side_effect=side_effect_func)
|
||||
self.datastores._get = mock.Mock(side_effect=side_effect_func)
|
||||
self.assertEqual(('/datastores/datastore1',
|
||||
'datastore'),
|
||||
self.datastores.get(1))
|
||||
|
||||
|
||||
class DatastoreVersionsTest(TestCase):
|
||||
class DatastoreVersionsTest(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(DatastoreVersionsTest, self).setUp()
|
||||
self.orig__init = datastores.DatastoreVersions.__init__
|
||||
datastores.DatastoreVersions.__init__ = Mock(return_value=None)
|
||||
datastores.DatastoreVersions.__init__ = mock.Mock(return_value=None)
|
||||
self.datastore_versions = datastores.DatastoreVersions()
|
||||
self.datastore_versions.api = Mock()
|
||||
self.datastore_versions.api.client = Mock()
|
||||
self.datastore_versions.resource_class = Mock(
|
||||
self.datastore_versions.api = mock.Mock()
|
||||
self.datastore_versions.api.client = mock.Mock()
|
||||
self.datastore_versions.resource_class = mock.Mock(
|
||||
return_value="ds_version-1")
|
||||
|
||||
self.orig_base_getid = base.getid
|
||||
base.getid = Mock(return_value="datastore_version1")
|
||||
base.getid = mock.Mock(return_value="datastore_version1")
|
||||
|
||||
def tearDown(self):
|
||||
super(DatastoreVersionsTest, self).tearDown()
|
||||
@ -111,7 +111,7 @@ class DatastoreVersionsTest(TestCase):
|
||||
def side_effect_func(path, inst, limit, marker):
|
||||
return path, inst, limit, marker
|
||||
|
||||
self.datastore_versions._list = Mock(side_effect=side_effect_func)
|
||||
self.datastore_versions._list = mock.Mock(side_effect=side_effect_func)
|
||||
limit = "test-limit"
|
||||
marker = "test-marker"
|
||||
expected = ("/datastores/datastore1/versions",
|
||||
@ -123,7 +123,7 @@ class DatastoreVersionsTest(TestCase):
|
||||
def side_effect_func(path, inst):
|
||||
return path, inst
|
||||
|
||||
self.datastore_versions._get = Mock(side_effect=side_effect_func)
|
||||
self.datastore_versions._get = mock.Mock(side_effect=side_effect_func)
|
||||
self.assertEqual(('/datastores/datastore1/versions/'
|
||||
'datastore_version1',
|
||||
'version'),
|
||||
|
@ -17,8 +17,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from testtools import TestCase
|
||||
from mock import Mock
|
||||
import testtools
|
||||
import mock
|
||||
|
||||
from troveclient.v1 import instances
|
||||
from troveclient import base
|
||||
@ -28,14 +28,14 @@ Unit tests for instances.py
|
||||
"""
|
||||
|
||||
|
||||
class InstanceTest(TestCase):
|
||||
class InstanceTest(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(InstanceTest, self).setUp()
|
||||
self.orig__init = instances.Instance.__init__
|
||||
instances.Instance.__init__ = Mock(return_value=None)
|
||||
instances.Instance.__init__ = mock.Mock(return_value=None)
|
||||
self.instance = instances.Instance()
|
||||
self.instance.manager = Mock()
|
||||
self.instance.manager = mock.Mock()
|
||||
|
||||
def tearDown(self):
|
||||
super(InstanceTest, self).tearDown()
|
||||
@ -47,37 +47,37 @@ class InstanceTest(TestCase):
|
||||
|
||||
def test_list_databases(self):
|
||||
db_list = ['database1', 'database2']
|
||||
self.instance.manager.databases = Mock()
|
||||
self.instance.manager.databases.list = Mock(return_value=db_list)
|
||||
self.instance.manager.databases = mock.Mock()
|
||||
self.instance.manager.databases.list = mock.Mock(return_value=db_list)
|
||||
self.assertEqual(db_list, self.instance.list_databases())
|
||||
|
||||
def test_delete(self):
|
||||
db_delete_mock = Mock(return_value=None)
|
||||
db_delete_mock = mock.Mock(return_value=None)
|
||||
self.instance.manager.delete = db_delete_mock
|
||||
self.instance.delete()
|
||||
self.assertEqual(1, db_delete_mock.call_count)
|
||||
|
||||
def test_restart(self):
|
||||
db_restart_mock = Mock(return_value=None)
|
||||
db_restart_mock = mock.Mock(return_value=None)
|
||||
self.instance.manager.restart = db_restart_mock
|
||||
self.instance.id = 1
|
||||
self.instance.restart()
|
||||
self.assertEqual(1, db_restart_mock.call_count)
|
||||
|
||||
|
||||
class InstancesTest(TestCase):
|
||||
class InstancesTest(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(InstancesTest, self).setUp()
|
||||
self.orig__init = instances.Instances.__init__
|
||||
instances.Instances.__init__ = Mock(return_value=None)
|
||||
instances.Instances.__init__ = mock.Mock(return_value=None)
|
||||
self.instances = instances.Instances()
|
||||
self.instances.api = Mock()
|
||||
self.instances.api.client = Mock()
|
||||
self.instances.resource_class = Mock(return_value="instance-1")
|
||||
self.instances.api = mock.Mock()
|
||||
self.instances.api.client = mock.Mock()
|
||||
self.instances.resource_class = mock.Mock(return_value="instance-1")
|
||||
|
||||
self.orig_base_getid = base.getid
|
||||
base.getid = Mock(return_value="instance1")
|
||||
base.getid = mock.Mock(return_value="instance1")
|
||||
|
||||
def tearDown(self):
|
||||
super(InstancesTest, self).tearDown()
|
||||
@ -88,7 +88,7 @@ class InstancesTest(TestCase):
|
||||
def side_effect_func(path, body, inst):
|
||||
return path, body, inst
|
||||
|
||||
self.instances._create = Mock(side_effect=side_effect_func)
|
||||
self.instances._create = mock.Mock(side_effect=side_effect_func)
|
||||
p, b, i = self.instances.create("test-name", 103, "test-volume",
|
||||
['db1', 'db2'], ['u1', 'u2'],
|
||||
datastore="datastore",
|
||||
@ -105,15 +105,17 @@ class InstancesTest(TestCase):
|
||||
self.assertEqual(103, b["instance"]["flavorRef"])
|
||||
|
||||
def test__list(self):
|
||||
self.instances.api.client.get = Mock(return_value=('resp', None))
|
||||
self.instances.api.client.get = mock.Mock(return_value=('resp', None))
|
||||
self.assertRaises(Exception, self.instances._list, "url", None)
|
||||
|
||||
body = Mock()
|
||||
body.get = Mock(return_value=[{'href': 'http://test.net/test_file',
|
||||
'rel': 'next'}])
|
||||
body.__getitem__ = Mock(return_value='instance1')
|
||||
#self.instances.resource_class = Mock(return_value="instance-1")
|
||||
self.instances.api.client.get = Mock(return_value=('resp', body))
|
||||
body = mock.Mock()
|
||||
body.get = mock.Mock(
|
||||
return_value=[{'href': 'http://test.net/test_file',
|
||||
'rel': 'next'}]
|
||||
)
|
||||
body.__getitem__ = mock.Mock(return_value='instance1')
|
||||
#self.instances.resource_class = mock.Mock(return_value="instance-1")
|
||||
self.instances.api.client.get = mock.Mock(return_value=('resp', body))
|
||||
_expected = [{'href': 'http://test.net/test_file', 'rel': 'next'}]
|
||||
self.assertEqual(_expected, self.instances._list("url", None).links)
|
||||
|
||||
@ -121,7 +123,7 @@ class InstancesTest(TestCase):
|
||||
def side_effect_func(path, inst, limit, marker):
|
||||
return path, inst, limit, marker
|
||||
|
||||
self.instances._list = Mock(side_effect=side_effect_func)
|
||||
self.instances._list = mock.Mock(side_effect=side_effect_func)
|
||||
limit = "test-limit"
|
||||
marker = "test-marker"
|
||||
expected = ("/instances", "instances", limit, marker)
|
||||
@ -131,27 +133,27 @@ class InstancesTest(TestCase):
|
||||
def side_effect_func(path, inst):
|
||||
return path, inst
|
||||
|
||||
self.instances._get = Mock(side_effect=side_effect_func)
|
||||
self.instances._get = mock.Mock(side_effect=side_effect_func)
|
||||
self.assertEqual(('/instances/instance1', 'instance'),
|
||||
self.instances.get(1))
|
||||
|
||||
def test_delete(self):
|
||||
resp = Mock()
|
||||
resp = mock.Mock()
|
||||
resp.status_code = 200
|
||||
body = None
|
||||
self.instances.api.client.delete = Mock(return_value=(resp, body))
|
||||
self.instances.api.client.delete = mock.Mock(return_value=(resp, body))
|
||||
self.instances.delete('instance1')
|
||||
resp.status_code = 500
|
||||
self.assertRaises(Exception, self.instances.delete, 'instance1')
|
||||
|
||||
def test__action(self):
|
||||
body = Mock()
|
||||
resp = Mock()
|
||||
body = mock.Mock()
|
||||
resp = mock.Mock()
|
||||
resp.status_code = 200
|
||||
self.instances.api.client.post = Mock(return_value=(resp, body))
|
||||
self.instances.api.client.post = mock.Mock(return_value=(resp, body))
|
||||
self.assertEqual('instance-1', self.instances._action(1, body))
|
||||
|
||||
self.instances.api.client.post = Mock(return_value=(resp, None))
|
||||
self.instances.api.client.post = mock.Mock(return_value=(resp, None))
|
||||
self.assertEqual(None, self.instances._action(1, body))
|
||||
|
||||
def _set_action_mock(self):
|
||||
@ -161,7 +163,7 @@ class InstancesTest(TestCase):
|
||||
|
||||
self._instance_id = None
|
||||
self._body = None
|
||||
self.instances._action = Mock(side_effect=side_effect_func)
|
||||
self.instances._action = mock.Mock(side_effect=side_effect_func)
|
||||
|
||||
def test_resize_volume(self):
|
||||
self._set_action_mock()
|
||||
@ -182,7 +184,7 @@ class InstancesTest(TestCase):
|
||||
self.assertEqual({'restart': {}}, self._body)
|
||||
|
||||
|
||||
class InstanceStatusTest(TestCase):
|
||||
class InstanceStatusTest(testtools.TestCase):
|
||||
|
||||
def test_constants(self):
|
||||
self.assertEqual("ACTIVE", instances.InstanceStatus.ACTIVE)
|
||||
|
@ -17,26 +17,26 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from testtools import TestCase
|
||||
from mock import Mock
|
||||
import testtools
|
||||
import mock
|
||||
from troveclient.v1 import limits
|
||||
|
||||
|
||||
class LimitsTest(TestCase):
|
||||
class LimitsTest(testtools.TestCase):
|
||||
"""
|
||||
This class tests the calling code for the Limits API
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
super(LimitsTest, self).setUp()
|
||||
self.limits = limits.Limits(Mock())
|
||||
self.limits.api.client = Mock()
|
||||
self.limits = limits.Limits(mock.Mock())
|
||||
self.limits.api.client = mock.Mock()
|
||||
|
||||
def tearDown(self):
|
||||
super(LimitsTest, self).tearDown()
|
||||
|
||||
def test_list(self):
|
||||
resp = Mock()
|
||||
resp = mock.Mock()
|
||||
resp.status_code = 200
|
||||
body = {"limits":
|
||||
[
|
||||
@ -71,7 +71,7 @@ class LimitsTest(TestCase):
|
||||
'remaining': 2, 'unit': 'MINUTE'}]}
|
||||
response = (resp, body)
|
||||
|
||||
mock_get = Mock(return_value=response)
|
||||
mock_get = mock.Mock(return_value=response)
|
||||
self.limits.api.client.get = mock_get
|
||||
self.assertIsNotNone(self.limits.list())
|
||||
mock_get.assert_called_once_with("/limits")
|
||||
@ -84,7 +84,7 @@ class LimitsTest(TestCase):
|
||||
def _check_error_response(self, status_code):
|
||||
RESPONSE_KEY = "limits"
|
||||
|
||||
resp = Mock()
|
||||
resp = mock.Mock()
|
||||
resp.status_code = status_code
|
||||
body = {RESPONSE_KEY: {
|
||||
'absolute': {},
|
||||
@ -92,6 +92,6 @@ class LimitsTest(TestCase):
|
||||
{'limit': []}]}}
|
||||
response = (resp, body)
|
||||
|
||||
mock_get = Mock(return_value=response)
|
||||
mock_get = mock.Mock(return_value=response)
|
||||
self.limits.api.client.get = mock_get
|
||||
self.assertRaises(Exception, self.limits.list)
|
||||
|
@ -17,8 +17,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from testtools import TestCase
|
||||
from mock import Mock
|
||||
import testtools
|
||||
import mock
|
||||
|
||||
from troveclient.v1 import management
|
||||
from troveclient import base
|
||||
@ -28,12 +28,12 @@ Unit tests for management.py
|
||||
"""
|
||||
|
||||
|
||||
class RootHistoryTest(TestCase):
|
||||
class RootHistoryTest(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(RootHistoryTest, self).setUp()
|
||||
self.orig__init = management.RootHistory.__init__
|
||||
management.RootHistory.__init__ = Mock(return_value=None)
|
||||
management.RootHistory.__init__ = mock.Mock(return_value=None)
|
||||
|
||||
def tearDown(self):
|
||||
super(RootHistoryTest, self).tearDown()
|
||||
@ -48,19 +48,19 @@ class RootHistoryTest(TestCase):
|
||||
root_history.__repr__())
|
||||
|
||||
|
||||
class ManagementTest(TestCase):
|
||||
class ManagementTest(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(ManagementTest, self).setUp()
|
||||
self.orig__init = management.Management.__init__
|
||||
management.Management.__init__ = Mock(return_value=None)
|
||||
management.Management.__init__ = mock.Mock(return_value=None)
|
||||
self.management = management.Management()
|
||||
self.management.api = Mock()
|
||||
self.management.api.client = Mock()
|
||||
self.management.api = mock.Mock()
|
||||
self.management.api.client = mock.Mock()
|
||||
|
||||
self.orig_hist__init = management.RootHistory.__init__
|
||||
self.orig_base_getid = base.getid
|
||||
base.getid = Mock(return_value="instance1")
|
||||
base.getid = mock.Mock(return_value="instance1")
|
||||
|
||||
def tearDown(self):
|
||||
super(ManagementTest, self).tearDown()
|
||||
@ -69,22 +69,24 @@ class ManagementTest(TestCase):
|
||||
base.getid = self.orig_base_getid
|
||||
|
||||
def test__list(self):
|
||||
self.management.api.client.get = Mock(return_value=('resp', None))
|
||||
self.management.api.client.get = mock.Mock(return_value=('resp', None))
|
||||
self.assertRaises(Exception, self.management._list, "url", None)
|
||||
|
||||
body = Mock()
|
||||
body.get = Mock(return_value=[{'href': 'http://test.net/test_file',
|
||||
'rel': 'next'}])
|
||||
body.__getitem__ = Mock(return_value='instance1')
|
||||
self.management.resource_class = Mock(return_value="instance-1")
|
||||
self.management.api.client.get = Mock(return_value=('resp', body))
|
||||
body = mock.Mock()
|
||||
body.get = mock.Mock(
|
||||
return_value=[{'href': 'http://test.net/test_file',
|
||||
'rel': 'next'}]
|
||||
)
|
||||
body.__getitem__ = mock.Mock(return_value='instance1')
|
||||
self.management.resource_class = mock.Mock(return_value="instance-1")
|
||||
self.management.api.client.get = mock.Mock(return_value=('resp', body))
|
||||
_expected = [{'href': 'http://test.net/test_file', 'rel': 'next'}]
|
||||
self.assertEqual(_expected, self.management._list("url", None).links)
|
||||
|
||||
def test_show(self):
|
||||
def side_effect_func(path, instance):
|
||||
return path, instance
|
||||
self.management._get = Mock(side_effect=side_effect_func)
|
||||
self.management._get = mock.Mock(side_effect=side_effect_func)
|
||||
p, i = self.management.show(1)
|
||||
self.assertEqual(('/mgmt/instances/instance1', 'instance'), (p, i))
|
||||
|
||||
@ -92,25 +94,27 @@ class ManagementTest(TestCase):
|
||||
def side_effect_func(url, name, limit, marker):
|
||||
return url
|
||||
|
||||
self.management._list = Mock(side_effect=side_effect_func)
|
||||
self.management._list = mock.Mock(side_effect=side_effect_func)
|
||||
self.assertEqual('/mgmt/instances?deleted=true',
|
||||
self.management.index(deleted=True))
|
||||
self.assertEqual('/mgmt/instances?deleted=false',
|
||||
self.management.index(deleted=False))
|
||||
|
||||
def test_root_enabled_history(self):
|
||||
self.management.api.client.get = Mock(return_value=('resp', None))
|
||||
self.management.api.client.get = mock.Mock(return_value=('resp', None))
|
||||
self.assertRaises(Exception,
|
||||
self.management.root_enabled_history, "instance")
|
||||
body = {'root_history': 'rh'}
|
||||
self.management.api.client.get = Mock(return_value=('resp', body))
|
||||
management.RootHistory.__init__ = Mock(return_value=None)
|
||||
self.management.api.client.get = mock.Mock(return_value=('resp', body))
|
||||
management.RootHistory.__init__ = mock.Mock(return_value=None)
|
||||
rh = self.management.root_enabled_history("instance")
|
||||
self.assertTrue(isinstance(rh, management.RootHistory))
|
||||
|
||||
def test__action(self):
|
||||
resp = Mock()
|
||||
self.management.api.client.post = Mock(return_value=(resp, 'body'))
|
||||
resp = mock.Mock()
|
||||
self.management.api.client.post = mock.Mock(
|
||||
return_value=(resp, 'body')
|
||||
)
|
||||
resp.status_code = 200
|
||||
self.management._action(1, 'body')
|
||||
self.assertEqual(1, self.management.api.client.post.call_count)
|
||||
@ -123,7 +127,7 @@ class ManagementTest(TestCase):
|
||||
|
||||
def side_effect_func(instance_id, body):
|
||||
self.body_ = body
|
||||
self.management._action = Mock(side_effect=side_effect_func)
|
||||
self.management._action = mock.Mock(side_effect=side_effect_func)
|
||||
|
||||
def test_stop(self):
|
||||
self._mock_action()
|
||||
@ -163,18 +167,18 @@ class ManagementTest(TestCase):
|
||||
self.assertEqual({'reset-task-status': {}}, self.body_)
|
||||
|
||||
|
||||
class MgmtFlavorsTest(TestCase):
|
||||
class MgmtFlavorsTest(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(MgmtFlavorsTest, self).setUp()
|
||||
self.orig__init = management.MgmtFlavors.__init__
|
||||
management.MgmtFlavors.__init__ = Mock(return_value=None)
|
||||
management.MgmtFlavors.__init__ = mock.Mock(return_value=None)
|
||||
self.flavors = management.MgmtFlavors()
|
||||
self.flavors.api = Mock()
|
||||
self.flavors.api.client = Mock()
|
||||
self.flavors.resource_class = Mock(return_value="flavor-1")
|
||||
self.flavors.api = mock.Mock()
|
||||
self.flavors.api.client = mock.Mock()
|
||||
self.flavors.resource_class = mock.Mock(return_value="flavor-1")
|
||||
self.orig_base_getid = base.getid
|
||||
base.getid = Mock(return_value="flavor1")
|
||||
base.getid = mock.Mock(return_value="flavor1")
|
||||
|
||||
def tearDown(self):
|
||||
super(MgmtFlavorsTest, self).tearDown()
|
||||
@ -185,7 +189,7 @@ class MgmtFlavorsTest(TestCase):
|
||||
def side_effect_func(path, body, inst):
|
||||
return path, body, inst
|
||||
|
||||
self.flavors._create = Mock(side_effect=side_effect_func)
|
||||
self.flavors._create = mock.Mock(side_effect=side_effect_func)
|
||||
p, b, i = self.flavors.create("test-name", 1024, 30, 2, 1)
|
||||
self.assertEqual("/mgmt/flavors", p)
|
||||
self.assertEqual("flavor", i)
|
||||
|
@ -17,8 +17,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from testtools import TestCase
|
||||
from mock import Mock
|
||||
import testtools
|
||||
import mock
|
||||
|
||||
from troveclient.v1 import security_groups
|
||||
|
||||
@ -27,12 +27,12 @@ Unit tests for security_groups.py
|
||||
"""
|
||||
|
||||
|
||||
class SecGroupTest(TestCase):
|
||||
class SecGroupTest(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(SecGroupTest, self).setUp()
|
||||
self.orig__init = security_groups.SecurityGroup.__init__
|
||||
security_groups.SecurityGroup.__init__ = Mock(return_value=None)
|
||||
security_groups.SecurityGroup.__init__ = mock.Mock(return_value=None)
|
||||
self.security_group = security_groups.SecurityGroup()
|
||||
self.security_groups = security_groups.SecurityGroups(1)
|
||||
|
||||
@ -47,26 +47,30 @@ class SecGroupTest(TestCase):
|
||||
|
||||
def test_list(self):
|
||||
sec_group_list = ['secgroup1', 'secgroup2']
|
||||
self.security_groups.list = Mock(return_value=sec_group_list)
|
||||
self.security_groups.list = mock.Mock(return_value=sec_group_list)
|
||||
self.assertEqual(sec_group_list, self.security_groups.list())
|
||||
|
||||
def test_get(self):
|
||||
def side_effect_func(path, inst):
|
||||
return path, inst
|
||||
|
||||
self.security_groups._get = Mock(side_effect=side_effect_func)
|
||||
self.security_groups._get = mock.Mock(side_effect=side_effect_func)
|
||||
self.security_group.id = 1
|
||||
self.assertEqual(('/security-groups/1', 'security_group'),
|
||||
self.security_groups.get(self.security_group))
|
||||
|
||||
|
||||
class SecGroupRuleTest(TestCase):
|
||||
class SecGroupRuleTest(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(SecGroupRuleTest, self).setUp()
|
||||
self.orig__init = security_groups.SecurityGroupRule.__init__
|
||||
security_groups.SecurityGroupRule.__init__ = Mock(return_value=None)
|
||||
security_groups.SecurityGroupRules.__init__ = Mock(return_value=None)
|
||||
security_groups.SecurityGroupRule.__init__ = mock.Mock(
|
||||
return_value=None
|
||||
)
|
||||
security_groups.SecurityGroupRules.__init__ = mock.Mock(
|
||||
return_value=None
|
||||
)
|
||||
self.security_group_rule = security_groups.SecurityGroupRule()
|
||||
self.security_group_rules = security_groups.SecurityGroupRules()
|
||||
|
||||
@ -95,7 +99,9 @@ class SecGroupRuleTest(TestCase):
|
||||
def side_effect_func(path, body, inst):
|
||||
return path, body, inst
|
||||
|
||||
self.security_group_rules._create = Mock(side_effect=side_effect_func)
|
||||
self.security_group_rules._create = mock.Mock(
|
||||
side_effect=side_effect_func
|
||||
)
|
||||
p, b, i = self.security_group_rules.create(1, "tcp",
|
||||
80, 80, "0.0.0.0//0")
|
||||
self.assertEqual("/security-group-rules", p)
|
||||
@ -107,13 +113,14 @@ class SecGroupRuleTest(TestCase):
|
||||
self.assertEqual("0.0.0.0//0", b["security_group_rule"]["cidr"])
|
||||
|
||||
def test_delete(self):
|
||||
resp = Mock()
|
||||
resp = mock.Mock()
|
||||
resp.status = 200
|
||||
body = None
|
||||
self.security_group_rules.api = Mock()
|
||||
self.security_group_rules.api.client = Mock()
|
||||
self.security_group_rules.api.client.delete = \
|
||||
Mock(return_value=(resp, body))
|
||||
self.security_group_rules.api = mock.Mock()
|
||||
self.security_group_rules.api.client = mock.Mock()
|
||||
self.security_group_rules.api.client.delete = mock.Mock(
|
||||
return_value=(resp, body)
|
||||
)
|
||||
self.security_group_rules.delete(self.id)
|
||||
resp.status_code = 500
|
||||
self.assertRaises(Exception, self.security_group_rules.delete,
|
||||
|
@ -17,8 +17,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from testtools import TestCase
|
||||
from mock import Mock
|
||||
import testtools
|
||||
import mock
|
||||
|
||||
from troveclient.v1 import users
|
||||
from troveclient import base
|
||||
@ -28,11 +28,11 @@ Unit tests for users.py
|
||||
"""
|
||||
|
||||
|
||||
class UserTest(TestCase):
|
||||
class UserTest(testtools.TestCase):
|
||||
def setUp(self):
|
||||
super(UserTest, self).setUp()
|
||||
self.orig__init = users.User.__init__
|
||||
users.User.__init__ = Mock(return_value=None)
|
||||
users.User.__init__ = mock.Mock(return_value=None)
|
||||
self.user = users.User()
|
||||
|
||||
def tearDown(self):
|
||||
@ -44,17 +44,17 @@ class UserTest(TestCase):
|
||||
self.assertEqual('<User: user-1>', self.user.__repr__())
|
||||
|
||||
|
||||
class UsersTest(TestCase):
|
||||
class UsersTest(testtools.TestCase):
|
||||
def setUp(self):
|
||||
super(UsersTest, self).setUp()
|
||||
self.orig__init = users.Users.__init__
|
||||
users.Users.__init__ = Mock(return_value=None)
|
||||
users.Users.__init__ = mock.Mock(return_value=None)
|
||||
self.users = users.Users()
|
||||
self.users.api = Mock()
|
||||
self.users.api.client = Mock()
|
||||
self.users.api = mock.Mock()
|
||||
self.users.api.client = mock.Mock()
|
||||
|
||||
self.orig_base_getid = base.getid
|
||||
base.getid = Mock(return_value="instance1")
|
||||
base.getid = mock.Mock(return_value="instance1")
|
||||
|
||||
def tearDown(self):
|
||||
super(UsersTest, self).tearDown()
|
||||
@ -62,7 +62,7 @@ class UsersTest(TestCase):
|
||||
base.getid = self.orig_base_getid
|
||||
|
||||
def _get_mock_method(self):
|
||||
self._resp = Mock()
|
||||
self._resp = mock.Mock()
|
||||
self._body = None
|
||||
self._url = None
|
||||
|
||||
@ -71,7 +71,7 @@ class UsersTest(TestCase):
|
||||
self._url = url
|
||||
return (self._resp, body)
|
||||
|
||||
return Mock(side_effect=side_effect_func)
|
||||
return mock.Mock(side_effect=side_effect_func)
|
||||
|
||||
def _build_fake_user(self, name, hostname=None, password=None,
|
||||
databases=None):
|
||||
@ -122,23 +122,25 @@ class UsersTest(TestCase):
|
||||
return val
|
||||
|
||||
key = 'key'
|
||||
body = Mock()
|
||||
body.get = Mock(return_value=[{'href': 'http://test.net/test_file',
|
||||
'rel': 'next'}])
|
||||
body.__getitem__ = Mock(return_value=["test-value"])
|
||||
body = mock.Mock()
|
||||
body.get = mock.Mock(
|
||||
return_value=[{'href': 'http://test.net/test_file',
|
||||
'rel': 'next'}]
|
||||
)
|
||||
body.__getitem__ = mock.Mock(return_value=["test-value"])
|
||||
|
||||
resp = Mock()
|
||||
resp = mock.Mock()
|
||||
resp.status_code = 200
|
||||
self.users.resource_class = Mock(side_effect=side_effect_func)
|
||||
self.users.api.client.get = Mock(return_value=(resp, body))
|
||||
self.users.resource_class = mock.Mock(side_effect=side_effect_func)
|
||||
self.users.api.client.get = mock.Mock(return_value=(resp, body))
|
||||
self.assertEqual(["test-value"], self.users._list('url', key).items)
|
||||
|
||||
self.users.api.client.get = Mock(return_value=(resp, None))
|
||||
self.users.api.client.get = mock.Mock(return_value=(resp, None))
|
||||
self.assertRaises(Exception, self.users._list, 'url', None)
|
||||
|
||||
def test_list(self):
|
||||
def side_effect_func(path, user, limit, marker):
|
||||
return path
|
||||
|
||||
self.users._list = Mock(side_effect=side_effect_func)
|
||||
self.users._list = mock.Mock(side_effect=side_effect_func)
|
||||
self.assertEqual('/instances/instance1/users', self.users.list(1))
|
||||
|
@ -19,11 +19,11 @@
|
||||
|
||||
import os
|
||||
import six
|
||||
from testtools import TestCase
|
||||
import testtools
|
||||
from troveclient import utils
|
||||
|
||||
|
||||
class UtilsTest(TestCase):
|
||||
class UtilsTest(testtools.TestCase):
|
||||
|
||||
def test_add_hookable_mixin(self):
|
||||
def func():
|
||||
|
@ -17,7 +17,7 @@
|
||||
# under the License.
|
||||
|
||||
from troveclient import base
|
||||
from troveclient.common import check_for_exceptions
|
||||
from troveclient import common
|
||||
|
||||
|
||||
class Account(base.Resource):
|
||||
@ -46,7 +46,7 @@ class Accounts(base.ManagerWithFind):
|
||||
|
||||
url = "/mgmt/accounts"
|
||||
resp, body = self.api.client.get(url)
|
||||
check_for_exceptions(resp, body)
|
||||
common.check_for_exceptions(resp, body)
|
||||
if not body:
|
||||
raise Exception("Call to " + url + " did not return a body.")
|
||||
return base.Resource(self, body)
|
||||
|
@ -16,18 +16,16 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from troveclient import client
|
||||
from troveclient.v1.databases import Databases
|
||||
from troveclient.v1.flavors import Flavors
|
||||
from troveclient.v1.limits import Limits
|
||||
from troveclient.v1.users import Users
|
||||
from troveclient.v1.root import Root
|
||||
from troveclient.v1.backups import Backups
|
||||
from troveclient.v1.security_groups import SecurityGroups
|
||||
from troveclient.v1.security_groups import SecurityGroupRules
|
||||
from troveclient.v1.datastores import Datastores
|
||||
from troveclient.v1.datastores import DatastoreVersions
|
||||
from troveclient.v1.instances import Instances
|
||||
from troveclient import client as trove_client
|
||||
from troveclient.v1 import backups
|
||||
from troveclient.v1 import databases
|
||||
from troveclient.v1 import datastores
|
||||
from troveclient.v1 import flavors
|
||||
from troveclient.v1 import instances
|
||||
from troveclient.v1 import limits
|
||||
from troveclient.v1 import root
|
||||
from troveclient.v1 import security_groups
|
||||
from troveclient.v1 import users
|
||||
|
||||
|
||||
class Client(object):
|
||||
@ -56,17 +54,17 @@ class Client(object):
|
||||
# self.limits = limits.LimitsManager(self)
|
||||
|
||||
# extensions
|
||||
self.flavors = Flavors(self)
|
||||
self.users = Users(self)
|
||||
self.databases = Databases(self)
|
||||
self.backups = Backups(self)
|
||||
self.instances = Instances(self)
|
||||
self.limits = Limits(self)
|
||||
self.root = Root(self)
|
||||
self.security_group_rules = SecurityGroupRules(self)
|
||||
self.security_groups = SecurityGroups(self)
|
||||
self.datastores = Datastores(self)
|
||||
self.datastore_versions = DatastoreVersions(self)
|
||||
self.flavors = flavors.Flavors(self)
|
||||
self.users = users.Users(self)
|
||||
self.databases = databases.Databases(self)
|
||||
self.backups = backups.Backups(self)
|
||||
self.instances = instances.Instances(self)
|
||||
self.limits = limits.Limits(self)
|
||||
self.root = root.Root(self)
|
||||
self.security_group_rules = security_groups.SecurityGroupRules(self)
|
||||
self.security_groups = security_groups.SecurityGroups(self)
|
||||
self.datastores = datastores.Datastores(self)
|
||||
self.datastore_versions = datastores.DatastoreVersions(self)
|
||||
|
||||
#self.hosts = Hosts(self)
|
||||
#self.quota = Quotas(self)
|
||||
@ -84,7 +82,7 @@ class Client(object):
|
||||
setattr(self, extension.name,
|
||||
extension.manager_class(self))
|
||||
|
||||
self.client = client.HTTPClient(
|
||||
self.client = trove_client.client.HTTPClient(
|
||||
username,
|
||||
password,
|
||||
project_id,
|
||||
|
@ -17,9 +17,7 @@
|
||||
# under the License.
|
||||
|
||||
from troveclient import base
|
||||
from troveclient.common import check_for_exceptions
|
||||
from troveclient.common import limit_url
|
||||
from troveclient.common import Paginated
|
||||
from troveclient import common
|
||||
from troveclient.openstack.common.py3kcompat import urlutils
|
||||
|
||||
|
||||
@ -46,17 +44,17 @@ class Databases(base.ManagerWithFind):
|
||||
body = {"databases": databases}
|
||||
url = "/instances/%s/databases" % instance_id
|
||||
resp, body = self.api.client.post(url, body=body)
|
||||
check_for_exceptions(resp, body)
|
||||
common.check_for_exceptions(resp, body)
|
||||
|
||||
def delete(self, instance_id, dbname):
|
||||
"""Delete an existing database in the specified instance"""
|
||||
url = "/instances/%s/databases/%s" % (instance_id, dbname)
|
||||
resp, body = self.api.client.delete(url)
|
||||
check_for_exceptions(resp, body)
|
||||
common.check_for_exceptions(resp, body)
|
||||
|
||||
def _list(self, url, response_key, limit=None, marker=None):
|
||||
resp, body = self.api.client.get(limit_url(url, limit, marker))
|
||||
check_for_exceptions(resp, body)
|
||||
resp, body = self.api.client.get(common.limit_url(url, limit, marker))
|
||||
common.check_for_exceptions(resp, body)
|
||||
if not body:
|
||||
raise Exception("Call to " + url +
|
||||
" did not return a body.")
|
||||
@ -70,7 +68,9 @@ class Databases(base.ManagerWithFind):
|
||||
next_marker = query_dict.get('marker', None)
|
||||
databases = body[response_key]
|
||||
databases = [self.resource_class(self, res) for res in databases]
|
||||
return Paginated(databases, next_marker=next_marker, links=links)
|
||||
return common.Paginated(
|
||||
databases, next_marker=next_marker, links=links
|
||||
)
|
||||
|
||||
def list(self, instance, limit=None, marker=None):
|
||||
"""
|
||||
|
@ -17,8 +17,7 @@
|
||||
# under the License.
|
||||
|
||||
from troveclient import base
|
||||
|
||||
from troveclient.common import check_for_exceptions
|
||||
from troveclient import common
|
||||
|
||||
|
||||
class Host(base.Resource):
|
||||
@ -47,7 +46,7 @@ class Hosts(base.ManagerWithFind):
|
||||
"""
|
||||
url = "/mgmt/hosts/%s/instances/action" % host_id
|
||||
resp, body = self.api.client.post(url, body=body)
|
||||
check_for_exceptions(resp, body)
|
||||
common.check_for_exceptions(resp, body)
|
||||
|
||||
def update_all(self, host_id):
|
||||
"""
|
||||
|
@ -18,10 +18,7 @@
|
||||
# under the License.
|
||||
|
||||
from troveclient import base
|
||||
|
||||
from troveclient.common import check_for_exceptions
|
||||
from troveclient.common import limit_url
|
||||
from troveclient.common import Paginated
|
||||
from troveclient import common
|
||||
from troveclient.openstack.common.apiclient import exceptions
|
||||
from troveclient.openstack.common.py3kcompat import urlutils
|
||||
|
||||
@ -89,7 +86,7 @@ class Instances(base.ManagerWithFind):
|
||||
return self._create("/instances", body, "instance")
|
||||
|
||||
def _list(self, url, response_key, limit=None, marker=None):
|
||||
resp, body = self.api.client.get(limit_url(url, limit, marker))
|
||||
resp, body = self.api.client.get(common.limit_url(url, limit, marker))
|
||||
if not body:
|
||||
raise Exception("Call to " + url + " did not return a body.")
|
||||
links = body.get('links', [])
|
||||
@ -102,7 +99,9 @@ class Instances(base.ManagerWithFind):
|
||||
next_marker = query_dict.get('marker', None)
|
||||
instances = body[response_key]
|
||||
instances = [self.resource_class(self, res) for res in instances]
|
||||
return Paginated(instances, next_marker=next_marker, links=links)
|
||||
return common.Paginated(
|
||||
instances, next_marker=next_marker, links=links
|
||||
)
|
||||
|
||||
def list(self, limit=None, marker=None):
|
||||
"""
|
||||
@ -147,7 +146,7 @@ class Instances(base.ManagerWithFind):
|
||||
"""
|
||||
url = "/instances/%s/action" % instance_id
|
||||
resp, body = self.api.client.post(url, body=body)
|
||||
check_for_exceptions(resp, body)
|
||||
common.check_for_exceptions(resp, body)
|
||||
if body:
|
||||
return self.resource_class(self, body, loaded=True)
|
||||
return body
|
||||
|
@ -17,13 +17,10 @@
|
||||
# under the License.
|
||||
|
||||
from troveclient import base
|
||||
|
||||
from troveclient.common import check_for_exceptions
|
||||
from troveclient.common import limit_url
|
||||
from troveclient.common import Paginated
|
||||
from troveclient import common
|
||||
from troveclient.openstack.common.py3kcompat import urlutils
|
||||
from troveclient.v1.instances import Instance
|
||||
from troveclient.v1.flavors import Flavor
|
||||
from troveclient.v1 import instances
|
||||
from troveclient.v1 import flavors
|
||||
|
||||
|
||||
class RootHistory(base.Resource):
|
||||
@ -36,14 +33,14 @@ class Management(base.ManagerWithFind):
|
||||
"""
|
||||
Manage :class:`Instances` resources.
|
||||
"""
|
||||
resource_class = Instance
|
||||
resource_class = instances.Instance
|
||||
|
||||
# Appease the abc gods
|
||||
def list(self):
|
||||
pass
|
||||
|
||||
def _list(self, url, response_key, limit=None, marker=None):
|
||||
resp, body = self.api.client.get(limit_url(url, limit, marker))
|
||||
resp, body = self.api.client.get(common.limit_url(url, limit, marker))
|
||||
if not body:
|
||||
raise Exception("Call to " + url + " did not return a body.")
|
||||
links = body.get('links', [])
|
||||
@ -56,7 +53,9 @@ class Management(base.ManagerWithFind):
|
||||
next_marker = query_dict.get('marker', None)
|
||||
instances = body[response_key]
|
||||
instances = [self.resource_class(self, res) for res in instances]
|
||||
return Paginated(instances, next_marker=next_marker, links=links)
|
||||
return common.Paginated(
|
||||
instances, next_marker=next_marker, links=links
|
||||
)
|
||||
|
||||
def show(self, instance):
|
||||
"""
|
||||
@ -102,7 +101,7 @@ class Management(base.ManagerWithFind):
|
||||
"""
|
||||
url = "/mgmt/instances/%s/action" % instance_id
|
||||
resp, body = self.api.client.post(url, body=body)
|
||||
check_for_exceptions(resp, body)
|
||||
common.check_for_exceptions(resp, body)
|
||||
|
||||
def stop(self, instance_id):
|
||||
body = {'stop': {}}
|
||||
@ -148,7 +147,7 @@ class MgmtFlavors(base.ManagerWithFind):
|
||||
"""
|
||||
Manage :class:`Flavor` resources.
|
||||
"""
|
||||
resource_class = Flavor
|
||||
resource_class = flavors.Flavor
|
||||
|
||||
def __repr__(self):
|
||||
return "<Flavors Manager at %s>" % id(self)
|
||||
|
@ -18,7 +18,7 @@
|
||||
# under the License.
|
||||
|
||||
from troveclient import base
|
||||
from troveclient.common import check_for_exceptions
|
||||
from troveclient import common
|
||||
|
||||
|
||||
class Quotas(base.ManagerWithFind):
|
||||
@ -33,7 +33,7 @@ class Quotas(base.ManagerWithFind):
|
||||
|
||||
url = "/mgmt/quotas/%s" % tenant_id
|
||||
resp, body = self.api.client.get(url)
|
||||
check_for_exceptions(resp, body)
|
||||
common.check_for_exceptions(resp, body)
|
||||
if not body:
|
||||
raise Exception("Call to " + url + " did not return a body.")
|
||||
if 'quotas' not in body:
|
||||
@ -47,7 +47,7 @@ class Quotas(base.ManagerWithFind):
|
||||
url = "/mgmt/quotas/%s" % id
|
||||
body = {"quotas": quotas}
|
||||
resp, body = self.api.client.put(url, body=body)
|
||||
check_for_exceptions(resp, body)
|
||||
common.check_for_exceptions(resp, body)
|
||||
if not body:
|
||||
raise Exception("Call to " + url + " did not return a body.")
|
||||
if 'quotas' not in body:
|
||||
|
@ -17,9 +17,8 @@
|
||||
# under the License.
|
||||
|
||||
from troveclient import base
|
||||
|
||||
from troveclient.v1 import users
|
||||
from troveclient.common import check_for_exceptions
|
||||
from troveclient import common
|
||||
|
||||
|
||||
class Root(base.ManagerWithFind):
|
||||
@ -35,14 +34,14 @@ class Root(base.ManagerWithFind):
|
||||
sepcified db instance
|
||||
"""
|
||||
resp, body = self.api.client.post(self.url % instance_id)
|
||||
check_for_exceptions(resp, body)
|
||||
common.check_for_exceptions(resp, body)
|
||||
return body['user']['name'], body['user']['password']
|
||||
|
||||
def is_root_enabled(self, instance_id):
|
||||
""" Return True if root is enabled for the instance;
|
||||
False otherwise"""
|
||||
resp, body = self.api.client.get(self.url % instance_id)
|
||||
check_for_exceptions(resp, body)
|
||||
common.check_for_exceptions(resp, body)
|
||||
return self.resource_class(self, body, loaded=True)
|
||||
|
||||
# Appease the abc gods
|
||||
|
@ -18,9 +18,7 @@
|
||||
# under the License.
|
||||
|
||||
from troveclient import base
|
||||
|
||||
from troveclient.common import limit_url
|
||||
from troveclient.common import Paginated
|
||||
from troveclient import common
|
||||
from troveclient.openstack.common.apiclient import exceptions
|
||||
from troveclient.openstack.common.py3kcompat import urlutils
|
||||
|
||||
@ -40,7 +38,7 @@ class SecurityGroups(base.ManagerWithFind):
|
||||
resource_class = SecurityGroup
|
||||
|
||||
def _list(self, url, response_key, limit=None, marker=None):
|
||||
resp, body = self.api.client.get(limit_url(url, limit, marker))
|
||||
resp, body = self.api.client.get(common.limit_url(url, limit, marker))
|
||||
if not body:
|
||||
raise Exception("Call to " + url + " did not return a body.")
|
||||
links = body.get('links', [])
|
||||
@ -53,7 +51,9 @@ class SecurityGroups(base.ManagerWithFind):
|
||||
next_marker = query_dict.get('marker', None)
|
||||
instances = body[response_key]
|
||||
instances = [self.resource_class(self, res) for res in instances]
|
||||
return Paginated(instances, next_marker=next_marker, links=links)
|
||||
return common.Paginated(
|
||||
instances, next_marker=next_marker, links=links
|
||||
)
|
||||
|
||||
def list(self, limit=None, marker=None):
|
||||
"""
|
||||
|
@ -18,10 +18,7 @@
|
||||
|
||||
from troveclient import base
|
||||
from troveclient.v1 import databases
|
||||
from troveclient.common import check_for_exceptions
|
||||
from troveclient.common import limit_url
|
||||
from troveclient.common import Paginated
|
||||
from troveclient.common import quote_user_host
|
||||
from troveclient import common
|
||||
from troveclient.openstack.common.py3kcompat import urlutils
|
||||
|
||||
|
||||
@ -46,18 +43,18 @@ class Users(base.ManagerWithFind):
|
||||
body = {"users": users}
|
||||
url = "/instances/%s/users" % instance_id
|
||||
resp, body = self.api.client.post(url, body=body)
|
||||
check_for_exceptions(resp, body)
|
||||
common.check_for_exceptions(resp, body)
|
||||
|
||||
def delete(self, instance_id, username, hostname=None):
|
||||
"""Delete an existing user in the specified instance"""
|
||||
user = quote_user_host(username, hostname)
|
||||
user = common.quote_user_host(username, hostname)
|
||||
url = "/instances/%s/users/%s" % (instance_id, user)
|
||||
resp, body = self.api.client.delete(url)
|
||||
check_for_exceptions(resp, body)
|
||||
common.check_for_exceptions(resp, body)
|
||||
|
||||
def _list(self, url, response_key, limit=None, marker=None):
|
||||
resp, body = self.api.client.get(limit_url(url, limit, marker))
|
||||
check_for_exceptions(resp, body)
|
||||
resp, body = self.api.client.get(common.limit_url(url, limit, marker))
|
||||
common.check_for_exceptions(resp, body)
|
||||
if not body:
|
||||
raise Exception("Call to " + url +
|
||||
" did not return a body.")
|
||||
@ -70,7 +67,9 @@ class Users(base.ManagerWithFind):
|
||||
query_dict = dict(urlutils.parse_qsl(parsed_url.query))
|
||||
next_marker = query_dict.get('marker', None)
|
||||
users = [self.resource_class(self, res) for res in body[response_key]]
|
||||
return Paginated(users, next_marker=next_marker, links=links)
|
||||
return common.Paginated(
|
||||
users, next_marker=next_marker, links=links
|
||||
)
|
||||
|
||||
def list(self, instance, limit=None, marker=None):
|
||||
"""
|
||||
@ -87,7 +86,7 @@ class Users(base.ManagerWithFind):
|
||||
|
||||
:rtype: :class:`User`.
|
||||
"""
|
||||
user = quote_user_host(username, hostname)
|
||||
user = common.quote_user_host(username, hostname)
|
||||
url = "/instances/%s/users/%s" % (instance_id, user)
|
||||
return self._get(url, "user")
|
||||
|
||||
@ -99,7 +98,7 @@ class Users(base.ManagerWithFind):
|
||||
:rtype: :class:`User`.
|
||||
"""
|
||||
instance_id = base.getid(instance)
|
||||
user = quote_user_host(username, hostname)
|
||||
user = common.quote_user_host(username, hostname)
|
||||
user_dict = {}
|
||||
if not newuserattr:
|
||||
newuserattr = {}
|
||||
@ -107,16 +106,16 @@ class Users(base.ManagerWithFind):
|
||||
user_dict['user'] = newuserattr
|
||||
url = "/instances/%s/users/%s" % (instance_id, user)
|
||||
resp, body = self.api.client.put(url, body=user_dict)
|
||||
check_for_exceptions(resp, body)
|
||||
common.check_for_exceptions(resp, body)
|
||||
|
||||
def list_access(self, instance, username, hostname=None):
|
||||
"""Show all databases the given user has access to. """
|
||||
instance_id = base.getid(instance)
|
||||
user = quote_user_host(username, hostname)
|
||||
user = common.quote_user_host(username, hostname)
|
||||
url = "/instances/%(instance_id)s/users/%(user)s/databases"
|
||||
local_vars = locals()
|
||||
resp, body = self.api.client.get(url % local_vars)
|
||||
check_for_exceptions(resp, body)
|
||||
common.check_for_exceptions(resp, body)
|
||||
if not body:
|
||||
raise Exception("Call to %s did not return to a body" % url)
|
||||
return [databases.Database(self, db) for db in body['databases']]
|
||||
@ -124,22 +123,22 @@ class Users(base.ManagerWithFind):
|
||||
def grant(self, instance, username, databases, hostname=None):
|
||||
"""Allow an existing user permissions to access a database."""
|
||||
instance_id = base.getid(instance)
|
||||
user = quote_user_host(username, hostname)
|
||||
user = common.quote_user_host(username, hostname)
|
||||
url = "/instances/%(instance_id)s/users/%(user)s/databases"
|
||||
dbs = {'databases': [{'name': db} for db in databases]}
|
||||
local_vars = locals()
|
||||
resp, body = self.api.client.put(url % local_vars, body=dbs)
|
||||
check_for_exceptions(resp, body)
|
||||
common.check_for_exceptions(resp, body)
|
||||
|
||||
def revoke(self, instance, username, database, hostname=None):
|
||||
"""Revoke from an existing user access permissions to a database."""
|
||||
instance_id = base.getid(instance)
|
||||
user = quote_user_host(username, hostname)
|
||||
user = common.quote_user_host(username, hostname)
|
||||
url = ("/instances/%(instance_id)s/users/%(user)s/"
|
||||
"databases/%(database)s")
|
||||
local_vars = locals()
|
||||
resp, body = self.api.client.delete(url % local_vars)
|
||||
check_for_exceptions(resp, body)
|
||||
common.check_for_exceptions(resp, body)
|
||||
|
||||
def change_passwords(self, instance, users):
|
||||
"""Change the password for one or more users."""
|
||||
@ -147,4 +146,4 @@ class Users(base.ManagerWithFind):
|
||||
user_dict = {"users": users}
|
||||
url = "/instances/%s/users" % instance_id
|
||||
resp, body = self.api.client.put(url, body=user_dict)
|
||||
check_for_exceptions(resp, body)
|
||||
common.check_for_exceptions(resp, body)
|
||||
|
Loading…
x
Reference in New Issue
Block a user