2
# Licensed under the Apache License, Version 2.0 (the "License"); you may
3
# not use this file except in compliance with the License. You may obtain
4
# a copy of the License at
6
# http://www.apache.org/licenses/LICENSE-2.0
8
# Unless required by applicable law or agreed to in writing, software
9
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11
# License for the specific language governing permissions and limitations
14
from ceilometerclient.v2 import options
15
from tests import utils
18
class BuildUrlTest(utils.BaseTestCase):
21
url = options.build_url('/', [{'field': 'this',
24
self.assertEqual(url, '/?q.op=gt&q.value=43&q.field=this')
27
url = options.build_url('/', [{'field': 'this',
33
ops = 'q.op=gt&q.op=lt'
34
vals = 'q.value=43&q.value=88'
35
fields = 'q.field=this&q.field=that'
36
self.assertEqual(url, '/?%s&%s&%s' % (ops, vals, fields))
38
def test_default_op(self):
39
url = options.build_url('/', [{'field': 'this',
41
self.assertEqual(url, '/?q.op=&q.value=43&q.field=this')
44
class CliTest(utils.BaseTestCase):
47
ar = options.cli_to_array('this<=34')
48
self.assertEqual(ar, [{'field': 'this', 'op': 'le', 'value': '34'}])
51
ar = options.cli_to_array('this<=34;that!=foo')
52
self.assertEqual(ar, [{'field': 'this', 'op': 'le', 'value': '34'},
53
{'field': 'that', 'op': 'ne', 'value': 'foo'}])
55
def test_negative(self):
56
ar = options.cli_to_array('this>=-783')
57
self.assertEqual(ar, [{'field': 'this', 'op': 'ge', 'value': '-783'}])
60
ar = options.cli_to_array('this<=283.347')
61
self.assertEqual(ar, [{'field': 'this',
62
'op': 'le', 'value': '283.347'}])
64
def test_invalid_seperator(self):
65
self.assertRaises(ValueError, options.cli_to_array,
68
def test_invalid_operator(self):
69
self.assertRaises(ValueError, options.cli_to_array,
72
def test_with_dot(self):
73
ar = options.cli_to_array('metadata.this<=34')
74
self.assertEqual(ar, [{'field': 'metadata.this',
75
'op': 'le', 'value': '34'}])