openstacksdk/openstack/tests/unit/test_format.py
Monty Taylor 1b43673c04
Update all test base classes to use base.TestCase
We have a centrally defined test case base class that handles a set of
things like log capture, mocking time.sleep and setting up
requests-mock.

We also had a split base test case, with some things using TestCase and
some using RequestsMockTestCase. This was a holdover from the transition
to requests-mock. We are finally at the point where we don't need the
split, so merge TestCase and RequestsMockTest case.

Then, update all of the tests to use the new combined base class.

Also, replace a use of unittest.skipTest with self.skipTest from the
base class.

Change-Id: I2cc3e201a5241262e5d102d3de8423c4fb2a8c4a
2018-02-16 23:19:41 -06:00

39 lines
1.7 KiB
Python

# 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 openstack.tests.unit import base
from openstack import format
class TestBoolStrFormatter(base.TestCase):
def test_deserialize(self):
self.assertTrue(format.BoolStr.deserialize(True))
self.assertTrue(format.BoolStr.deserialize('True'))
self.assertTrue(format.BoolStr.deserialize('TRUE'))
self.assertTrue(format.BoolStr.deserialize('true'))
self.assertFalse(format.BoolStr.deserialize(False))
self.assertFalse(format.BoolStr.deserialize('False'))
self.assertFalse(format.BoolStr.deserialize('FALSE'))
self.assertFalse(format.BoolStr.deserialize('false'))
self.assertRaises(ValueError, format.BoolStr.deserialize, None)
self.assertRaises(ValueError, format.BoolStr.deserialize, '')
self.assertRaises(ValueError, format.BoolStr.deserialize, 'INVALID')
def test_serialize(self):
self.assertEqual('true', format.BoolStr.serialize(True))
self.assertEqual('false', format.BoolStr.serialize(False))
self.assertRaises(ValueError, format.BoolStr.serialize, None)
self.assertRaises(ValueError, format.BoolStr.serialize, '')
self.assertRaises(ValueError, format.BoolStr.serialize, 'True')