Fix pep8 issues and update requirements

Change-Id: I4a08875468f60fdabeb5934f50deed4453474e7c
This commit is contained in:
lvdongbing 2016-08-04 22:01:41 -04:00
parent 06d6a356f6
commit 7a2c17cab7
14 changed files with 56 additions and 73 deletions

View File

@ -22,10 +22,7 @@ from __future__ import print_function
import argparse
import copy
import getpass
import hashlib
import json
import logging
import os
import sys
import traceback
@ -46,7 +43,7 @@ from keystoneclient import session
osprofiler_profiler = importutils.try_import("osprofiler.profiler")
SUPPORTED_VERSIONS = [1,]
SUPPORTED_VERSIONS = [1, ]
class BileanShell(object):
@ -160,7 +157,8 @@ class BileanShell(object):
parser.add_argument('--os-bilean-api-version',
default=utils.env('OS_BILEAN_API_VERSION',
default=None),
help='Defaults to env[OS_BILEAN_API_VERSION] or 2.')
help='Defaults to env[OS_BILEAN_API_VERSION] or '
'2.')
parser.add_argument('--os_bilean_api_version',
help=argparse.SUPPRESS)
@ -464,7 +462,8 @@ class BileanShell(object):
# build available subcommands based on version
try:
api_version = int(options.os_bilean_api_version or url_version or 1)
api_version = options.os_bilean_api_version or url_version or 1
api_version = int(api_version)
if api_version not in SUPPORTED_VERSIONS:
raise ValueError
except ValueError:
@ -546,8 +545,8 @@ class BileanShell(object):
self.get_subcommand_parser(1)
if command in self.subcommands:
command = ' ' + command
print(("\nRun `bilean --os-bilean-api-version 1 help%s`"
" for v1 help") % (command or ''))
print(("\nRun `bilean --os-bilean-api-version 1 "
"help%s` for v1 help") % (command or ''))
except ImportError:
pass

View File

@ -172,9 +172,8 @@ class TestClient(testtools.TestCase):
self.assertIn(self.endpoint, comm_err.message)
def test_connection_refused(self):
"""
"""Should receive a CommunicationError if connection refused.
Should receive a CommunicationError if connection refused.
And the error should list the host and port that refused the
connection
"""

View File

@ -15,11 +15,6 @@
# under the License.
import argparse
try:
from collections import OrderedDict
except ImportError:
from ordereddict import OrderedDict
import hashlib
import json
import logging
import os
@ -31,7 +26,6 @@ import fixtures
from keystoneclient import exceptions as ks_exc
from keystoneclient import fixture as ks_fixture
import mock
import requests
from requests_mock.contrib import fixture as rm_fixture
import six
@ -481,7 +475,8 @@ class ShellTestWithKeystoneV3Auth(ShellTest):
self.assertRaises(exc.CommandError, bilean_shell.main, args.split())
def test_bash_completion(self):
stdout, stderr = self.shell('--os-bilean-api-version 1 bash_completion')
stdout, stderr = self.shell('--os-bilean-api-version 1 '
'bash_completion')
# just check we have some output
required = [
'--value',

View File

@ -13,7 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import collections
import mock
from six import moves
import sys
import testtools
@ -38,20 +37,20 @@ class ShellTest(testtools.TestCase):
'status=ACTIVE'])
self.assertEqual({'name': 'bilean_user',
'status': 'ACTIVE'}, p)
def test_format_parameters_multiple_semicolon_values(self):
p = utils.format_parameters([
'status=ACTIVE',
'name=bilean;user'])
self.assertEqual({'name': 'bilean;user',
'status': 'ACTIVE'}, p)
def test_format_parameters_parse_semicolon_false(self):
p = utils.format_parameters(
['name=bilean;a=b'],
parse_semicolon=False)
self.assertEqual({'name': 'bilean;a=b'}, p)
def test_format_parameters_multiple_values_per_pamaters(self):
p = utils.format_parameters([
'status=ACTIVE',
@ -59,21 +58,21 @@ class ShellTest(testtools.TestCase):
self.assertIn('status', p)
self.assertIn('ACTIVE', p['status'])
self.assertIn('FREE', p['status'])
def test_format_parameter_bad_parameter(self):
params = ['name=bilean_user;statusACTIVE']
ex = self.assertRaises(exc.CommandError,
utils.format_parameters, params)
self.assertEqual('Malformed parameter(statusACTIVE). '
'Use the key=value format.', str(ex))
def test_format_multiple_bad_parameter(self):
params = ['name=bilean_user', 'statusACTIVE']
ex = self.assertRaises(exc.CommandError,
utils.format_parameters, params)
self.assertEqual('Malformed parameter(statusACTIVE). '
'Use the key=value format.', str(ex))
def test_link_formatter(self):
self.assertEqual('', utils.link_formatter(None))
self.assertEqual('', utils.link_formatter([]))

View File

@ -66,7 +66,7 @@ class FakeAPI(object):
class RawRequest(object):
def __init__(self, headers, body=None,
version=1.0, status=200, reason="Ok"):
"""
"""RawRequest
:param headers: dict representing HTTP response headers
:param body: file-like object
@ -93,7 +93,7 @@ class RawRequest(object):
class FakeResponse(object):
def __init__(self, headers=None, body=None,
version=1.0, status_code=200, reason="Ok"):
"""
"""FakeResponse
:param headers: dict representing HTTP response headers
:param body: file-like object

View File

@ -21,6 +21,7 @@ import testtools
FAKE_ID = 'FAKE_ID'
fake_resource = {'id': FAKE_ID}
class ResourceManagerTest(testtools.TestCase):
def setUp(self):
@ -29,22 +30,22 @@ class ResourceManagerTest(testtools.TestCase):
@mock.patch.object(ResourceManager, '_list')
def test_list_resource(self, mock_list):
mock_list.return_value = [fake_resource]
mock_list.return_value = ([fake_resource], None)
result = self.mgr.list()
self.assertEqual(fake_resource, result.next())
self.assertEqual(fake_resource, next(result))
# Make sure url is correct.
mock_list.assert_called_once_with('/resources?', 'resources')
@mock.patch.object(ResourceManager, '_list')
def test_list_resource_with_kwargs(self, mock_list):
mock_list.return_value = [fake_resource]
mock_list.return_value = ([fake_resource], None)
kwargs = {'limit': 2,
'marker': FAKE_ID,
'filters': {
'resource_type': 'os.nova.server',
'user_id': FAKE_ID}}
result = self.mgr.list(**kwargs)
self.assertEqual(fake_resource, result.next())
self.assertEqual(fake_resource, next(result))
# Make sure url is correct.
self.assertEqual(1, mock_list.call_count)
args = mock_list.call_args
@ -58,8 +59,3 @@ class ResourceManagerTest(testtools.TestCase):
'resource_type': ['os.nova.server'],
'user_id': [FAKE_ID]}
self.assertEqual(expected_query_dict, query_params)
@mock.patch.object(ResourceManager, '_get')
def test_get_resource(self, mock_get):
self.mgr.get(FAKE_ID)
mock_get.assert_called_once_with('/resources/%s' % FAKE_ID, 'resource')

View File

@ -17,9 +17,9 @@
from bileanclient.common import http
from bileanclient.v1 import policies
from bileanclient.v1 import resources
from bileanclient.v1 import rules
from bileanclient.v1 import users
from bileanclient.v1 import resources
class Client(object):

View File

@ -72,7 +72,7 @@ class PolicyManager(base.BaseManager):
def create(self, **kwargs):
"""Create a new policy."""
resq, body = self.client.post(url, data=kwargs)
resq, body = self.client.post('/policies', data=kwargs)
return self.resource_class(self, body.get('policy'), loaded=True)
def get(self, policy_id):

View File

@ -19,6 +19,8 @@ from six.moves.urllib import parse
from bileanclient.openstack.common.apiclient import base
OS_REQ_ID_HDR = 'x-openstack-request-id'
class Rule(base.Resource):
def __repr__(self):
@ -43,7 +45,7 @@ class RuleManager(base.BaseManager):
:rtype: list of :class:`Rule`.
"""
def paginate(params):
def paginate(params, return_request_id=None):
'''Paginate rules, even if more than API limit.'''
current_limit = int(params.get('limit') or 0)
url = '/rules?%s' % parse.urlencode(params, True)
@ -51,6 +53,9 @@ class RuleManager(base.BaseManager):
for rule in rules:
yield rule
if return_request_id is not None:
return_request_id.append(resp.headers.get(OS_REQ_ID_HDR, None))
num_rules = len(rules)
remaining_limit = current_limit - num_rules
if remaining_limit > 0 and num_rules > 0:
@ -69,7 +74,7 @@ class RuleManager(base.BaseManager):
if value:
params[key] = value
return paginate(params)
return paginate(params, return_request_id)
def create(self, **kwargs):
"""Create a rule by given data."""

View File

@ -1,16 +1,12 @@
# The order of packages is significant, because pip processes them in the order
# of appearance. Changing the order has an impact on the overall integration
# process, which may cause wedges in the gate later.
Babel!=2.3.0,!=2.3.1,!=2.3.2,!=2.3.3,>=1.3 # BSD
pbr>=1.6 # Apache-2.0
argparse
iso8601>=0.1.9 # MIT
PrettyTable<0.8,>=0.7 # BSD
oslo.i18n>=2.1.0 # Apache-2.0
oslo.serialization>=1.10.0 # Apache-2.0
oslo.utils>=3.5.0 # Apache-2.0
python-keystoneclient!=1.8.0,!=2.1.0,>=1.6.0 # Apache-2.0
PyYAML>=3.1.0 # MIT
requests!=2.9.0,>=2.8.1 # Apache-2.0
pbr!=2.1.0,>=2.0.0 # Apache-2.0
Babel!=2.4.0,>=2.3.4 # BSD
PrettyTable<0.8,>=0.7.1 # BSD
python-keystoneclient>=3.8.0 # Apache-2.0
requests>=2.14.2 # Apache-2.0
warlock!=1.3.0,<2,>=1.0.1 # Apache-2.0
six>=1.9.0 # MIT
oslo.utils>=3.20.0 # Apache-2.0
oslo.i18n!=3.15.2,>=2.1.0 # Apache-2.0

View File

@ -15,7 +15,7 @@ classifier =
Programming Language :: Python :: 2
Programming Language :: Python :: 2.7
Programming Language :: Python :: 3
Programming Language :: Python :: 3.3
Programming Language :: Python :: 3.5
[files]
packages = bileanclient

View File

@ -1,4 +1,3 @@
#!/usr/bin/env python
# Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License");
@ -26,5 +25,5 @@ except ImportError:
pass
setuptools.setup(
setup_requires=['pbr'],
setup_requires=['pbr>=2.0.0'],
pbr=True)

View File

@ -1,17 +1,17 @@
# The order of packages is significant, because pip processes them in the order
# of appearance. Changing the order has an impact on the overall integration
# process, which may cause wedges in the gate later.
coverage>=3.6 #Apache-2.0
discover # BSD
mock>=1.2 # BSD
mox3>=0.7.0 # Apache-2.0
coverage!=4.4,>=4.0 # Apache-2.0
hacking<0.12,>=0.11.0 # Apache-2.0
mock>=2.0 # BSD
ordereddict # MIT
fixtures<2.0,>=1.3.1 # Apache-2.0/BSD
requests-mock>=0.7.0 # Apache-2.0
sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2 # BSD
oslosphinx!=3.4.0,>=2.5.0 # Apache-2.0
sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2
os-client-config>=1.27.0 # Apache-2.0
oslosphinx>=4.7.0 # Apache-2.0
reno!=2.3.1,>=1.8.0 # Apache-2.0
sphinx!=1.6.1,>=1.5.1 # BSD
testrepository>=0.0.18 # Apache-2.0/BSD
testtools>=1.4.0 # MIT
testscenarios>=0.4 # Apache-2.0/BSD
testtools>=1.4.0 #MIT
fixtures>=3.0.0 # Apache-2.0/BSD
requests-mock>=1.1 # Apache-2.0
tempest>=14.0.0 # Apache-2.0

11
tox.ini
View File

@ -1,11 +1,11 @@
[tox]
minversion = 1.6
envlist = py34,py27,pypy,pep8
envlist = py35,py27,pep8
skipsdist = True
[testenv]
usedevelop = True
install_command = pip install -U {opts} {packages}
install_command = pip install -c{env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt} {opts} {packages}
setenv =
VIRTUAL_ENV={envdir}
deps =
@ -16,11 +16,6 @@ commands =
python setup.py testr --slowest --testr-args='{posargs}'
whitelist_externals = find
[testenv:pypy]
deps = setuptools<3.2
-r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
[testenv:pep8]
commands =
flake8
@ -38,9 +33,9 @@ commands=
python setup.py build_sphinx
[flake8]
ignore = F403,F812,F821
show-source = True
exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build
max-complexity = 20
[hacking]
import_exceptions = bileanclient.openstack.common._i18n