Merge "Don't glob match name_or_id"

This commit is contained in:
Jenkins 2017-03-09 21:44:04 +00:00 committed by Gerrit Code Review
commit 986540665c
2 changed files with 8 additions and 20 deletions

View File

@ -13,7 +13,6 @@
# limitations under the License.
import contextlib
import fnmatch
import inspect
import jmespath
import munch
@ -84,8 +83,7 @@ def _filter_list(data, name_or_id, filters):
each dictionary contains an 'id' and 'name'
key if a value for name_or_id is given.
:param string name_or_id:
The name or ID of the entity being filtered. Can be a glob pattern,
such as 'nb01*'.
The name or ID of the entity being filtered.
:param filters:
A dictionary of meta data to use for further filtering. Elements
of this dictionary may, themselves, be dictionaries. Example::
@ -104,9 +102,8 @@ def _filter_list(data, name_or_id, filters):
for e in data:
e_id = e.get('id', None)
e_name = e.get('name', None)
if ((e_id and fnmatch.fnmatch(str(e_id), str(name_or_id))) or
(e_name and fnmatch.fnmatch(
str(e_name), str(name_or_id)))):
if ((e_id and str(e_id) == str(name_or_id)) or
(e_name and str(e_name) == str(name_or_id))):
identifier_matches.append(e)
data = identifier_matches

View File

@ -40,21 +40,12 @@ class TestUtils(base.TestCase):
ret = _utils._filter_list(data, 'donald', None)
self.assertEqual([el1], ret)
def test__filter_list_name_or_id_glob(self):
def test__filter_list_name_or_id_special(self):
el1 = dict(id=100, name='donald')
el2 = dict(id=200, name='pluto')
el3 = dict(id=200, name='pluto-2')
data = [el1, el2, el3]
ret = _utils._filter_list(data, 'pluto*', None)
self.assertEqual([el2, el3], ret)
def test__filter_list_name_or_id_glob_not_found(self):
el1 = dict(id=100, name='donald')
el2 = dict(id=200, name='pluto')
el3 = dict(id=200, name='pluto-2')
data = [el1, el2, el3]
ret = _utils._filter_list(data, 'q*', None)
self.assertEqual([], ret)
el2 = dict(id=200, name='pluto[2017-01-10]')
data = [el1, el2]
ret = _utils._filter_list(data, 'pluto[2017-01-10]', None)
self.assertEqual([el2], ret)
def test__filter_list_filter(self):
el1 = dict(id=100, name='donald', other='duck')