getting file size for all dict files to be downloaded. coming to be 400mb or so.
[worddb.git] / libs / openid / test / test_xri.py
blobdc5921aefcbfa030a4d5e1e82efd847f5c35ae35
1 from unittest import TestCase
2 from openid.yadis import xri
4 class XriDiscoveryTestCase(TestCase):
5 def test_isXRI(self):
6 i = xri.identifierScheme
7 self.failUnlessEqual(i('=john.smith'), 'XRI')
8 self.failUnlessEqual(i('@smiths/john'), 'XRI')
9 self.failUnlessEqual(i('smoker.myopenid.com'), 'URI')
10 self.failUnlessEqual(i('xri://=john'), 'XRI')
11 self.failUnlessEqual(i(''), 'URI')
14 class XriEscapingTestCase(TestCase):
15 def test_escaping_percents(self):
16 self.failUnlessEqual(xri.escapeForIRI('@example/abc%2Fd/ef'),
17 '@example/abc%252Fd/ef')
20 def test_escaping_xref(self):
21 # no escapes
22 esc = xri.escapeForIRI
23 self.failUnlessEqual('@example/foo/(@bar)', esc('@example/foo/(@bar)'))
24 # escape slashes
25 self.failUnlessEqual('@example/foo/(@bar%2Fbaz)',
26 esc('@example/foo/(@bar/baz)'))
27 self.failUnlessEqual('@example/foo/(@bar%2Fbaz)/(+a%2Fb)',
28 esc('@example/foo/(@bar/baz)/(+a/b)'))
29 # escape query ? and fragment #
30 self.failUnlessEqual('@example/foo/(@baz%3Fp=q%23r)?i=j#k',
31 esc('@example/foo/(@baz?p=q#r)?i=j#k'))
35 class XriTransformationTestCase(TestCase):
36 def test_to_iri_normal(self):
37 self.failUnlessEqual(xri.toIRINormal('@example'), 'xri://@example')
39 try:
40 unichr(0x10000)
41 except ValueError:
42 # bleh narrow python build
43 def test_iri_to_url(self):
44 s = u'l\xa1m'
45 expected = 'l%C2%A1m'
46 self.failUnlessEqual(xri.iriToURI(s), expected)
47 else:
48 def test_iri_to_url(self):
49 s = u'l\xa1m\U00101010n'
50 expected = 'l%C2%A1m%F4%81%80%90n'
51 self.failUnlessEqual(xri.iriToURI(s), expected)
55 class CanonicalIDTest(TestCase):
56 def mkTest(providerID, canonicalID, isAuthoritative):
57 def test(self):
58 result = xri.providerIsAuthoritative(providerID, canonicalID)
59 format = "%s providing %s, expected %s"
60 message = format % (providerID, canonicalID, isAuthoritative)
61 self.failUnlessEqual(isAuthoritative, result, message)
63 return test
65 test_equals = mkTest('=', '=!698.74D1.A1F2.86C7', True)
66 test_atOne = mkTest('@!1234', '@!1234!ABCD', True)
67 test_atTwo = mkTest('@!1234!5678', '@!1234!5678!ABCD', True)
69 test_atEqualsFails = mkTest('@!1234', '=!1234!ABCD', False)
70 test_tooDeepFails = mkTest('@!1234', '@!1234!ABCD!9765', False)
71 test_atEqualsAndTooDeepFails = mkTest('@!1234!ABCD', '=!1234', False)
72 test_differentBeginningFails = mkTest('=!BABE', '=!D00D', False)
74 class TestGetRootAuthority(TestCase):
75 def mkTest(the_xri, expected_root):
76 def test(self):
77 actual_root = xri.rootAuthority(the_xri)
78 self.failUnlessEqual(actual_root, xri.XRI(expected_root))
79 return test
81 test_at = mkTest("@foo", "@")
82 test_atStar = mkTest("@foo*bar", "@")
83 test_atStarStar = mkTest("@*foo*bar", "@")
84 test_atWithPath = mkTest("@foo/bar", "@")
85 test_bangBang = mkTest("!!990!991", "!")
86 test_bang = mkTest("!1001!02", "!")
87 test_equalsStar = mkTest("=foo*bar", "=")
88 test_xrefPath = mkTest("(example.com)/foo", "(example.com)")
89 test_xrefStar = mkTest("(example.com)*bar/foo", "(example.com)")
90 test_uriAuth = mkTest("baz.example.com/foo", "baz.example.com")
91 test_uriAuthPort = mkTest("baz.example.com:8080/foo",
92 "baz.example.com:8080")
94 # Looking at the ABNF in XRI Syntax 2.0, I don't think you can
95 # have example.com*bar. You can do (example.com)*bar, but that
96 # would mean something else.
97 ##("example.com*bar/(=baz)", "example.com*bar"),
98 ##("baz.example.com!01/foo", "baz.example.com!01"),
100 if __name__ == '__main__':
101 import unittest
102 unittest.main()