~ubuntu-branches/ubuntu/trusty/python-ceilometerclient/trusty

« back to all changes in this revision

Viewing changes to tests/v2/test_options.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2013-08-13 11:27:54 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20130813112754-fz58btmvrw9gsrhn
Tags: 1.0.3-0ubuntu1
* New upstream release. 
* debian/patches/fix-keystoneclient-version.patch: Dropped no longer needed. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#
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
5
 
#
6
 
#         http://www.apache.org/licenses/LICENSE-2.0
7
 
#
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
12
 
#    under the License.
13
 
 
14
 
from ceilometerclient.v2 import options
15
 
from tests import utils
16
 
 
17
 
 
18
 
class BuildUrlTest(utils.BaseTestCase):
19
 
 
20
 
    def test_one(self):
21
 
        url = options.build_url('/', [{'field': 'this',
22
 
                                       'op': 'gt',
23
 
                                       'value': 43}])
24
 
        self.assertEqual(url, '/?q.op=gt&q.value=43&q.field=this')
25
 
 
26
 
    def test_two(self):
27
 
        url = options.build_url('/', [{'field': 'this',
28
 
                                       'op': 'gt',
29
 
                                       'value': 43},
30
 
                                      {'field': 'that',
31
 
                                       'op': 'lt',
32
 
                                       'value': 88}])
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))
37
 
 
38
 
    def test_default_op(self):
39
 
        url = options.build_url('/', [{'field': 'this',
40
 
                                       'value': 43}])
41
 
        self.assertEqual(url, '/?q.op=&q.value=43&q.field=this')
42
 
 
43
 
 
44
 
class CliTest(utils.BaseTestCase):
45
 
 
46
 
    def test_one(self):
47
 
        ar = options.cli_to_array('this<=34')
48
 
        self.assertEqual(ar, [{'field': 'this', 'op': 'le', 'value': '34'}])
49
 
 
50
 
    def test_two(self):
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'}])
54
 
 
55
 
    def test_negative(self):
56
 
        ar = options.cli_to_array('this>=-783')
57
 
        self.assertEqual(ar, [{'field': 'this', 'op': 'ge', 'value': '-783'}])
58
 
 
59
 
    def test_float(self):
60
 
        ar = options.cli_to_array('this<=283.347')
61
 
        self.assertEqual(ar, [{'field': 'this',
62
 
                               'op': 'le', 'value': '283.347'}])
63
 
 
64
 
    def test_invalid_seperator(self):
65
 
        self.assertRaises(ValueError, options.cli_to_array,
66
 
                          'this=2.4,fooo=doof')
67
 
 
68
 
    def test_invalid_operator(self):
69
 
        self.assertRaises(ValueError, options.cli_to_array,
70
 
                          'this=2.4;fooo-doof')
71
 
 
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'}])