Merge "Fixes test_exceptions.py for Python3"

This commit is contained in:
Jenkins 2014-07-22 21:42:57 +00:00 committed by Gerrit Code Review
commit 686597b52a
4 changed files with 11 additions and 10 deletions

View File

@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
import io
from lxml import etree
from testtools import matchers
@ -35,13 +35,13 @@ class XMLEquals(object):
def canonical_xml(s):
s = s.strip()
fp = six.StringIO()
fp = io.BytesIO()
dom = etree.fromstring(s, parser)
dom.getroottree().write_c14n(fp)
s = fp.getvalue()
dom = etree.fromstring(s, parser)
return etree.tostring(dom, pretty_print=True)
return etree.tostring(dom, pretty_print=True).decode('utf-8')
expected = canonical_xml(self.expected)
other = canonical_xml(other)

View File

@ -89,15 +89,15 @@ class ExceptionTestCase(tests.TestCase):
e = exception.ValidationError(attribute='xx',
target='Long \xe2\x80\x93 Dash')
self.assertIn(u'\u2013', e.message)
self.assertIn(u'\u2013', six.text_type(e))
def test_invalid_unicode_string(self):
# NOTE(jamielennox): This is a complete failure case so what is
# returned in the e.message is not that important so long as there is
# an error with a message
# returned in the exception message is not that important so long
# as there is an error with a message
e = exception.ValidationError(attribute='xx',
target='\xe7a va')
self.assertIn('%(attribute)', e.message)
self.assertIn('%(attribute)', six.text_type(e))
class UnexpectedExceptionTestCase(ExceptionTestCase):

View File

@ -21,19 +21,19 @@ from keystone.tests import matchers
class TestXMLEquals(tests.BaseTestCase, helpers.TestMatchersInterface):
matches_xml = """
matches_xml = b"""
<?xml version="1.0" encoding="UTF-8"?>
<test xmlns="http://docs.openstack.org/identity/api/v2.0">
<success a="a" b="b"/>
</test>
"""
equivalent_xml = """
equivalent_xml = b"""
<?xml version="1.0" encoding="UTF-8"?>
<test xmlns="http://docs.openstack.org/identity/api/v2.0">
<success b="b" a="a"></success>
</test>
"""
mismatches_xml = """
mismatches_xml = b"""
<?xml version="1.0" encoding="UTF-8"?>
<test xmlns="http://docs.openstack.org/identity/api/v2.0">
<nope_it_fails/>

View File

@ -27,6 +27,7 @@ commands =
keystone/tests/test_driver_hints.py \
keystone/tests/test_hacking_checks.py \
keystone/tests/test_injection.py \
keystone/tests/test_matchers.py \
keystone/tests/test_policy.py \
keystone/tests/test_s3_token_middleware.py \
keystone/tests/test_singular_plural.py \