Fixing potential NameErrors
Fixing a couple locations that could potentially raise NameErrors instead of intended exceptions. These were found by looking at flake8 F821 (undefined name) errors. Added in unit tests to verify NameErrors would not be raised. Change-Id: I8619cb0be495b814335a5aea23daca025484d3c6
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"
|
||||
" specific." % (manager.resource_class.__name__.lower(),
|
||||
name_or_id))
|
||||
raise exc.CommandError(msg)
|
||||
raise exceptions.CommandError(msg)
|
||||
|
||||
|
||||
def unauthenticated(f):
|
||||
|
@@ -17,6 +17,7 @@
|
||||
import logging
|
||||
|
||||
from keystoneclient import base
|
||||
from keystoneclient import exceptions
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
@@ -38,6 +38,9 @@ class FakeManager(object):
|
||||
raise exceptions.NotFound(resource_id)
|
||||
|
||||
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():
|
||||
if resource['name'] == str(name):
|
||||
return resource
|
||||
@@ -76,3 +79,9 @@ class FindResourceTestCase(test_utils.TestCase):
|
||||
def test_find_by_int_name(self):
|
||||
output = utils.find_resource(self.manager, 9876)
|
||||
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
|
||||
|
||||
from keystoneclient import exceptions
|
||||
from keystoneclient.v3 import users
|
||||
from tests.v3 import utils
|
||||
|
||||
@@ -63,6 +64,10 @@ class UserTests(utils.TestCase, utils.CrudTests):
|
||||
self.mox.ReplayAll()
|
||||
|
||||
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):
|
||||
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.assertRaises(exceptions.ValidationError,
|
||||
self.manager.check_in_group,
|
||||
user=ref['id'],
|
||||
group=None)
|
||||
|
||||
def test_remove_user_from_group(self):
|
||||
group_id = uuid.uuid4().hex
|
||||
ref = self.new_ref()
|
||||
@@ -131,6 +141,10 @@ class UserTests(utils.TestCase, utils.CrudTests):
|
||||
self.mox.ReplayAll()
|
||||
|
||||
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):
|
||||
# Can create a user with the deprecated project option rather than
|
||||
|
Reference in New Issue
Block a user