diff options
| author | Denis Makogon <dmakogon@mirantis.com> | 2013-12-10 18:49:20 +0200 |
|---|---|---|
| committer | Denis Makogon <dmakogon@mirantis.com> | 2013-12-10 18:49:20 +0200 |
| commit | 69c865695f388141bcbf645e57771bcb3fcdb491 (patch) | |
| tree | 50cb616ebc6fefda52a6efd96141dcacc4ea2110 /troveclient/compat | |
| parent | 7499015e510fbd8f900581fabafdc586b097ab3c (diff) | |
| download | python-troveclient-69c865695f388141bcbf645e57771bcb3fcdb491.tar.gz | |
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
Diffstat (limited to 'troveclient/compat')
| -rw-r--r-- | troveclient/compat/auth.py | 4 | ||||
| -rw-r--r-- | troveclient/compat/cli.py | 14 | ||||
| -rw-r--r-- | troveclient/compat/client.py | 83 | ||||
| -rw-r--r-- | troveclient/compat/common.py | 16 | ||||
| -rw-r--r-- | troveclient/compat/mcli.py | 4 | ||||
| -rw-r--r-- | troveclient/compat/tests/test_auth.py | 118 | ||||
| -rw-r--r-- | troveclient/compat/tests/test_common.py | 100 | ||||
| -rw-r--r-- | troveclient/compat/tests/test_xml.py | 20 | ||||
| -rw-r--r-- | troveclient/compat/xml.py | 23 |
9 files changed, 214 insertions, 168 deletions
diff --git a/troveclient/compat/auth.py b/troveclient/compat/auth.py index ed9ddd9..f7e0ea9 100644 --- a/troveclient/compat/auth.py +++ b/troveclient/compat/auth.py @@ -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": diff --git a/troveclient/compat/cli.py b/troveclient/compat/cli.py index 85489c1..fcb1c6a 100644 --- a/troveclient/compat/cli.py +++ b/troveclient/compat/cli.py @@ -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: diff --git a/troveclient/compat/client.py b/troveclient/compat/client.py index f0f0ac4..2b4b7c4 100644 --- a/troveclient/compat/client.py +++ b/troveclient/compat/client.py @@ -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): diff --git a/troveclient/compat/common.py b/troveclient/compat/common.py index 92922a6..a50914e 100644 --- a/troveclient/compat/common.py +++ b/troveclient/compat/common.py @@ -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]) diff --git a/troveclient/compat/mcli.py b/troveclient/compat/mcli.py index baa096c..7a597ed 100644 --- a/troveclient/compat/mcli.py +++ b/troveclient/compat/mcli.py @@ -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: diff --git a/troveclient/compat/tests/test_auth.py b/troveclient/compat/tests/test_auth.py index cb3b6bc..582e000 100644 --- a/troveclient/compat/tests/test_auth.py +++ b/troveclient/compat/tests/test_auth.py @@ -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") diff --git a/troveclient/compat/tests/test_common.py b/troveclient/compat/tests/test_common.py index 1a12258..8f0f6d0 100644 --- a/troveclient/compat/tests/test_common.py +++ b/troveclient/compat/tests/test_common.py @@ -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) diff --git a/troveclient/compat/tests/test_xml.py b/troveclient/compat/tests/test_xml.py index dfae68a..73c798c 100644 --- a/troveclient/compat/tests/test_xml.py +++ b/troveclient/compat/tests/test_xml.py @@ -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> diff --git a/troveclient/compat/xml.py b/troveclient/compat/xml.py index e01c23c..546d8fb 100644 --- a/troveclient/compat/xml.py +++ b/troveclient/compat/xml.py @@ -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): |
