summaryrefslogtreecommitdiff
path: root/novaclient/tests/unit/v2/test_usage.py
diff options
context:
space:
mode:
Diffstat (limited to 'novaclient/tests/unit/v2/test_usage.py')
-rw-r--r--novaclient/tests/unit/v2/test_usage.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/novaclient/tests/unit/v2/test_usage.py b/novaclient/tests/unit/v2/test_usage.py
new file mode 100644
index 0000000..a92be0e
--- /dev/null
+++ b/novaclient/tests/unit/v2/test_usage.py
@@ -0,0 +1,57 @@
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
14import datetime
15
16from novaclient.tests.unit import utils
17from novaclient.tests.unit.v2 import fakes
18from novaclient.v2 import usage
19
20
21class UsageTest(utils.TestCase):
22 def setUp(self):
23 super(UsageTest, self).setUp()
24 self.cs = self._get_fake_client()
25 self.usage_type = self._get_usage_type()
26
27 def _get_fake_client(self):
28 return fakes.FakeClient()
29
30 def _get_usage_type(self):
31 return usage.Usage
32
33 def test_usage_list(self, detailed=False):
34 now = datetime.datetime.now()
35 usages = self.cs.usage.list(now, now, detailed)
36
37 self.cs.assert_called(
38 'GET',
39 "/os-simple-tenant-usage?" +
40 ("start=%s&" % now.isoformat()) +
41 ("end=%s&" % now.isoformat()) +
42 ("detailed=%s" % int(bool(detailed))))
43 [self.assertIsInstance(u, usage.Usage) for u in usages]
44
45 def test_usage_list_detailed(self):
46 self.test_usage_list(True)
47
48 def test_usage_get(self):
49 now = datetime.datetime.now()
50 u = self.cs.usage.get("tenantfoo", now, now)
51
52 self.cs.assert_called(
53 'GET',
54 "/os-simple-tenant-usage/tenantfoo?" +
55 ("start=%s&" % now.isoformat()) +
56 ("end=%s" % now.isoformat()))
57 self.assertIsInstance(u, usage.Usage)