Improved adapter base coverage

- Improved a log message in base.

Change-Id: I93ad2db742682adcd196705a1c3f9315b9ac956c
This commit is contained in:
Erik Olof Gunnar Andersson 2023-11-08 07:28:57 -08:00
parent 4e185d4e26
commit 1fb207f8cc
2 changed files with 32 additions and 1 deletions

View File

@ -68,7 +68,7 @@ class DesignateAdapter(metaclass=DesignateObjectAdapterMetaclass):
try:
return cls._adapter_classes[key]
except KeyError as e:
keys = str(e).split(':')
keys = str(e).strip('\'').split(':')
raise exceptions.AdapterNotFound(
'Adapter for %(obj)s to format %(format)s not found' %
{

View File

@ -14,6 +14,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import datetime
from unittest import mock
from oslo_log import log as logging
from oslo_utils import timeutils
@ -97,6 +98,29 @@ class DesignateAdapterTest(oslotest.base.BaseTestCase):
self.assertIsInstance(test_obj, DesignateTestObject)
self.assertEqual('example.test.', test_obj.name)
@mock.patch.object(DesignateTestAdapter, 'parse_object')
def test_parse_type_error(self, mock_parse_object):
mock_parse_object.side_effect = TypeError('test')
self.assertRaisesRegex(
exceptions.InvalidObject,
'Provided object is not valid. Got a TypeError with message test',
adapters.DesignateAdapter.parse, 'TEST_API', {},
DesignateTestObject()
)
@mock.patch.object(DesignateTestAdapter, 'parse_object')
def test_parse_attribute_error(self, mock_parse_object):
mock_parse_object.side_effect = AttributeError('test')
self.assertRaisesRegex(
exceptions.InvalidObject,
'Provided object is not valid. Got an AttributeError '
'with message test',
adapters.DesignateAdapter.parse, 'TEST_API', {},
DesignateTestObject()
)
def test_parse_schema_does_not_match(self):
self.assertRaisesRegex(
exceptions.InvalidObject,
@ -113,6 +137,13 @@ class DesignateAdapterTest(oslotest.base.BaseTestCase):
self.assertIsInstance(adapter(), DesignateTestAdapter)
def test_get_object_adapter_not_found(self):
self.assertRaisesRegex(
exceptions.AdapterNotFound,
'Adapter for DesignateTestObject to format None not found',
adapters.DesignateAdapter.get_object_adapter, DesignateTestObject()
)
def test_object_render(self):
test_obj = adapters.DesignateAdapter.render(
'TEST_API', DesignateTestObject()