Fix api_validation for Python 3
* Convert argument to base64.decodestring() to bytes for PY3. * Fix an issue with python3.5 where the format of an internal error message changed. Change-Id: If8184c190e76d8cefb5b097f8fa8cb7564207103 Closes-Bug: 1598062
This commit is contained in:
parent
3b87313eb4
commit
b7033277dc
@ -45,6 +45,8 @@ def _validate_datetime_format(instance):
|
||||
@jsonschema.FormatChecker.cls_checks('base64')
|
||||
def _validate_base64_format(instance):
|
||||
try:
|
||||
if isinstance(instance, six.text_type):
|
||||
instance = instance.encode('utf-8')
|
||||
base64.decodestring(instance)
|
||||
except base64.binascii.Error:
|
||||
return False
|
||||
|
@ -18,6 +18,7 @@ import re
|
||||
import fixtures
|
||||
from jsonschema import exceptions as jsonschema_exc
|
||||
import six
|
||||
import sys
|
||||
|
||||
from nova.api.openstack import api_version_request as api_version
|
||||
from nova.api import validation
|
||||
@ -354,7 +355,13 @@ class PatternPropertiesTestCase(APIValidationTestCase):
|
||||
self.check_validation_error(self.post, body={'0123456789a': 'bar'},
|
||||
expected_detail=detail)
|
||||
|
||||
detail = "expected string or buffer"
|
||||
# Note(jrosenboom): This is referencing an internal python error
|
||||
# string, which is no stable interface. We need a patch in the
|
||||
# jsonschema library in order to fix this properly.
|
||||
if sys.version[:3] == '3.5':
|
||||
detail = "expected string or bytes-like object"
|
||||
else:
|
||||
detail = "expected string or buffer"
|
||||
self.check_validation_error(self.post, body={None: 'bar'},
|
||||
expected_detail=detail)
|
||||
|
||||
|
@ -56,7 +56,6 @@ nova.tests.unit.network.test_manager.LdapDNSTestCase
|
||||
nova.tests.unit.pci.test_manager.PciDevTrackerTestCase
|
||||
nova.tests.unit.pci.test_stats.PciDeviceStatsTestCase
|
||||
nova.tests.unit.pci.test_stats.PciDeviceStatsWithTagsTestCase
|
||||
nova.tests.unit.test_api_validation.Base64TestCase
|
||||
nova.tests.unit.test_bdm.BlockDeviceMappingEc2CloudTestCase
|
||||
nova.tests.unit.test_configdrive2.ConfigDriveTestCase
|
||||
nova.tests.unit.test_hacking.HackingTestCase
|
||||
|
Loading…
Reference in New Issue
Block a user