~vcs-imports/quotient/main

« back to all changes in this revision

Viewing changes to quotient/test/test_storcred.py

  • Committer: glyph
  • Date: 2003-10-26 23:44:25 UTC
  • Revision ID: Arch-1:unnamed@bazaar.ubuntu.com%series--4208--patch-749
whitespace

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
from os.path import join as opj
3
 
 
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
9
 
 
10
 
from quotient.items.powerup import IPowerStation
11
 
from quotient.storcred import StoreCredentialsChecker, StoreRealm, Avatar
12
 
from quotient.storq import Store
13
 
 
14
 
 
15
 
class IAvatarTest(Interface): pass
16
 
class AdapterTest(Adapter):
17
 
    __implements__ = IAvatarTest
18
 
 
19
 
registerAdapter(AdapterTest, Avatar, IAvatarTest)
20
 
 
21
 
USERNAME = "userXname"
22
 
PASSWORD = "passXword"
23
 
 
24
 
class LoginExampleAccess(unittest.TestCase):
25
 
 
26
 
    def setUp(self):
27
 
        self.pathToDB = self.mktemp()
28
 
        self.store = Store(opj(self.pathToDB, "db"), opj(self.pathToDB, "files"))
29
 
        def _():
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(_)
37
 
 
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]?
47