Merge "Fix api_validation for Python 3"

This commit is contained in:
Jenkins 2016-07-02 11:06:17 +00:00 committed by Gerrit Code Review
commit 4c4591f2cd
3 changed files with 10 additions and 2 deletions

View File

@ -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

View File

@ -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)

View File

@ -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