summaryrefslogtreecommitdiff
path: root/ceilometerclient/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'ceilometerclient/tests/unit')
-rw-r--r--ceilometerclient/tests/unit/test_client.py14
-rw-r--r--ceilometerclient/tests/unit/v1/__init__.py0
-rw-r--r--ceilometerclient/tests/unit/v1/test_meters.py162
-rw-r--r--ceilometerclient/tests/unit/v1/test_projects.py65
-rw-r--r--ceilometerclient/tests/unit/v1/test_resources.py161
-rw-r--r--ceilometerclient/tests/unit/v1/test_samples.py196
-rw-r--r--ceilometerclient/tests/unit/v1/test_users.py65
7 files changed, 0 insertions, 663 deletions
diff --git a/ceilometerclient/tests/unit/test_client.py b/ceilometerclient/tests/unit/test_client.py
index 5498853..3021699 100644
--- a/ceilometerclient/tests/unit/test_client.py
+++ b/ceilometerclient/tests/unit/test_client.py
@@ -23,7 +23,6 @@ from ceilometerclient import exc
from ceilometerclient.openstack.common.apiclient import exceptions
from ceilometerclient.tests.unit import fakes
from ceilometerclient.tests.unit import utils
-from ceilometerclient.v1 import client as v1client
from ceilometerclient.v2 import client as v2client
FAKE_ENV = {
@@ -64,20 +63,7 @@ class ClientTest(utils.BaseTestCase):
self.assertTrue(session.request.called)
self.assertTrue(resp.json.called)
- def test_client_v1_with_session(self):
- resp = mock.Mock(status_code=200, text=b'')
- resp.json.return_value = {'resources': []}
- session = mock.Mock()
- session.request.return_value = resp
- c = client.get_client(1, session=session)
- c.resources.list()
- self.assertTrue(session.request.called)
- self.assertTrue(resp.json.called)
-
def test_client_version(self):
- c1 = self.create_client(env=FAKE_ENV, api_version=1)
- self.assertIsInstance(c1, v1client.Client)
-
c2 = self.create_client(env=FAKE_ENV, api_version=2)
self.assertIsInstance(c2, v2client.Client)
diff --git a/ceilometerclient/tests/unit/v1/__init__.py b/ceilometerclient/tests/unit/v1/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/ceilometerclient/tests/unit/v1/__init__.py
+++ /dev/null
diff --git a/ceilometerclient/tests/unit/v1/test_meters.py b/ceilometerclient/tests/unit/v1/test_meters.py
deleted file mode 100644
index afd9a1b..0000000
--- a/ceilometerclient/tests/unit/v1/test_meters.py
+++ /dev/null
@@ -1,162 +0,0 @@
-# Copyright 2012 OpenStack Foundation
-# All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-from ceilometerclient.openstack.common.apiclient import client
-from ceilometerclient.openstack.common.apiclient import fake_client
-from ceilometerclient.tests.unit import utils
-import ceilometerclient.v1.meters
-
-
-fixtures = {
- '/v1/meters': {
- 'GET': (
- {},
- {'meters': [
- {
- 'resource_id': 'a',
- 'project_id': 'dig_the_ditch',
- 'user_id': 'freddy',
- 'name': 'this',
- 'type': 'counter',
- },
- {
- 'resource_id': 'b',
- 'project_id': 'dig_the_ditch',
- 'user_id': 'joey',
- 'name': 'this',
- 'type': 'counter',
- },
- ]},
- ),
- },
- '/v1/users/joey/meters': {
- 'GET': (
- {},
- {'meters': [
- {
- 'resource_id': 'b',
- 'project_id': 'dig_the_ditch',
- 'user_id': 'joey',
- 'name': 'this',
- 'type': 'counter',
- },
- ]},
- ),
- },
- '/v1/projects/dig_the_ditch/meters': {
- 'GET': (
- {},
- {'meters': [
- {
- 'resource_id': 'b',
- 'project_id': 'dig_the_ditch',
- 'user_id': 'joey',
- 'name': 'this',
- 'type': 'counter',
- },
- ]},
- ),
- },
- '/v1/sources/openstack/meters': {
- 'GET': (
- {},
- {'meters': [
- {
- 'resource_id': 'b',
- 'project_id': 'dig_the_ditch',
- 'user_id': 'joey',
- 'name': 'this',
- 'type': 'counter',
- },
- {
- 'resource_id': 'q',
- 'project_id': 'dig_the_trench',
- 'user_id': 'joey',
- 'name': 'this',
- 'type': 'counter',
- },
- ]},
- ),
- },
- '/v1/meters?metadata.zxc_id=foo': {
- 'GET': (
- {},
- {'meters': [
- {
- 'resource_id': 'b',
- 'project_id': 'dig_the_ditch',
- 'user_id': 'joey',
- 'name': 'this',
- 'type': 'counter',
- },
- ]},
- ),
- },
-}
-
-
-class MeterManagerTest(utils.BaseTestCase):
-
- def setUp(self):
- super(MeterManagerTest, self).setUp()
- self.http_client = fake_client.FakeHTTPClient(fixtures=fixtures)
- self.api = client.BaseClient(self.http_client)
- self.mgr = ceilometerclient.v1.meters.MeterManager(self.api)
-
- def test_list_all(self):
- resources = list(self.mgr.list())
- expect = [
- 'GET', '/v1/meters'
- ]
- self.http_client.assert_called(*expect)
- self.assertEqual(len(resources), 2)
- self.assertEqual(resources[0].resource_id, 'a')
- self.assertEqual(resources[1].resource_id, 'b')
-
- def test_list_by_source(self):
- resources = list(self.mgr.list(source='openstack'))
- expect = [
- 'GET', '/v1/sources/openstack/meters'
- ]
- self.http_client.assert_called(*expect)
- self.assertEqual(len(resources), 2)
- self.assertEqual(resources[0].resource_id, 'b')
- self.assertEqual(resources[1].resource_id, 'q')
-
- def test_list_by_user(self):
- resources = list(self.mgr.list(user_id='joey'))
- expect = [
- 'GET', '/v1/users/joey/meters'
- ]
- self.http_client.assert_called(*expect)
- self.assertEqual(len(resources), 1)
- self.assertEqual(resources[0].resource_id, 'b')
-
- def test_list_by_project(self):
- resources = list(self.mgr.list(project_id='dig_the_ditch'))
- expect = [
- 'GET', '/v1/projects/dig_the_ditch/meters'
- ]
- self.http_client.assert_called(*expect)
- self.assertEqual(len(resources), 1)
- self.assertEqual(resources[0].resource_id, 'b')
-
- def test_list_by_metaquery(self):
- resources = list(self.mgr.list(metaquery='metadata.zxc_id=foo'))
- expect = [
- 'GET', '/v1/meters?metadata.zxc_id=foo'
- ]
- self.http_client.assert_called(*expect)
- self.assertEqual(len(resources), 1)
- self.assertEqual(resources[0].resource_id, 'b')
diff --git a/ceilometerclient/tests/unit/v1/test_projects.py b/ceilometerclient/tests/unit/v1/test_projects.py
deleted file mode 100644
index 7b31bce..0000000
--- a/ceilometerclient/tests/unit/v1/test_projects.py
+++ /dev/null
@@ -1,65 +0,0 @@
-# Copyright 2012 OpenStack Foundation
-# All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-from ceilometerclient.openstack.common.apiclient import client
-from ceilometerclient.openstack.common.apiclient import fake_client
-from ceilometerclient.tests.unit import utils
-import ceilometerclient.v1.meters
-
-
-fixtures = {
- '/v1/projects': {
- 'GET': (
- {},
- {'projects': [
- 'a',
- 'b',
- ]},
- ),
- },
- '/v1/sources/source_b/projects': {
- 'GET': (
- {},
- {'projects': ['b']},
- ),
- },
-}
-
-
-class ProjectManagerTest(utils.BaseTestCase):
-
- def setUp(self):
- super(ProjectManagerTest, self).setUp()
- self.http_client = fake_client.FakeHTTPClient(fixtures=fixtures)
- self.api = client.BaseClient(self.http_client)
- self.mgr = ceilometerclient.v1.meters.ProjectManager(self.api)
-
- def test_list_all(self):
- projects = list(self.mgr.list())
- expect = [
- 'GET', '/v1/projects'
- ]
- self.http_client.assert_called(*expect)
- self.assertEqual(len(projects), 2)
- self.assertEqual(projects[0].project_id, 'a')
- self.assertEqual(projects[1].project_id, 'b')
-
- def test_list_by_source(self):
- projects = list(self.mgr.list(source='source_b'))
- expect = [
- 'GET', '/v1/sources/source_b/projects'
- ]
- self.http_client.assert_called(*expect)
- self.assertEqual(len(projects), 1)
- self.assertEqual(projects[0].project_id, 'b')
diff --git a/ceilometerclient/tests/unit/v1/test_resources.py b/ceilometerclient/tests/unit/v1/test_resources.py
deleted file mode 100644
index cfc4f6c..0000000
--- a/ceilometerclient/tests/unit/v1/test_resources.py
+++ /dev/null
@@ -1,161 +0,0 @@
-# Copyright 2012 OpenStack Foundation
-# All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-from ceilometerclient.openstack.common.apiclient import client
-from ceilometerclient.openstack.common.apiclient import fake_client
-from ceilometerclient.tests.unit import utils
-import ceilometerclient.v1.meters
-
-
-fixtures = {
- '/v1/resources': {
- 'GET': (
- {},
- {'resources': [
- {
- 'resource_id': 'a',
- 'project_id': 'project_bla',
- 'user_id': 'freddy',
- 'timestamp': 'now',
- 'meter': ['this', 'that'],
- 'metadata': {'zxc_id': 'bla'},
- },
- {
- 'resource_id': 'b',
- 'project_id': 'dig_the_ditch',
- 'user_id': 'joey',
- 'timestamp': 'now',
- 'meter': ['this', 'that'],
- 'metadata': {'zxc_id': 'foo'},
- },
- ]},
- ),
- },
- '/v1/users/joey/resources': {
- 'GET': (
- {},
- {'resources': [
- {
- 'resource_id': 'b',
- 'project_id': 'dig_the_ditch',
- 'user_id': 'joey',
- 'timestamp': 'now',
- 'meter': ['this', 'that'],
- 'metadata': {'zxc_id': 'foo'},
- },
- ]},
- ),
- },
- '/v1/resources?metadata.zxc_id=foo': {
- 'GET': (
- {},
- {'resources': [
- {
- 'resource_id': 'b',
- 'project_id': 'dig_the_ditch',
- 'user_id': 'joey',
- 'timestamp': 'now',
- 'meter': ['this', 'that'],
- 'metadata': {'zxc_id': 'foo'},
- },
- ]},
- ),
- },
- '/v1/projects/project_bla/resources': {
- 'GET': (
- {},
- {'resources': [
- {
- 'resource_id': 'a',
- 'project_id': 'project_bla',
- 'user_id': 'freddy',
- 'timestamp': 'now',
- 'meter': ['this', 'that'],
- 'metadata': {'zxc_id': 'bla'},
- },
- ]},
- ),
- },
- '/v1/resources?start_timestamp=now&end_timestamp=now': {
- 'GET': (
- {},
- {'resources': [
- {
- 'resource_id': 'b',
- 'project_id': 'dig_the_ditch',
- 'user_id': 'joey',
- 'timestamp': 'now',
- 'meter': ['this', 'that'],
- 'metadata': {'zxc_id': 'foo'},
- },
- ]},
- ),
- },
-}
-
-
-class ResourceManagerTest(utils.BaseTestCase):
-
- def setUp(self):
- super(ResourceManagerTest, self).setUp()
- self.http_client = fake_client.FakeHTTPClient(fixtures=fixtures)
- self.api = client.BaseClient(self.http_client)
- self.mgr = ceilometerclient.v1.meters.ResourceManager(self.api)
-
- def test_list_all(self):
- resources = list(self.mgr.list())
- expect = [
- 'GET', '/v1/resources'
- ]
- self.http_client.assert_called(*expect)
- self.assertEqual(len(resources), 2)
- self.assertEqual(resources[0].resource_id, 'a')
- self.assertEqual(resources[1].resource_id, 'b')
-
- def test_list_by_user(self):
- resources = list(self.mgr.list(user_id='joey'))
- expect = [
- 'GET', '/v1/users/joey/resources'
- ]
- self.http_client.assert_called(*expect)
- self.assertEqual(len(resources), 1)
- self.assertEqual(resources[0].resource_id, 'b')
-
- def test_list_by_metaquery(self):
- resources = list(self.mgr.list(metaquery='metadata.zxc_id=foo'))
- expect = [
- 'GET', '/v1/resources?metadata.zxc_id=foo'
- ]
- self.http_client.assert_called(*expect)
- self.assertEqual(len(resources), 1)
- self.assertEqual(resources[0].resource_id, 'b')
-
- def test_list_by_project(self):
- resources = list(self.mgr.list(project_id='project_bla'))
- expect = [
- 'GET', '/v1/projects/project_bla/resources'
- ]
- self.http_client.assert_called(*expect)
- self.assertEqual(len(resources), 1)
- self.assertEqual(resources[0].resource_id, 'a')
-
- def test_list_by_timestamp(self):
- resources = list(self.mgr.list(start_timestamp='now',
- end_timestamp='now'))
- expect = [
- 'GET', '/v1/resources?start_timestamp=now&end_timestamp=now'
- ]
- self.http_client.assert_called(*expect)
- self.assertEqual(len(resources), 1)
- self.assertEqual(resources[0].resource_id, 'b')
diff --git a/ceilometerclient/tests/unit/v1/test_samples.py b/ceilometerclient/tests/unit/v1/test_samples.py
deleted file mode 100644
index 0f1a029..0000000
--- a/ceilometerclient/tests/unit/v1/test_samples.py
+++ /dev/null
@@ -1,196 +0,0 @@
-# Copyright 2012 OpenStack Foundation
-# All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-from ceilometerclient.openstack.common.apiclient import client
-from ceilometerclient.openstack.common.apiclient import fake_client
-from ceilometerclient.tests.unit import utils
-import ceilometerclient.v1.meters
-
-
-fixtures = {
- '/v1/users/freddy/meters/balls': {
- 'GET': (
- {},
- {'events': [
- {
- 'resource_id': 'inst-0045',
- 'project_id': 'melbourne_open',
- 'user_id': 'freddy',
- 'name': 'tennis',
- 'type': 'counter',
- 'unit': 'balls',
- 'volume': 3,
- 'timestamp': None,
- 'resource_metadata': None,
- },
- ]},
- ),
- },
- '/v1/sources/openstack/meters/this': {
- 'GET': (
- {},
- {'events': [
- {
- 'resource_id': 'b',
- 'project_id': 'dig_the_ditch',
- 'user_id': 'joey',
- 'name': 'this',
- 'type': 'counter',
- 'unit': 'b',
- 'volume': 45,
- 'timestamp': None,
- 'resource_metadata': None,
- },
- ]},
- ),
- },
- '/v1/projects/dig_the_ditch/meters/meters': {
- 'GET': (
- {},
- {'events': [
- {
- 'resource_id': 'b',
- 'project_id': 'dig_the_ditch',
- 'user_id': 'joey',
- 'name': 'meters',
- 'type': 'counter',
- 'unit': 'meters',
- 'volume': 345,
- 'timestamp': None,
- 'resource_metadata': None,
- },
- ]},
- ),
- },
- '/v1/meters?metadata.zxc_id=foo': {
- 'GET': (
- {},
- {'events': [
- {
- 'resource_id': 'b',
- 'project_id': 'dig_the_ditch',
- 'user_id': 'joey',
- 'name': 'this',
- 'type': 'counter',
- 'unit': 'meters',
- 'volume': 98,
- 'timestamp': None,
- 'resource_metadata': {'zxc_id': 'foo'},
- },
- ]},
- ),
- },
- '/v1/users/freddy/meters/balls?start_timestamp=now&end_timestamp=now': {
- 'GET': (
- {},
- {'events': [
- {
- 'resource_id': 'inst-0045',
- 'project_id': 'melbourne_open',
- 'user_id': 'freddy',
- 'name': 'tennis',
- 'type': 'counter',
- 'unit': 'balls',
- 'volume': 3,
- 'timestamp': 'now',
- 'resource_metadata': None,
- },
-
- ]},
- ),
- },
- '/v1/meters': {
- 'GET': (
- {},
- {'meters': []},
- ),
- },
-}
-
-
-class SampleManagerTest(utils.BaseTestCase):
-
- def setUp(self):
- super(SampleManagerTest, self).setUp()
- self.http_client = fake_client.FakeHTTPClient(fixtures=fixtures)
- self.api = client.BaseClient(self.http_client)
- self.mgr = ceilometerclient.v1.meters.SampleManager(self.api)
-
- def test_list_all(self):
- samples = list(self.mgr.list(counter_name=None))
- expect = [
- 'GET', '/v1/meters'
- ]
- self.http_client.assert_called(*expect)
- self.assertEqual(len(samples), 0)
-
- def test_list_by_source(self):
- samples = list(self.mgr.list(source='openstack',
- counter_name='this'))
- expect = [
- 'GET', '/v1/sources/openstack/meters/this'
- ]
- self.http_client.assert_called(*expect)
- self.assertEqual(len(samples), 1)
- self.assertEqual(samples[0].resource_id, 'b')
-
- def test_list_by_user(self):
- samples = list(self.mgr.list(user_id='freddy',
- counter_name='balls'))
- expect = [
- 'GET', '/v1/users/freddy/meters/balls'
- ]
- self.http_client.assert_called(*expect)
- self.assertEqual(len(samples), 1)
- self.assertEqual(samples[0].project_id, 'melbourne_open')
- self.assertEqual(samples[0].user_id, 'freddy')
- self.assertEqual(samples[0].volume, 3)
-
- def test_list_by_project(self):
- samples = list(self.mgr.list(project_id='dig_the_ditch',
- counter_name='meters'))
- expect = [
- 'GET', '/v1/projects/dig_the_ditch/meters/meters'
- ]
- self.http_client.assert_called(*expect)
- self.assertEqual(len(samples), 1)
- self.assertEqual(samples[0].project_id, 'dig_the_ditch')
- self.assertEqual(samples[0].volume, 345)
- self.assertEqual(samples[0].unit, 'meters')
-
- def test_list_by_metaquery(self):
- samples = list(self.mgr.list(metaquery='metadata.zxc_id=foo',
- counter_name='this'))
- expect = [
- 'GET', '/v1/meters?metadata.zxc_id=foo'
- ]
- self.http_client.assert_called(*expect)
- self.assertEqual(len(samples), 1)
- self.assertEqual(samples[0].resource_metadata['zxc_id'], 'foo')
-
- def test_list_by_timestamp(self):
- samples = list(self.mgr.list(user_id='freddy',
- counter_name='balls',
- start_timestamp='now',
- end_timestamp='now'))
- expect = [
- 'GET',
- '/v1/users/freddy/meters/balls?' +
- 'start_timestamp=now&end_timestamp=now'
- ]
- self.http_client.assert_called(*expect)
- self.assertEqual(len(samples), 1)
- self.assertEqual(samples[0].project_id, 'melbourne_open')
- self.assertEqual(samples[0].user_id, 'freddy')
- self.assertEqual(samples[0].volume, 3)
diff --git a/ceilometerclient/tests/unit/v1/test_users.py b/ceilometerclient/tests/unit/v1/test_users.py
deleted file mode 100644
index e8e98a1..0000000
--- a/ceilometerclient/tests/unit/v1/test_users.py
+++ /dev/null
@@ -1,65 +0,0 @@
-# Copyright 2012 OpenStack Foundation
-# All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-from ceilometerclient.openstack.common.apiclient import client
-from ceilometerclient.openstack.common.apiclient import fake_client
-from ceilometerclient.tests.unit import utils
-import ceilometerclient.v1.meters
-
-
-fixtures = {
- '/v1/users': {
- 'GET': (
- {},
- {'users': [
- 'a',
- 'b',
- ]},
- ),
- },
- '/v1/sources/source_b/users': {
- 'GET': (
- {},
- {'users': ['b']},
- ),
- },
-}
-
-
-class UserManagerTest(utils.BaseTestCase):
-
- def setUp(self):
- super(UserManagerTest, self).setUp()
- self.http_client = fake_client.FakeHTTPClient(fixtures=fixtures)
- self.api = client.BaseClient(self.http_client)
- self.mgr = ceilometerclient.v1.meters.UserManager(self.api)
-
- def test_list_all(self):
- users = list(self.mgr.list())
- expect = [
- 'GET', '/v1/users'
- ]
- self.http_client.assert_called(*expect)
- self.assertEqual(len(users), 2)
- self.assertEqual(users[0].user_id, 'a')
- self.assertEqual(users[1].user_id, 'b')
-
- def test_list_by_source(self):
- users = list(self.mgr.list(source='source_b'))
- expect = [
- 'GET', '/v1/sources/source_b/users'
- ]
- self.http_client.assert_called(*expect)
- self.assertEqual(len(users), 1)
- self.assertEqual(users[0].user_id, 'b')