Improve unit test coverage
Added unit tests to test_types.py and test_magnum_service.py. Also, lines containing abstract methods and 'pass' were being counted in the coverage metrics, so those were added to the coveragerc. Change-Id: I4af7005453b8f843b640661a972b3f1689ed7dd0 Partial-Bug: #1511667
This commit is contained in:
parent
70fed16ba3
commit
91d8aa4fc5
|
@ -5,3 +5,6 @@ omit = magnum/tests/*,magnum/openstack/*
|
||||||
|
|
||||||
[report]
|
[report]
|
||||||
ignore_errors = True
|
ignore_errors = True
|
||||||
|
exclude_lines =
|
||||||
|
@abc.abstract
|
||||||
|
pass
|
||||||
|
|
|
@ -37,6 +37,16 @@ class TestMacAddressType(base.FunctionalTest):
|
||||||
self.assertRaises(exception.InvalidMAC,
|
self.assertRaises(exception.InvalidMAC,
|
||||||
types.MacAddressType.validate, 'invalid-mac')
|
types.MacAddressType.validate, 'invalid-mac')
|
||||||
|
|
||||||
|
def test_frombasetype(self):
|
||||||
|
test_mac = 'aa:bb:cc:11:22:33'
|
||||||
|
with mock.patch.object(utils, 'validate_and_normalize_mac') as m_mock:
|
||||||
|
types.MacAddressType.frombasetype(test_mac)
|
||||||
|
m_mock.assert_called_once_with(test_mac)
|
||||||
|
|
||||||
|
def test_frombasetype_no_value(self):
|
||||||
|
test_mac = None
|
||||||
|
self.assertEqual(None, types.MacAddressType.frombasetype(test_mac))
|
||||||
|
|
||||||
|
|
||||||
class TestUuidType(base.FunctionalTest):
|
class TestUuidType(base.FunctionalTest):
|
||||||
|
|
||||||
|
@ -207,6 +217,10 @@ class TestBooleanType(base.FunctionalTest):
|
||||||
self.assertRaises(exception.Invalid, v.validate, "invalid-value")
|
self.assertRaises(exception.Invalid, v.validate, "invalid-value")
|
||||||
self.assertRaises(exception.Invalid, v.validate, "01")
|
self.assertRaises(exception.Invalid, v.validate, "01")
|
||||||
|
|
||||||
|
def test_frombasetype_no_value(self):
|
||||||
|
v = types.BooleanType()
|
||||||
|
self.assertEqual(None, v.frombasetype(None))
|
||||||
|
|
||||||
|
|
||||||
class TestNameType(base.FunctionalTest):
|
class TestNameType(base.FunctionalTest):
|
||||||
|
|
||||||
|
@ -217,3 +231,10 @@ class TestNameType(base.FunctionalTest):
|
||||||
def test_invalid_name(self):
|
def test_invalid_name(self):
|
||||||
self.assertRaises(exception.InvalidName, types.NameType.validate, None)
|
self.assertRaises(exception.InvalidName, types.NameType.validate, None)
|
||||||
self.assertRaises(exception.InvalidName, types.NameType.validate, '')
|
self.assertRaises(exception.InvalidName, types.NameType.validate, '')
|
||||||
|
|
||||||
|
def test_frombasetype_no_value(self):
|
||||||
|
self.assertEqual('name', types.NameType.frombasetype('name'))
|
||||||
|
self.assertEqual(1234, types.NameType.frombasetype(1234))
|
||||||
|
|
||||||
|
def test_frombasetype(self):
|
||||||
|
self.assertEqual(None, types.NameType.frombasetype(None))
|
||||||
|
|
|
@ -36,6 +36,16 @@ class TestMagnumServiceObject(base.DbTestCase):
|
||||||
'fake-bin')
|
'fake-bin')
|
||||||
self.assertEqual(self.context, ms._context)
|
self.assertEqual(self.context, ms._context)
|
||||||
|
|
||||||
|
def test_get_by_host_and_binary_no_service(self):
|
||||||
|
with mock.patch.object(self.dbapi, 'create_magnum_service',
|
||||||
|
autospec=True) as mock_get_magnum_service:
|
||||||
|
mock_get_magnum_service.return_value = None
|
||||||
|
ms = objects.MagnumService.get_by_host_and_binary(self.context,
|
||||||
|
'fake-host',
|
||||||
|
'fake-bin')
|
||||||
|
|
||||||
|
self.assertIsNone(ms)
|
||||||
|
|
||||||
def test_create(self):
|
def test_create(self):
|
||||||
with mock.patch.object(self.dbapi, 'create_magnum_service',
|
with mock.patch.object(self.dbapi, 'create_magnum_service',
|
||||||
autospec=True) as mock_create_magnum_service:
|
autospec=True) as mock_create_magnum_service:
|
||||||
|
|
Loading…
Reference in New Issue