utils: allow UUID to not have any dash

Change-Id: I33b4f40e6695019f7f4aaa2ad9f38c71d60783d5
Closes-Bug: #1524360
This commit is contained in:
Julien Danjou
2015-12-17 15:40:22 +01:00
parent 5f892efe41
commit da9a2a68c3
3 changed files with 16 additions and 2 deletions

View File

@@ -101,6 +101,16 @@ class ResourceClientTest(base.ClientTestBase):
self.assertEqual(self.PROJECT_ID, resource_list["project_id"])
self.assertEqual(resource["started_at"], resource_list["started_at"])
# Search with uuid without dashes
result = self.gnocchi('resource',
params=("search --type generic "
"--query 'project_id=%s'"
) % self.PROJECT_ID.replace("-", ""))
resource_list = self.parser.listing(result)[0]
self.assertEqual(self.RESOURCE_ID, resource_list["id"])
self.assertEqual(self.PROJECT_ID, resource_list["project_id"])
self.assertEqual(resource["started_at"], resource_list["started_at"])
# UPDATE with Delete metric
result = self.gnocchi(
'resource', params=("update -t generic %s -a project_id:%s "

View File

@@ -23,6 +23,10 @@ class SearchQueryBuilderTest(base.BaseTestCase):
self.assertEqual(expected, req)
def test_search_query_builder(self):
self._do_test('foo=7EED6CC3-EDC8-48C9-8EF6-8A36B9ACC91C',
{"=": {"foo": "7EED6CC3-EDC8-48C9-8EF6-8A36B9ACC91C"}})
self._do_test('foo=7EED6CC3EDC848C98EF68A36B9ACC91C',
{"=": {"foo": "7EED6CC3EDC848C98EF68A36B9ACC91C"}})
self._do_test('foo=bar', {"=": {"foo": "bar"}})
self._do_test('foo!=1', {"!=": {"foo": 1.0}})
self._do_test('foo=True', {"=": {"foo": True}})

View File

@@ -26,8 +26,8 @@ null = pp.Regex("None|none|null").setParseAction(pp.replaceWith(None))
boolean = "False|True|false|true"
boolean = pp.Regex(boolean).setParseAction(lambda t: t[0].lower() == "true")
hex_string = lambda n: pp.Word(pp.hexnums, exact=n)
uuid = pp.Combine(hex_string(8) + ("-" + hex_string(4)) * 3 +
"-" + hex_string(12))
uuid = pp.Combine(hex_string(8) + (pp.Optional("-") + hex_string(4)) * 3 +
pp.Optional("-") + hex_string(12))
number = r"[+-]?\d+(:?\.\d*)?(:?[eE][+-]?\d+)?"
number = pp.Regex(number).setParseAction(lambda t: float(t[0]))
identifier = pp.Word(pp.alphas, pp.alphanums + "_")