Merge "Fixing potential NameErrors"
This commit is contained in:
@@ -108,7 +108,7 @@ def find_resource(manager, name_or_id):
|
|||||||
msg = ("Multiple %s matches found for '%s', use an ID to be more"
|
msg = ("Multiple %s matches found for '%s', use an ID to be more"
|
||||||
" specific." % (manager.resource_class.__name__.lower(),
|
" specific." % (manager.resource_class.__name__.lower(),
|
||||||
name_or_id))
|
name_or_id))
|
||||||
raise exc.CommandError(msg)
|
raise exceptions.CommandError(msg)
|
||||||
|
|
||||||
|
|
||||||
def unauthenticated(f):
|
def unauthenticated(f):
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from keystoneclient import base
|
from keystoneclient import base
|
||||||
|
from keystoneclient import exceptions
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
@@ -38,6 +38,9 @@ class FakeManager(object):
|
|||||||
raise exceptions.NotFound(resource_id)
|
raise exceptions.NotFound(resource_id)
|
||||||
|
|
||||||
def find(self, name=None):
|
def find(self, name=None):
|
||||||
|
if name == '9999':
|
||||||
|
# NOTE(morganfainberg): special case that raises NoUniqueMatch.
|
||||||
|
raise exceptions.NoUniqueMatch()
|
||||||
for resource_id, resource in self.resources.items():
|
for resource_id, resource in self.resources.items():
|
||||||
if resource['name'] == str(name):
|
if resource['name'] == str(name):
|
||||||
return resource
|
return resource
|
||||||
@@ -76,3 +79,9 @@ class FindResourceTestCase(test_utils.TestCase):
|
|||||||
def test_find_by_int_name(self):
|
def test_find_by_int_name(self):
|
||||||
output = utils.find_resource(self.manager, 9876)
|
output = utils.find_resource(self.manager, 9876)
|
||||||
self.assertEqual(output, self.manager.resources['5678'])
|
self.assertEqual(output, self.manager.resources['5678'])
|
||||||
|
|
||||||
|
def test_find_no_unique_match(self):
|
||||||
|
self.assertRaises(exceptions.CommandError,
|
||||||
|
utils.find_resource,
|
||||||
|
self.manager,
|
||||||
|
9999)
|
||||||
|
@@ -20,6 +20,7 @@ import uuid
|
|||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
from keystoneclient import exceptions
|
||||||
from keystoneclient.v3 import users
|
from keystoneclient.v3 import users
|
||||||
from tests.v3 import utils
|
from tests.v3 import utils
|
||||||
|
|
||||||
@@ -63,6 +64,10 @@ class UserTests(utils.TestCase, utils.CrudTests):
|
|||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
|
|
||||||
self.manager.add_to_group(user=ref['id'], group=group_id)
|
self.manager.add_to_group(user=ref['id'], group=group_id)
|
||||||
|
self.assertRaises(exceptions.ValidationError,
|
||||||
|
self.manager.remove_from_group,
|
||||||
|
user=ref['id'],
|
||||||
|
group=None)
|
||||||
|
|
||||||
def test_list_users_in_group(self):
|
def test_list_users_in_group(self):
|
||||||
group_id = uuid.uuid4().hex
|
group_id = uuid.uuid4().hex
|
||||||
@@ -110,6 +115,11 @@ class UserTests(utils.TestCase, utils.CrudTests):
|
|||||||
|
|
||||||
self.manager.check_in_group(user=ref['id'], group=group_id)
|
self.manager.check_in_group(user=ref['id'], group=group_id)
|
||||||
|
|
||||||
|
self.assertRaises(exceptions.ValidationError,
|
||||||
|
self.manager.check_in_group,
|
||||||
|
user=ref['id'],
|
||||||
|
group=None)
|
||||||
|
|
||||||
def test_remove_user_from_group(self):
|
def test_remove_user_from_group(self):
|
||||||
group_id = uuid.uuid4().hex
|
group_id = uuid.uuid4().hex
|
||||||
ref = self.new_ref()
|
ref = self.new_ref()
|
||||||
@@ -131,6 +141,10 @@ class UserTests(utils.TestCase, utils.CrudTests):
|
|||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
|
|
||||||
self.manager.remove_from_group(user=ref['id'], group=group_id)
|
self.manager.remove_from_group(user=ref['id'], group=group_id)
|
||||||
|
self.assertRaises(exceptions.ValidationError,
|
||||||
|
self.manager.remove_from_group,
|
||||||
|
user=ref['id'],
|
||||||
|
group=None)
|
||||||
|
|
||||||
def test_create_with_project(self):
|
def test_create_with_project(self):
|
||||||
# Can create a user with the deprecated project option rather than
|
# Can create a user with the deprecated project option rather than
|
||||||
|
Reference in New Issue
Block a user