Add some unit tests for cloudkitty/api/v1

Add unit tests for cloudkitty/api/types to test UuidType and Multi-
Type and for cloudkitty/datamodels/report to test SummaryModel
initialization.

Change-Id: I53b44da7d4d5e85afc079a88c8f7b06f40905aae
This commit is contained in:
qin.jiang 2017-02-28 15:01:47 +08:00 committed by Luka Peschke
parent c1e0844175
commit f21c49cf4b
4 changed files with 91 additions and 0 deletions

View File

View File

View File

@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Objectif Libre
#
# 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.
#
"""Test SummaryModel objects."""
from oslotest import base
from cloudkitty.api.v1.datamodels import report
class TestSummary(base.BaseTestCase):
def setUp(self):
super(TestSummary, self).setUp()
def test_nulls(self):
s = report.SummaryModel(begin=None,
end=None,
tenant_id=None,
res_type=None,
rate=None)
self.assertIsNone(s.begin)
self.assertIsNone(s.end)
self.assertEqual(s.tenant_id, "ALL")
self.assertEqual(s.res_type, "ALL")
self.assertEqual(s.rate, "0")

View File

@ -0,0 +1,53 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Objectif Libre
#
# 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.
#
"""Test cloudkitty/api/v1/types."""
from oslotest import base
from wsme import types as wtypes
from cloudkitty.api.v1 import types
class TestTypes(base.BaseTestCase):
def setUp(self):
super(TestTypes, self).setUp()
self.uuidtype = types.UuidType
self.multitype = types.MultiType(wtypes.text, int, float, dict)
def test_valid_uuid_values(self):
valid_values = ['7977999e-2e25-11e6-a8b2-df30b233ffcb',
'ac55b000-a05b-4832-b2ff-265a034886ab',
'39dbd39d-f663-4444-a795-fb19d81af136']
for valid_value in valid_values:
self.uuidtype.validate(valid_value)
def test_invalid_uuid_values(self):
invalid_values = ['dxwegycw', '1234567', '#@%^&$*!']
for invalid_value in invalid_values:
self.assertRaises(ValueError, self.uuidtype.validate,
invalid_value)
def test_valid_multi_values(self):
valid_values = ['string_value', 123, 23.4, {'key': 'value'}]
for valid_value in valid_values:
self.multitype.validate(valid_value)
def test_invalid_multi_values(self):
invalid_values = [[1, 2, 3], ('a', 'b', 'c')]
for invalid_value in invalid_values:
self.assertRaises(ValueError, self.multitype.validate,
invalid_value)