summaryrefslogtreecommitdiffstats
path: root/tests/test_ipalib
diff options
context:
space:
mode:
authorJohn Dennis <jdennis@redhat.com>2011-08-03 19:26:19 -0400
committerRob Crittenden <rcritten@redhat.com>2011-08-16 23:27:46 -0400
commit97f0671ce9dd1d260fea4e95f6e6e017a1ef1048 (patch)
treed31677862b116cca6e648009ae1816b0803fa1bf /tests/test_ipalib
parentb13899ebc523cbb5f1ec09cc78ac92d696ee966f (diff)
downloadfreeipa-97f0671ce9dd1d260fea4e95f6e6e017a1ef1048.tar.gz
freeipa-97f0671ce9dd1d260fea4e95f6e6e017a1ef1048.tar.xz
freeipa-97f0671ce9dd1d260fea4e95f6e6e017a1ef1048.zip
ticket 1569 - Test DN object non-latin Unicode support
The DN unittest was lacking a test for i18n. The unittest was updated to store "Hello" in Arabic with both utf-8 and unicode and verify the values could be properly retrieved and converted to dn string syntax. During the testing a few problems were discovered and corrected. * passing in utf-8 caused an ASCII decode error becuase of Python's silly default encoding of ASCII. The fix was to explictly use the utf-8 codec. * there were a couple of places where encode/decode were not called correctly. * the internal attr and value members of the AVA class were renamed to explicitly show they are stored as unicode. Of course the unittest was updated as well.
Diffstat (limited to 'tests/test_ipalib')
-rw-r--r--tests/test_ipalib/test_dn.py94
1 files changed, 94 insertions, 0 deletions
diff --git a/tests/test_ipalib/test_dn.py b/tests/test_ipalib/test_dn.py
index f4aa0aaec..04e442f3f 100644
--- a/tests/test_ipalib/test_dn.py
+++ b/tests/test_ipalib/test_dn.py
@@ -987,5 +987,99 @@ class TestEscapes(unittest.TestCase):
self.assertEqual(dn['cn'], self.privilege)
self.assertEqual(dn[0].value, self.privilege)
+class TestInternationalization(unittest.TestCase):
+ def setUp(self):
+ # Hello in Arabic
+ self.arabic_hello_utf8 = '\xd9\x85\xd9\x83\xd9\x8a\xd9\x84' + \
+ '\xd8\xb9\x20\xd9\x85\xd8\xa7\xd9' + \
+ '\x84\xd9\x91\xd8\xb3\xd9\x84\xd8\xa7'
+
+ self.arabic_hello_unicode = self.arabic_hello_utf8.decode('utf-8')
+
+ def test_i18n(self):
+ self.assertEqual(self.arabic_hello_utf8,
+ self.arabic_hello_unicode.encode('utf-8'))
+
+ # AVA's
+ # test attr i18n
+ ava1 = AVA(self.arabic_hello_unicode, 'foo')
+ self.assertIsInstance(ava1.attr, unicode)
+ self.assertIsInstance(ava1.value, unicode)
+ self.assertEqual(ava1.attr, self.arabic_hello_unicode)
+ self.assertEqual(str(ava1), self.arabic_hello_utf8+'=foo')
+
+ ava1 = AVA(self.arabic_hello_utf8, 'foo')
+ self.assertIsInstance(ava1.attr, unicode)
+ self.assertIsInstance(ava1.value, unicode)
+ self.assertEqual(ava1.attr, self.arabic_hello_unicode)
+ self.assertEqual(str(ava1), self.arabic_hello_utf8+'=foo')
+
+ # test value i18n
+ ava1 = AVA('cn', self.arabic_hello_unicode)
+ self.assertIsInstance(ava1.attr, unicode)
+ self.assertIsInstance(ava1.value, unicode)
+ self.assertEqual(ava1.value, self.arabic_hello_unicode)
+ self.assertEqual(str(ava1), 'cn='+self.arabic_hello_utf8)
+
+ ava1 = AVA('cn', self.arabic_hello_utf8)
+ self.assertIsInstance(ava1.attr, unicode)
+ self.assertIsInstance(ava1.value, unicode)
+ self.assertEqual(ava1.value, self.arabic_hello_unicode)
+ self.assertEqual(str(ava1), 'cn='+self.arabic_hello_utf8)
+
+ # RDN's
+ # test attr i18n
+ rdn1 = RDN((self.arabic_hello_unicode, 'foo'))
+ self.assertIsInstance(rdn1.attr, unicode)
+ self.assertIsInstance(rdn1.value, unicode)
+ self.assertEqual(rdn1.attr, self.arabic_hello_unicode)
+ self.assertEqual(str(rdn1), self.arabic_hello_utf8+'=foo')
+
+ rdn1 = RDN((self.arabic_hello_utf8, 'foo'))
+ self.assertIsInstance(rdn1.attr, unicode)
+ self.assertIsInstance(rdn1.value, unicode)
+ self.assertEqual(rdn1.attr, self.arabic_hello_unicode)
+ self.assertEqual(str(rdn1), self.arabic_hello_utf8+'=foo')
+
+ # test value i18n
+ rdn1 = RDN(('cn', self.arabic_hello_unicode))
+ self.assertIsInstance(rdn1.attr, unicode)
+ self.assertIsInstance(rdn1.value, unicode)
+ self.assertEqual(rdn1.value, self.arabic_hello_unicode)
+ self.assertEqual(str(rdn1), 'cn='+self.arabic_hello_utf8)
+
+ rdn1 = RDN(('cn', self.arabic_hello_utf8))
+ self.assertIsInstance(rdn1.attr, unicode)
+ self.assertIsInstance(rdn1.value, unicode)
+ self.assertEqual(rdn1.value, self.arabic_hello_unicode)
+ self.assertEqual(str(rdn1), 'cn='+self.arabic_hello_utf8)
+
+ # DN's
+ # test attr i18n
+ dn1 = DN((self.arabic_hello_unicode, 'foo'))
+ self.assertIsInstance(dn1[0].attr, unicode)
+ self.assertIsInstance(dn1[0].value, unicode)
+ self.assertEqual(dn1[0].attr, self.arabic_hello_unicode)
+ self.assertEqual(str(dn1), self.arabic_hello_utf8+'=foo')
+
+ dn1 = DN((self.arabic_hello_utf8, 'foo'))
+ self.assertIsInstance(dn1[0].attr, unicode)
+ self.assertIsInstance(dn1[0].value, unicode)
+ self.assertEqual(dn1[0].attr, self.arabic_hello_unicode)
+ self.assertEqual(str(dn1), self.arabic_hello_utf8+'=foo')
+
+ # test value i18n
+ dn1 = DN(('cn', self.arabic_hello_unicode))
+ self.assertIsInstance(dn1[0].attr, unicode)
+ self.assertIsInstance(dn1[0].value, unicode)
+ self.assertEqual(dn1[0].value, self.arabic_hello_unicode)
+ self.assertEqual(str(dn1), 'cn='+self.arabic_hello_utf8)
+
+ dn1 = DN(('cn', self.arabic_hello_utf8))
+ self.assertIsInstance(dn1[0].attr, unicode)
+ self.assertIsInstance(dn1[0].value, unicode)
+ self.assertEqual(dn1[0].value, self.arabic_hello_unicode)
+ self.assertEqual(str(dn1), 'cn='+self.arabic_hello_utf8)
+
if __name__ == '__main__':
unittest.main()