2
from os.path import join as opj
4
from twisted.trial import unittest
5
from twisted.cred.portal import Portal, IRealm
6
from twisted.cred.checkers import ICredentialsChecker
7
from twisted.cred.credentials import UsernamePassword
8
from twisted.python.components import Interface, Adapter, registerAdapter
10
from quotient.items.powerup import IPowerStation
11
from quotient.storcred import StoreCredentialsChecker, StoreRealm, Avatar
12
from quotient.storq import Store
15
class IAvatarTest(Interface): pass
16
class AdapterTest(Adapter):
17
__implements__ = IAvatarTest
19
registerAdapter(AdapterTest, Avatar, IAvatarTest)
21
USERNAME = "userXname"
22
PASSWORD = "passXword"
24
class LoginExampleAccess(unittest.TestCase):
27
self.pathToDB = self.mktemp()
28
self.store = Store(opj(self.pathToDB, "db"), opj(self.pathToDB, "files"))
30
IPowerStation(self.store).installPowerup(StoreRealm)
31
icc = ICredentialsChecker(self.store)
32
icc.addDomain("divmod.org")
33
self.avatar = Avatar(self.store, name=USERNAME)
34
self.avatar.setInsecurePassword(PASSWORD)
35
icc.addAvatarToDomain(self.avatar, "divmod.org")
36
self.store.transact(_)
38
def testDefaultLogin(self):
39
p = Portal(IRealm(self.store))
40
p.registerChecker(ICredentialsChecker(self.store))
41
r = unittest.deferredResult(p.login(UsernamePassword(
42
USERNAME, PASSWORD), None, IAvatarTest))
43
self.assertEquals(len(r), 3)
44
self.assertEquals(r[0], IAvatarTest)
45
self.assertEquals(r[1], IAvatarTest(self.avatar))
46
# Who cares about r[2]?