Parent: [129dbf] (diff)

Child: [588145] (diff)

Download this file

test_openid.py    65 lines (58 with data), 2.2 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# -*- coding: utf-8 -*-
"""
Model tests for openid_model
"""
import time
import mock
from pylons import c, g, request
from webob import Request
from openid.association import Association
from ming.orm.ormsession import ThreadLocalORMSession
from allura.lib.app_globals import Globals
from allura import model as M
from allura.lib import helpers as h
def setUp():
g._push_object(Globals())
c._push_object(mock.Mock())
request._push_object(Request.blank('/'))
ThreadLocalORMSession.close_all()
M.EmailAddress.query.remove({})
M.OpenIdNonce.query.remove({})
M.OpenIdAssociation.query.remove({})
#conn = M.main_doc_session.bind.conn
def test_oid_model():
oid = M.OpenIdAssociation(_id='http://example.com')
assoc = mock.Mock()
assoc.handle = 'foo'
assoc.serialize = lambda:'bar'
assoc.getExpiresIn = lambda:0
with h.push_config(Association,
deserialize=staticmethod(lambda v:assoc)):
oid.set_assoc(assoc)
assert assoc == oid.get_assoc('foo')
oid.set_assoc(assoc)
oid.remove_assoc('foo')
assert oid.get_assoc('foo') is None
oid.set_assoc(assoc)
assert oid.get_assoc('foo') is not None
oid.cleanup_assocs()
assert oid.get_assoc('foo') is None
def test_oid_store():
assoc = mock.Mock()
assoc.handle = 'foo'
assoc.serialize = lambda:'bar'
assoc.getExpiresIn = lambda:0
store = M.OpenIdStore()
with h.push_config(Association,
deserialize=staticmethod(lambda v:assoc)):
store.storeAssociation('http://example.com', assoc)
assert assoc == store.getAssociation('http://example.com', 'foo')
assert assoc == store.getAssociation('http://example.com')
store.removeAssociation('http://example.com', 'foo')
t0 = time.time()
assert store.useNonce('http://www.example.com', t0, 'abcd')
ThreadLocalORMSession.flush_all()
assert not store.useNonce('http://www.example.com', t0, 'abcd')
assert not store.useNonce('http://www.example.com', t0-1e9, 'abcd')
assert store.getAssociation('http://example.com') is None
store.cleanupNonces()