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

« back to all changes in this revision

Viewing changes to tests/v2/test_resources.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
 
# 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 ceilometerclient.v2.resources
17
 
from tests import utils
18
 
 
19
 
 
20
 
fixtures = {
21
 
    '/v2/resources': {
22
 
        'GET': (
23
 
            {},
24
 
            [
25
 
                {
26
 
                    'resource_id': 'a',
27
 
                    'project_id': 'project_bla',
28
 
                    'user_id': 'freddy',
29
 
                    'metadata': {'zxc_id': 'bla'},
30
 
                },
31
 
                {
32
 
                    'resource_id': 'b',
33
 
                    'project_id': 'dig_the_ditch',
34
 
                    'user_id': 'joey',
35
 
                    'metadata': {'zxc_id': 'foo'},
36
 
                },
37
 
            ]
38
 
        ),
39
 
    },
40
 
    '/v2/resources?q.op=&q.value=a&q.field=resource_id':
41
 
    {
42
 
        'GET': (
43
 
            {},
44
 
            [
45
 
                {
46
 
                    'resource_id': 'a',
47
 
                    'project_id': 'project_bla',
48
 
                    'user_id': 'freddy',
49
 
                    'metadata': {'zxc_id': 'bla'},
50
 
                },
51
 
            ]
52
 
        ),
53
 
    },
54
 
    '/v2/resources/a':
55
 
    {
56
 
        'GET': (
57
 
            {},
58
 
            {
59
 
                'resource_id': 'a',
60
 
                'project_id': 'project_bla',
61
 
                'user_id': 'freddy',
62
 
                'metadata': {'zxc_id': 'bla'},
63
 
            },
64
 
        ),
65
 
    },
66
 
}
67
 
 
68
 
 
69
 
class ResourceManagerTest(utils.BaseTestCase):
70
 
 
71
 
    def setUp(self):
72
 
        super(ResourceManagerTest, self).setUp()
73
 
        self.api = utils.FakeAPI(fixtures)
74
 
        self.mgr = ceilometerclient.v2.resources.ResourceManager(self.api)
75
 
 
76
 
    def test_list_all(self):
77
 
        resources = list(self.mgr.list())
78
 
        expect = [
79
 
            ('GET', '/v2/resources', {}, None),
80
 
        ]
81
 
        self.assertEqual(self.api.calls, expect)
82
 
        self.assertEqual(len(resources), 2)
83
 
        self.assertEqual(resources[0].resource_id, 'a')
84
 
        self.assertEqual(resources[1].resource_id, 'b')
85
 
 
86
 
    def test_list_one(self):
87
 
        resource = self.mgr.get(resource_id='a')
88
 
        expect = [
89
 
            ('GET', '/v2/resources/a', {}, None),
90
 
        ]
91
 
        self.assertEqual(self.api.calls, expect)
92
 
        self.assertTrue(resource)
93
 
        self.assertEqual(resource.resource_id, 'a')
94
 
 
95
 
    def test_list_by_query(self):
96
 
        resources = list(self.mgr.list(q=[{"field": "resource_id",
97
 
                                           "value": "a"},
98
 
                                          ]))
99
 
        expect = [
100
 
            ('GET', '/v2/resources?q.op=&q.value=a&q.field=resource_id',
101
 
             {}, None),
102
 
        ]
103
 
        self.assertEqual(self.api.calls, expect)
104
 
        self.assertEqual(len(resources), 1)
105
 
        self.assertEqual(resources[0].resource_id, 'a')