~ubuntu-branches/ubuntu/wily/python-ceilometerclient/wily

« back to all changes in this revision

Viewing changes to tests/v2/test_statistics.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2013-03-01 12:47:39 UTC
  • Revision ID: package-import@ubuntu.com-20130301124739-0in66psacnqpksch
Tags: upstream-0.1~dde86a3
ImportĀ upstreamĀ versionĀ 0.1~dde86a3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2012 OpenStack LLC.
 
2
# All Rights Reserved.
 
3
#
 
4
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
5
#    not use this file except in compliance with the License. You may obtain
 
6
#    a copy of the License at
 
7
#
 
8
#         http://www.apache.org/licenses/LICENSE-2.0
 
9
#
 
10
#    Unless required by applicable law or agreed to in writing, software
 
11
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
12
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
13
#    License for the specific language governing permissions and limitations
 
14
#    under the License.
 
15
 
 
16
import unittest
 
17
 
 
18
import ceilometerclient.v2.statistics
 
19
from tests import utils
 
20
 
 
21
 
 
22
fixtures = {
 
23
    '/v2/meters/instance/statistics':
 
24
    {
 
25
        'GET': (
 
26
            {},
 
27
            [{
 
28
                u'count': 135,
 
29
                u'duration_start': u'2013-02-04T10:51:42',
 
30
                u'min': 1.0,
 
31
                u'max': 1.0,
 
32
                u'duration_end':
 
33
                u'2013-02-05T15:46:09',
 
34
                u'duration': 1734.0,
 
35
                u'avg': 1.0,
 
36
                u'sum': 135.0,
 
37
            }]
 
38
        ),
 
39
    },
 
40
    '/v2/meters/instance/statistics?q.op=&q.op=&q.value=foo&q.value=bar&q.field=resource_id&q.field=source':
 
41
    {
 
42
        'GET': (
 
43
            {},
 
44
            [{
 
45
                u'count': 135,
 
46
                u'duration_start': u'2013-02-04T10:51:42',
 
47
                u'min': 1.0,
 
48
                u'max': 1.0,
 
49
                u'duration_end':
 
50
                u'2013-02-05T15:46:09',
 
51
                u'duration': 1734.0,
 
52
                u'avg': 1.0,
 
53
                u'sum': 135.0,
 
54
            }]
 
55
        ),
 
56
    }
 
57
}
 
58
 
 
59
 
 
60
class StatisticsManagerTest(unittest.TestCase):
 
61
 
 
62
    def setUp(self):
 
63
        self.api = utils.FakeAPI(fixtures)
 
64
        self.mgr = ceilometerclient.v2.statistics.StatisticsManager(self.api)
 
65
 
 
66
    def test_list_by_meter_name(self):
 
67
        stats = list(self.mgr.list(meter_name='instance'))
 
68
        expect = [
 
69
            ('GET', '/v2/meters/instance/statistics', {}, None),
 
70
        ]
 
71
        self.assertEqual(self.api.calls, expect)
 
72
        self.assertEqual(len(stats), 1)
 
73
        self.assertEqual(stats[0].count, 135)
 
74
 
 
75
    def test_list_by_meter_name_extended(self):
 
76
        stats = list(self.mgr.list(meter_name='instance',
 
77
                                   q=[
 
78
                                       {"field": "resource_id",
 
79
                                        "value": "foo"},
 
80
                                       {"field": "source",
 
81
                                        "value": "bar"},
 
82
                                   ]))
 
83
        expect = [
 
84
            ('GET',
 
85
             '/v2/meters/instance/statistics?q.op=&q.op=&q.value=foo&q.value=bar&q.field=resource_id&q.field=source',
 
86
             {}, None),
 
87
        ]
 
88
        self.assertEqual(self.api.calls, expect)
 
89
        self.assertEqual(len(stats), 1)
 
90
        self.assertEqual(stats[0].count, 135)