~gary/python-openid/python-openid-2.2.1-patched

« back to all changes in this revision

Viewing changes to openid/test/oidutil.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2007-11-30 02:46:28 UTC
  • mfrom: (1.1.1 pyopenid-2.0)
  • Revision ID: launchpad@pqm.canonical.com-20071130024628-qktwsew3383iawmq
[rs=SteveA] upgrade to python-openid-2.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
        s_prime = oidutil.fromBase64(b64)
40
40
        assert s_prime == s, (s, b64, s_prime)
41
41
 
42
 
def test_normalizeUrl():
43
 
    n = oidutil.normalizeUrl
44
 
 
45
 
    assert 'http://foo.com/' == n('foo.com')
46
 
 
47
 
    assert 'http://foo.com/' == n('http://foo.com')
48
 
    assert 'https://foo.com/' == n('https://foo.com')
49
 
    assert 'http://foo.com/bar' == n('foo.com/bar')
50
 
    assert 'http://foo.com/bar' == n('http://foo.com/bar')
51
 
 
52
 
    assert 'http://foo.com/' == n('http://foo.com/')
53
 
    assert 'https://foo.com/' == n('https://foo.com/')
54
 
    assert 'https://foo.com/bar'  == n('https://foo.com/bar')
55
 
 
56
 
    assert 'http://foo.com/%E8%8D%89' == n(u'foo.com/\u8349')
57
 
    assert 'http://foo.com/%E8%8D%89' == n(u'http://foo.com/\u8349')
58
 
 
59
 
    non_ascii_domain_cases = [
60
 
        ('http://xn--vl1a.com/', u'\u8349.com'),
61
 
        ('http://xn--vl1a.com/', u'http://\u8349.com'),
62
 
        ('http://xn--vl1a.com/', u'\u8349.com/'),
63
 
        ('http://xn--vl1a.com/', u'http://\u8349.com/'),
64
 
        ('http://xn--vl1a.com/%E8%8D%89', u'\u8349.com/\u8349'),
65
 
        ('http://xn--vl1a.com/%E8%8D%89', u'http://\u8349.com/\u8349'),
66
 
        ]
67
 
 
68
 
    try:
69
 
        codecs.getencoder('idna')
70
 
    except LookupError:
71
 
        # If there is no idna codec, these cases with
72
 
        # non-ascii-representable domain names should fail.
73
 
        should_raise = True
74
 
    else:
75
 
        should_raise = False
76
 
 
77
 
    for expected, case in non_ascii_domain_cases:
78
 
        try:
79
 
            actual = n(case)
80
 
        except UnicodeError:
81
 
            assert should_raise
82
 
        else:
83
 
            assert not should_raise and actual == expected, case
84
 
 
85
 
    assert n(None) is None
86
 
    assert n('') is None
87
 
    assert n('http://') is None
88
 
 
89
42
class AppendArgsTest(unittest.TestCase):
90
43
    def __init__(self, desc, args, expected):
91
44
        unittest.TestCase.__init__(self)
100
53
    def shortDescription(self):
101
54
        return self.desc
102
55
 
 
56
 
 
57
 
 
58
class TestSymbol(unittest.TestCase):
 
59
    def testCopyHash(self):
 
60
        import copy
 
61
        s = oidutil.Symbol("Foo")
 
62
        d = {s: 1}
 
63
        d_prime = copy.deepcopy(d)
 
64
        self.failUnless(s in d_prime, "%r isn't in %r" % (s, d_prime))
 
65
 
 
66
        t = oidutil.Symbol("Bar")
 
67
        self.failIfEqual(hash(s), hash(t))
 
68
 
 
69
 
103
70
def buildAppendTests():
104
71
    simple = 'http://www.example.com/'
105
72
    cases = [
185
152
    return unittest.TestSuite(tests)
186
153
 
187
154
def pyUnitTests():
188
 
    return buildAppendTests()
 
155
    some = buildAppendTests()
 
156
    some.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(TestSymbol))
 
157
    return some
189
158
 
190
159
def test_appendArgs():
191
160
    suite = buildAppendTests()
 
161
    suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(TestSymbol))
192
162
    runner = unittest.TextTestRunner()
193
163
    result = runner.run(suite)
194
164
    assert result.wasSuccessful()
199
169
 
200
170
def test(skipPyUnit=True):
201
171
    test_base64()
202
 
    test_normalizeUrl()
203
172
    if not skipPyUnit:
204
173
        test_appendArgs()
205
174