1 from unittest import TestCase
2 from openid.yadis import xri
3
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')
12
13
16 self.failUnlessEqual(xri.escapeForIRI('@example/abc%2Fd/ef'),
17 '@example/abc%252Fd/ef')
18
19
21
22 esc = xri.escapeForIRI
23 self.failUnlessEqual('@example/foo/(@bar)', esc('@example/foo/(@bar)'))
24
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
30 self.failUnlessEqual('@example/foo/(@baz%3Fp=q%23r)?i=j#k',
31 esc('@example/foo/(@baz?p=q#r)?i=j#k'))
32
33
34
52
53
54
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)
62
63 return test
64
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)
68
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)
73
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
80
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")
93
94
95
96
97
98
99
100 if __name__ == '__main__':
101 import unittest
102 unittest.main()
103