Merge "Fixes test_exceptions.py for Python3"
This commit is contained in:
commit
686597b52a
@ -12,7 +12,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import six
|
import io
|
||||||
|
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
from testtools import matchers
|
from testtools import matchers
|
||||||
@ -35,13 +35,13 @@ class XMLEquals(object):
|
|||||||
def canonical_xml(s):
|
def canonical_xml(s):
|
||||||
s = s.strip()
|
s = s.strip()
|
||||||
|
|
||||||
fp = six.StringIO()
|
fp = io.BytesIO()
|
||||||
dom = etree.fromstring(s, parser)
|
dom = etree.fromstring(s, parser)
|
||||||
dom.getroottree().write_c14n(fp)
|
dom.getroottree().write_c14n(fp)
|
||||||
s = fp.getvalue()
|
s = fp.getvalue()
|
||||||
|
|
||||||
dom = etree.fromstring(s, parser)
|
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)
|
expected = canonical_xml(self.expected)
|
||||||
other = canonical_xml(other)
|
other = canonical_xml(other)
|
||||||
|
@ -89,15 +89,15 @@ class ExceptionTestCase(tests.TestCase):
|
|||||||
e = exception.ValidationError(attribute='xx',
|
e = exception.ValidationError(attribute='xx',
|
||||||
target='Long \xe2\x80\x93 Dash')
|
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):
|
def test_invalid_unicode_string(self):
|
||||||
# NOTE(jamielennox): This is a complete failure case so what is
|
# 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
|
# returned in the exception message is not that important so long
|
||||||
# an error with a message
|
# as there is an error with a message
|
||||||
e = exception.ValidationError(attribute='xx',
|
e = exception.ValidationError(attribute='xx',
|
||||||
target='\xe7a va')
|
target='\xe7a va')
|
||||||
self.assertIn('%(attribute)', e.message)
|
self.assertIn('%(attribute)', six.text_type(e))
|
||||||
|
|
||||||
|
|
||||||
class UnexpectedExceptionTestCase(ExceptionTestCase):
|
class UnexpectedExceptionTestCase(ExceptionTestCase):
|
||||||
|
@ -21,19 +21,19 @@ from keystone.tests import matchers
|
|||||||
|
|
||||||
|
|
||||||
class TestXMLEquals(tests.BaseTestCase, helpers.TestMatchersInterface):
|
class TestXMLEquals(tests.BaseTestCase, helpers.TestMatchersInterface):
|
||||||
matches_xml = """
|
matches_xml = b"""
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<test xmlns="http://docs.openstack.org/identity/api/v2.0">
|
<test xmlns="http://docs.openstack.org/identity/api/v2.0">
|
||||||
<success a="a" b="b"/>
|
<success a="a" b="b"/>
|
||||||
</test>
|
</test>
|
||||||
"""
|
"""
|
||||||
equivalent_xml = """
|
equivalent_xml = b"""
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<test xmlns="http://docs.openstack.org/identity/api/v2.0">
|
<test xmlns="http://docs.openstack.org/identity/api/v2.0">
|
||||||
<success b="b" a="a"></success>
|
<success b="b" a="a"></success>
|
||||||
</test>
|
</test>
|
||||||
"""
|
"""
|
||||||
mismatches_xml = """
|
mismatches_xml = b"""
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<test xmlns="http://docs.openstack.org/identity/api/v2.0">
|
<test xmlns="http://docs.openstack.org/identity/api/v2.0">
|
||||||
<nope_it_fails/>
|
<nope_it_fails/>
|
||||||
|
1
tox.ini
1
tox.ini
@ -27,6 +27,7 @@ commands =
|
|||||||
keystone/tests/test_driver_hints.py \
|
keystone/tests/test_driver_hints.py \
|
||||||
keystone/tests/test_hacking_checks.py \
|
keystone/tests/test_hacking_checks.py \
|
||||||
keystone/tests/test_injection.py \
|
keystone/tests/test_injection.py \
|
||||||
|
keystone/tests/test_matchers.py \
|
||||||
keystone/tests/test_policy.py \
|
keystone/tests/test_policy.py \
|
||||||
keystone/tests/test_s3_token_middleware.py \
|
keystone/tests/test_s3_token_middleware.py \
|
||||||
keystone/tests/test_singular_plural.py \
|
keystone/tests/test_singular_plural.py \
|
||||||
|
Loading…
Reference in New Issue
Block a user