Merge "Fix PEP8 E126 and E202 errors"

This commit is contained in:
Jenkins 2014-06-27 21:41:34 +00:00 committed by Gerrit Code Review
commit ddf0c16a10
4 changed files with 359 additions and 319 deletions

View File

@ -19,76 +19,80 @@ from openstackclient.tests.identity.v3 import fakes as identity_fakes
class TestOAuth1(identity_fakes.TestOAuth1): class TestOAuth1(identity_fakes.TestOAuth1):
def setUp(self): def setUp(self):
super(TestOAuth1, self).setUp() super(TestOAuth1, self).setUp()
identity_client = self.app.client_manager.identity identity_client = self.app.client_manager.identity
self.consumers_mock = identity_client.oauth1.consumers self.consumers_mock = identity_client.oauth1.consumers
self.consumers_mock.reset_mock() self.consumers_mock.reset_mock()
class TestConsumerCreate(TestOAuth1): class TestConsumerCreate(TestOAuth1):
def setUp(self): def setUp(self):
super(TestConsumerCreate, self).setUp() super(TestConsumerCreate, self).setUp()
self.consumers_mock.create.return_value = fakes.FakeResource( self.consumers_mock.create.return_value = fakes.FakeResource(
None, copy.deepcopy(identity_fakes.OAUTH_CONSUMER), None,
loaded=True) copy.deepcopy(identity_fakes.OAUTH_CONSUMER),
loaded=True,
)
self.cmd = consumer.CreateConsumer(self.app, None) self.cmd = consumer.CreateConsumer(self.app, None)
def test_create_consumer(self): def test_create_consumer(self):
arglist = [ arglist = [
'--description', identity_fakes.consumer_description '--description', identity_fakes.consumer_description,
] ]
verifylist = [ verifylist = [
('description', identity_fakes.consumer_description) ('description', identity_fakes.consumer_description),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args) columns, data = self.cmd.take_action(parsed_args)
self.consumers_mock.create.assert_called_with( self.consumers_mock.create.assert_called_with(
identity_fakes.consumer_description) identity_fakes.consumer_description,
)
collist = ('description', 'id', 'secret') collist = ('description', 'id', 'secret')
self.assertEqual(columns, collist) self.assertEqual(columns, collist)
datalist = ( datalist = (
identity_fakes.consumer_description, identity_fakes.consumer_description,
identity_fakes.consumer_id, identity_fakes.consumer_id,
identity_fakes.consumer_secret identity_fakes.consumer_secret,
) )
self.assertEqual(data, datalist) self.assertEqual(data, datalist)
class TestConsumerDelete(TestOAuth1): class TestConsumerDelete(TestOAuth1):
def setUp(self): def setUp(self):
super(TestConsumerDelete, self).setUp() super(TestConsumerDelete, self).setUp()
# This is the return value for utils.find_resource() # This is the return value for utils.find_resource()
self.consumers_mock.get.return_value = fakes.FakeResource( self.consumers_mock.get.return_value = fakes.FakeResource(
None, None,
copy.deepcopy(identity_fakes.OAUTH_CONSUMER), copy.deepcopy(identity_fakes.OAUTH_CONSUMER),
loaded=True) loaded=True,
)
self.consumers_mock.delete.return_value = None self.consumers_mock.delete.return_value = None
self.cmd = consumer.DeleteConsumer(self.app, None) self.cmd = consumer.DeleteConsumer(self.app, None)
def test_delete_consumer(self): def test_delete_consumer(self):
arglist = [ arglist = [
identity_fakes.consumer_id identity_fakes.consumer_id,
] ]
verifylist = [ verifylist = [
('consumer', identity_fakes.consumer_id) ('consumer', identity_fakes.consumer_id),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args) result = self.cmd.run(parsed_args)
self.assertEqual(result, 0) self.assertEqual(result, 0)
self.consumers_mock.delete.assert_called_with( self.consumers_mock.delete.assert_called_with(
identity_fakes.consumer_id, identity_fakes.consumer_id,
) )
class TestConsumerList(TestOAuth1): class TestConsumerList(TestOAuth1):
@ -125,7 +129,7 @@ class TestConsumerList(TestOAuth1):
self.assertEqual(columns, collist) self.assertEqual(columns, collist)
datalist = (( datalist = ((
identity_fakes.consumer_id, identity_fakes.consumer_id,
identity_fakes.consumer_description identity_fakes.consumer_description,
), ) ), )
self.assertEqual(tuple(data), datalist) self.assertEqual(tuple(data), datalist)
@ -138,29 +142,33 @@ class TestConsumerShow(TestOAuth1):
consumer_no_secret = copy.deepcopy(identity_fakes.OAUTH_CONSUMER) consumer_no_secret = copy.deepcopy(identity_fakes.OAUTH_CONSUMER)
del consumer_no_secret['secret'] del consumer_no_secret['secret']
self.consumers_mock.get.return_value = fakes.FakeResource( self.consumers_mock.get.return_value = fakes.FakeResource(
None, consumer_no_secret, loaded=True) None,
consumer_no_secret,
loaded=True,
)
# Get the command object to test # Get the command object to test
self.cmd = consumer.ShowConsumer(self.app, None) self.cmd = consumer.ShowConsumer(self.app, None)
def test_consumer_show(self): def test_consumer_show(self):
arglist = [ arglist = [
identity_fakes.consumer_id identity_fakes.consumer_id,
] ]
verifylist = [ verifylist = [
('consumer', identity_fakes.consumer_id) ('consumer', identity_fakes.consumer_id),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args) columns, data = self.cmd.take_action(parsed_args)
self.consumers_mock.get.assert_called_with( self.consumers_mock.get.assert_called_with(
identity_fakes.consumer_id) identity_fakes.consumer_id,
)
collist = ('description', 'id' ) collist = ('description', 'id')
self.assertEqual(columns, collist) self.assertEqual(columns, collist)
datalist = ( datalist = (
identity_fakes.consumer_description, identity_fakes.consumer_description,
identity_fakes.consumer_id identity_fakes.consumer_id,
) )
self.assertEqual(data, datalist) self.assertEqual(data, datalist)
@ -171,12 +179,18 @@ class TestConsumerSet(TestOAuth1):
super(TestConsumerSet, self).setUp() super(TestConsumerSet, self).setUp()
self.consumers_mock.get.return_value = fakes.FakeResource( self.consumers_mock.get.return_value = fakes.FakeResource(
None, copy.deepcopy(identity_fakes.OAUTH_CONSUMER), loaded=True) None,
copy.deepcopy(identity_fakes.OAUTH_CONSUMER),
loaded=True,
)
consumer_updated = copy.deepcopy(identity_fakes.OAUTH_CONSUMER) consumer_updated = copy.deepcopy(identity_fakes.OAUTH_CONSUMER)
consumer_updated['description'] = "consumer new description" consumer_updated['description'] = "consumer new description"
self.consumers_mock.update.return_value = fakes.FakeResource( self.consumers_mock.update.return_value = fakes.FakeResource(
None, consumer_updated, loaded=True) None,
consumer_updated,
loaded=True,
)
self.cmd = consumer.SetConsumer(self.app, None) self.cmd = consumer.SetConsumer(self.app, None)
@ -185,11 +199,11 @@ class TestConsumerSet(TestOAuth1):
arglist = [ arglist = [
'--description', new_description, '--description', new_description,
identity_fakes.consumer_id identity_fakes.consumer_id,
] ]
verifylist = [ verifylist = [
('description', new_description), ('description', new_description),
('consumer', identity_fakes.consumer_id) ('consumer', identity_fakes.consumer_id),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.run(parsed_args) result = self.cmd.run(parsed_args)
@ -197,4 +211,6 @@ class TestConsumerSet(TestOAuth1):
kwargs = {'description': new_description} kwargs = {'description': new_description}
self.consumers_mock.update.assert_called_with( self.consumers_mock.update.assert_called_with(
identity_fakes.consumer_id, **kwargs) identity_fakes.consumer_id,
**kwargs
)

View File

@ -21,152 +21,165 @@ from openstackclient.tests.identity.v3 import fakes as identity_fakes
class TestIdentityProvider(identity_fakes.TestFederatedIdentity): class TestIdentityProvider(identity_fakes.TestFederatedIdentity):
def setUp(self): def setUp(self):
super(TestIdentityProvider, self).setUp() super(TestIdentityProvider, self).setUp()
self.identity_providers_mock = self.app.client_manager.\ self.identity_providers_mock = self.app.client_manager.\
identity.identity_providers identity.identity_providers
self.identity_providers_mock.reset_mock() self.identity_providers_mock.reset_mock()
class TestIdentityProviderCreate(TestIdentityProvider): class TestIdentityProviderCreate(TestIdentityProvider):
def setUp(self): def setUp(self):
super(TestIdentityProviderCreate, self).setUp() super(TestIdentityProviderCreate, self).setUp()
self.identity_providers_mock.create.return_value = \ self.identity_providers_mock.create.return_value = \
fakes.FakeResource( fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.IDENTITY_PROVIDER),
loaded=True
)
self.cmd = identity_provider.CreateIdentityProvider(
self.app, None)
def test_create_identity_provider_no_options(self):
arglist = [
identity_fakes.idp_id
]
verifylist = [
('identity_provider_id', identity_fakes.idp_id)
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
# Set expected values
kwargs = {
'enabled': True,
'description': None,
}
self.identity_providers_mock.create.assert_called_with(
identity_fakes.idp_id, **kwargs)
collist = ('description', 'enabled', 'id')
self.assertEqual(columns, collist)
datalist = (
identity_fakes.idp_description,
True,
identity_fakes.idp_id,
)
self.assertEqual(data, datalist)
def test_create_identity_provider_description(self):
arglist = ['--description', identity_fakes.idp_description,
identity_fakes.idp_id]
verifylist = [
('identity_provider_id', identity_fakes.idp_id),
('description', identity_fakes.idp_description)
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
# Set expected values
kwargs = {
'description': identity_fakes.idp_description,
'enabled': True,
}
self.identity_providers_mock.create.assert_called_with(
identity_fakes.idp_id, **kwargs)
collist = ('description', 'enabled', 'id')
self.assertEqual(columns, collist)
datalist = (
identity_fakes.idp_description, True, identity_fakes.idp_id,
)
self.assertEqual(data, datalist)
def test_create_identity_provider_disabled(self):
# Prepare FakeResource object
IDENTITY_PROVIDER = copy.deepcopy(identity_fakes.IDENTITY_PROVIDER)
IDENTITY_PROVIDER['enabled'] = False
IDENTITY_PROVIDER['description'] = None
self.identity_providers_mock.create.return_value = \
fakes.FakeResource(
None,
IDENTITY_PROVIDER,
loaded=True
)
arglist = ['--disable',
identity_fakes.idp_id]
verifylist = [
('identity_provider_id', identity_fakes.idp_id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
# Set expected values
kwargs = {
'enabled': False,
'description': None
}
self.identity_providers_mock.create.assert_called_with(
identity_fakes.idp_id, **kwargs)
collist = ('description', 'enabled', 'id')
self.assertEqual(columns, collist)
datalist = (
None, None,
False, copy.deepcopy(identity_fakes.IDENTITY_PROVIDER),
identity_fakes.idp_id, loaded=True,
) )
self.assertEqual(data, datalist)
self.cmd = identity_provider.CreateIdentityProvider(
self.app,
None,
)
def test_create_identity_provider_no_options(self):
arglist = [
identity_fakes.idp_id,
]
verifylist = [
('identity_provider_id', identity_fakes.idp_id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
# Set expected values
kwargs = {
'enabled': True,
'description': None,
}
self.identity_providers_mock.create.assert_called_with(
identity_fakes.idp_id,
**kwargs
)
collist = ('description', 'enabled', 'id')
self.assertEqual(columns, collist)
datalist = (
identity_fakes.idp_description,
True,
identity_fakes.idp_id,
)
self.assertEqual(data, datalist)
def test_create_identity_provider_description(self):
arglist = [
'--description', identity_fakes.idp_description,
identity_fakes.idp_id,
]
verifylist = [
('identity_provider_id', identity_fakes.idp_id),
('description', identity_fakes.idp_description),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
# Set expected values
kwargs = {
'description': identity_fakes.idp_description,
'enabled': True,
}
self.identity_providers_mock.create.assert_called_with(
identity_fakes.idp_id,
**kwargs
)
collist = ('description', 'enabled', 'id')
self.assertEqual(columns, collist)
datalist = (
identity_fakes.idp_description,
True,
identity_fakes.idp_id,
)
self.assertEqual(data, datalist)
def test_create_identity_provider_disabled(self):
# Prepare FakeResource object
IDENTITY_PROVIDER = copy.deepcopy(identity_fakes.IDENTITY_PROVIDER)
IDENTITY_PROVIDER['enabled'] = False
IDENTITY_PROVIDER['description'] = None
self.identity_providers_mock.create.return_value = \
fakes.FakeResource(
None,
IDENTITY_PROVIDER,
loaded=True,
)
arglist = [
'--disable',
identity_fakes.idp_id,
]
verifylist = [
('identity_provider_id', identity_fakes.idp_id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
# Set expected values
kwargs = {
'enabled': False,
'description': None,
}
self.identity_providers_mock.create.assert_called_with(
identity_fakes.idp_id,
**kwargs
)
collist = ('description', 'enabled', 'id')
self.assertEqual(columns, collist)
datalist = (
None,
False,
identity_fakes.idp_id,
)
self.assertEqual(data, datalist)
class TestIdentityProviderDelete(TestIdentityProvider): class TestIdentityProviderDelete(TestIdentityProvider):
def setUp(self): def setUp(self):
super(TestIdentityProviderDelete, self).setUp() super(TestIdentityProviderDelete, self).setUp()
# This is the return value for utils.find_resource() # This is the return value for utils.find_resource()
self.identity_providers_mock.get.return_value = fakes.FakeResource( self.identity_providers_mock.get.return_value = fakes.FakeResource(
None, None,
copy.deepcopy(identity_fakes.IDENTITY_PROVIDER), copy.deepcopy(identity_fakes.IDENTITY_PROVIDER),
loaded=True) loaded=True,
)
self.identity_providers_mock.delete.return_value = None self.identity_providers_mock.delete.return_value = None
self.cmd = identity_provider.DeleteIdentityProvider( self.cmd = identity_provider.DeleteIdentityProvider(self.app, None)
self.app, None)
def test_delete_identity_provider(self): def test_delete_identity_provider(self):
arglist = [ arglist = [
identity_fakes.idp_id identity_fakes.idp_id,
] ]
verifylist = [ verifylist = [
('identity_provider', identity_fakes.idp_id) ('identity_provider', identity_fakes.idp_id),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args) self.cmd.take_action(parsed_args)
self.identity_providers_mock.delete.assert_called_with( self.identity_providers_mock.delete.assert_called_with(
identity_fakes.idp_id, identity_fakes.idp_id,
) )
class TestIdentityProviderList(TestIdentityProvider): class TestIdentityProviderList(TestIdentityProvider):
@ -205,8 +218,7 @@ class TestIdentityProviderList(TestIdentityProvider):
datalist = (( datalist = ((
identity_fakes.idp_id, identity_fakes.idp_id,
True, True,
identity_fakes.idp_description identity_fakes.idp_description,
), ) ), )
self.assertEqual(tuple(data), datalist) self.assertEqual(tuple(data), datalist)
@ -219,7 +231,7 @@ class TestIdentityProviderShow(TestIdentityProvider):
self.identity_providers_mock.get.return_value = fakes.FakeResource( self.identity_providers_mock.get.return_value = fakes.FakeResource(
None, None,
copy.deepcopy(identity_fakes.IDENTITY_PROVIDER), copy.deepcopy(identity_fakes.IDENTITY_PROVIDER),
loaded=True loaded=True,
) )
# Get the command object to test # Get the command object to test
@ -227,24 +239,25 @@ class TestIdentityProviderShow(TestIdentityProvider):
def test_identity_provider_show(self): def test_identity_provider_show(self):
arglist = [ arglist = [
identity_fakes.idp_id identity_fakes.idp_id,
] ]
verifylist = [ verifylist = [
('identity_provider', identity_fakes.idp_id) ('identity_provider', identity_fakes.idp_id),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args) columns, data = self.cmd.take_action(parsed_args)
self.identity_providers_mock.get.assert_called_with( self.identity_providers_mock.get.assert_called_with(
identity_fakes.idp_id) identity_fakes.idp_id,
)
collist = ('description', 'enabled', 'id' ) collist = ('description', 'enabled', 'id')
self.assertEqual(columns, collist) self.assertEqual(columns, collist)
datalist = ( datalist = (
identity_fakes.idp_description, identity_fakes.idp_description,
True, True,
identity_fakes.idp_id identity_fakes.idp_id,
) )
self.assertEqual(data, datalist) self.assertEqual(data, datalist)
@ -259,7 +272,6 @@ class TestIdentityProviderSet(TestIdentityProvider):
"""Disable Identity Provider """Disable Identity Provider
Set Identity Provider's ``enabled`` attribute to False. Set Identity Provider's ``enabled`` attribute to False.
""" """
def prepare(self): def prepare(self):
"""Prepare fake return objects before the test is executed""" """Prepare fake return objects before the test is executed"""
@ -274,23 +286,27 @@ class TestIdentityProviderSet(TestIdentityProvider):
prepare(self) prepare(self)
arglist = [ arglist = [
'--disable', identity_fakes.idp_id '--disable', identity_fakes.idp_id,
] ]
verifylist = [ verifylist = [
('identity_provider', identity_fakes.idp_id), ('identity_provider', identity_fakes.idp_id),
('enable', False), ('enable', False),
('disable', True) ('disable', True),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args) columns, data = self.cmd.take_action(parsed_args)
self.identity_providers_mock.update.assert_called_with( self.identity_providers_mock.update.assert_called_with(
identity_fakes.idp_id, enabled=False) identity_fakes.idp_id,
collist = ('description', 'enabled', 'id' ) enabled=False,
)
collist = ('description', 'enabled', 'id')
self.assertEqual(columns, collist) self.assertEqual(columns, collist)
datalist = ( datalist = (
identity_fakes.idp_description, identity_fakes.idp_description,
False, False,
identity_fakes.idp_id identity_fakes.idp_id,
) )
self.assertEqual(datalist, data) self.assertEqual(datalist, data)
@ -298,7 +314,6 @@ class TestIdentityProviderSet(TestIdentityProvider):
"""Enable Identity Provider. """Enable Identity Provider.
Set Identity Provider's ``enabled`` attribute to True. Set Identity Provider's ``enabled`` attribute to True.
""" """
def prepare(self): def prepare(self):
"""Prepare fake return objects before the test is executed""" """Prepare fake return objects before the test is executed"""
@ -311,24 +326,24 @@ class TestIdentityProviderSet(TestIdentityProvider):
prepare(self) prepare(self)
arglist = [ arglist = [
'--enable', identity_fakes.idp_id '--enable', identity_fakes.idp_id,
] ]
verifylist = [ verifylist = [
('identity_provider', identity_fakes.idp_id), ('identity_provider', identity_fakes.idp_id),
('enable', True), ('enable', True),
('disable', False) ('disable', False),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args) columns, data = self.cmd.take_action(parsed_args)
self.identity_providers_mock.update.assert_called_with( self.identity_providers_mock.update.assert_called_with(
identity_fakes.idp_id, enabled=True) identity_fakes.idp_id, enabled=True)
collist = ('description', 'enabled', 'id' ) collist = ('description', 'enabled', 'id')
self.assertEqual(columns, collist) self.assertEqual(columns, collist)
datalist = ( datalist = (
identity_fakes.idp_description, identity_fakes.idp_description,
True, True,
identity_fakes.idp_id identity_fakes.idp_id,
) )
self.assertEqual(data, datalist) self.assertEqual(data, datalist)
@ -345,18 +360,18 @@ class TestIdentityProviderSet(TestIdentityProvider):
resources = fakes.FakeResource( resources = fakes.FakeResource(
None, None,
copy.deepcopy(identity_fakes.IDENTITY_PROVIDER), copy.deepcopy(identity_fakes.IDENTITY_PROVIDER),
loaded=True loaded=True,
) )
self.identity_providers_mock.update.return_value = resources self.identity_providers_mock.update.return_value = resources
prepare(self) prepare(self)
arglist = [ arglist = [
identity_fakes.idp_id identity_fakes.idp_id,
] ]
verifylist = [ verifylist = [
('identity_provider', identity_fakes.idp_id), ('identity_provider', identity_fakes.idp_id),
('enable', False), ('enable', False),
('disable', False) ('disable', False),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)

View File

@ -19,90 +19,96 @@ from openstackclient.tests.identity.v3 import fakes as identity_fakes
class TestOAuth1(identity_fakes.TestOAuth1): class TestOAuth1(identity_fakes.TestOAuth1):
def setUp(self): def setUp(self):
super(TestOAuth1, self).setUp() super(TestOAuth1, self).setUp()
identity_client = self.app.client_manager.identity identity_client = self.app.client_manager.identity
self.access_tokens_mock = identity_client.oauth1.access_tokens self.access_tokens_mock = identity_client.oauth1.access_tokens
self.access_tokens_mock.reset_mock() self.access_tokens_mock.reset_mock()
self.request_tokens_mock = identity_client.oauth1.request_tokens self.request_tokens_mock = identity_client.oauth1.request_tokens
self.request_tokens_mock.reset_mock() self.request_tokens_mock.reset_mock()
class TestRequestTokenCreate(TestOAuth1): class TestRequestTokenCreate(TestOAuth1):
def setUp(self): def setUp(self):
super(TestRequestTokenCreate, self).setUp() super(TestRequestTokenCreate, self).setUp()
self.request_tokens_mock.create.return_value = fakes.FakeResource( self.request_tokens_mock.create.return_value = fakes.FakeResource(
None, copy.deepcopy(identity_fakes.OAUTH_REQUEST_TOKEN), None,
loaded=True) copy.deepcopy(identity_fakes.OAUTH_REQUEST_TOKEN),
loaded=True,
)
self.cmd = token.CreateRequestToken(self.app, None) self.cmd = token.CreateRequestToken(self.app, None)
def test_create_request_tokens(self): def test_create_request_tokens(self):
arglist = [ arglist = [
'--consumer-key', identity_fakes.consumer_id, '--consumer-key', identity_fakes.consumer_id,
'--consumer-secret', identity_fakes.consumer_secret, '--consumer-secret', identity_fakes.consumer_secret,
'--project-id', identity_fakes.project_id '--project-id', identity_fakes.project_id,
] ]
verifylist = [ verifylist = [
('consumer_key', identity_fakes.consumer_id), ('consumer_key', identity_fakes.consumer_id),
('consumer_secret', identity_fakes.consumer_secret), ('consumer_secret', identity_fakes.consumer_secret),
('project_id', identity_fakes.project_id) ('project_id', identity_fakes.project_id),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args) columns, data = self.cmd.take_action(parsed_args)
self.request_tokens_mock.create.assert_called_with( self.request_tokens_mock.create.assert_called_with(
identity_fakes.consumer_id, identity_fakes.consumer_id,
identity_fakes.consumer_secret, identity_fakes.consumer_secret,
identity_fakes.project_id) identity_fakes.project_id,
)
collist = ('expires', 'id', 'key', 'secret') collist = ('expires', 'id', 'key', 'secret')
self.assertEqual(columns, collist) self.assertEqual(columns, collist)
datalist = ( datalist = (
identity_fakes.request_token_expires, identity_fakes.request_token_expires,
identity_fakes.request_token_id, identity_fakes.request_token_id,
identity_fakes.request_token_id, identity_fakes.request_token_id,
identity_fakes.request_token_secret identity_fakes.request_token_secret,
) )
self.assertEqual(data, datalist) self.assertEqual(data, datalist)
class TestRequestTokenAuthorize(TestOAuth1): class TestRequestTokenAuthorize(TestOAuth1):
def setUp(self): def setUp(self):
super(TestRequestTokenAuthorize, self).setUp() super(TestRequestTokenAuthorize, self).setUp()
self.request_tokens_mock.authorize.return_value = \ self.request_tokens_mock.authorize.return_value = \
fakes.FakeResource( fakes.FakeResource(
None, copy.deepcopy(identity_fakes.OAUTH_VERIFIER), None,
loaded=True) copy.deepcopy(identity_fakes.OAUTH_VERIFIER),
loaded=True,
self.cmd = token.AuthorizeRequestToken(self.app, None)
def test_authorize_request_tokens(self):
arglist = [
'--request-key', identity_fakes.request_token_id,
'--role-ids', identity_fakes.role_id
]
verifylist = [
('request_key', identity_fakes.request_token_id),
('role_ids', identity_fakes.role_id)
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
self.request_tokens_mock.authorize.assert_called_with(
identity_fakes.request_token_id,
[identity_fakes.role_id])
collist = ('oauth_verifier',)
self.assertEqual(columns, collist)
datalist = (
identity_fakes.oauth_verifier_pin,
) )
self.assertEqual(data, datalist)
self.cmd = token.AuthorizeRequestToken(self.app, None)
def test_authorize_request_tokens(self):
arglist = [
'--request-key', identity_fakes.request_token_id,
'--role-ids', identity_fakes.role_id,
]
verifylist = [
('request_key', identity_fakes.request_token_id),
('role_ids', identity_fakes.role_id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
self.request_tokens_mock.authorize.assert_called_with(
identity_fakes.request_token_id,
[identity_fakes.role_id],
)
collist = ('oauth_verifier',)
self.assertEqual(columns, collist)
datalist = (
identity_fakes.oauth_verifier_pin,
)
self.assertEqual(data, datalist)
class TestAccessTokenCreate(TestOAuth1): class TestAccessTokenCreate(TestOAuth1):
@ -111,42 +117,45 @@ class TestAccessTokenCreate(TestOAuth1):
super(TestAccessTokenCreate, self).setUp() super(TestAccessTokenCreate, self).setUp()
self.access_tokens_mock.create.return_value = fakes.FakeResource( self.access_tokens_mock.create.return_value = fakes.FakeResource(
None, copy.deepcopy(identity_fakes.OAUTH_ACCESS_TOKEN), None,
loaded=True) copy.deepcopy(identity_fakes.OAUTH_ACCESS_TOKEN),
loaded=True,
)
self.cmd = token.CreateAccessToken(self.app, None) self.cmd = token.CreateAccessToken(self.app, None)
def test_create_access_tokens(self): def test_create_access_tokens(self):
arglist = [ arglist = [
'--consumer-key', identity_fakes.consumer_id, '--consumer-key', identity_fakes.consumer_id,
'--consumer-secret', identity_fakes.consumer_secret, '--consumer-secret', identity_fakes.consumer_secret,
'--request-key', identity_fakes.request_token_id, '--request-key', identity_fakes.request_token_id,
'--request-secret', identity_fakes.request_token_secret, '--request-secret', identity_fakes.request_token_secret,
'--verifier', identity_fakes.oauth_verifier_pin '--verifier', identity_fakes.oauth_verifier_pin,
] ]
verifylist = [ verifylist = [
('consumer_key', identity_fakes.consumer_id), ('consumer_key', identity_fakes.consumer_id),
('consumer_secret', identity_fakes.consumer_secret), ('consumer_secret', identity_fakes.consumer_secret),
('request_key', identity_fakes.request_token_id), ('request_key', identity_fakes.request_token_id),
('request_secret', identity_fakes.request_token_secret), ('request_secret', identity_fakes.request_token_secret),
('verifier', identity_fakes.oauth_verifier_pin) ('verifier', identity_fakes.oauth_verifier_pin),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args) columns, data = self.cmd.take_action(parsed_args)
self.access_tokens_mock.create.assert_called_with( self.access_tokens_mock.create.assert_called_with(
identity_fakes.consumer_id, identity_fakes.consumer_id,
identity_fakes.consumer_secret, identity_fakes.consumer_secret,
identity_fakes.request_token_id, identity_fakes.request_token_id,
identity_fakes.request_token_secret, identity_fakes.request_token_secret,
identity_fakes.oauth_verifier_pin) identity_fakes.oauth_verifier_pin,
)
collist = ('expires', 'id', 'key', 'secret') collist = ('expires', 'id', 'key', 'secret')
self.assertEqual(columns, collist) self.assertEqual(columns, collist)
datalist = ( datalist = (
identity_fakes.access_token_expires, identity_fakes.access_token_expires,
identity_fakes.access_token_id, identity_fakes.access_token_id,
identity_fakes.access_token_id, identity_fakes.access_token_id,
identity_fakes.access_token_secret identity_fakes.access_token_secret,
) )
self.assertEqual(data, datalist) self.assertEqual(data, datalist)

View File

@ -28,6 +28,6 @@ commands=
python setup.py build_sphinx python setup.py build_sphinx
[flake8] [flake8]
ignore = E126,E202,W602,H302,H402,H305,H307,H904 ignore = H302,H305,H307,H402,H904
show-source = True show-source = True
exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,tools exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,tools