~divmod-dev/divmod.org/trunk

« back to all changes in this revision

Viewing changes to Imaginary/imaginary/test/test_wiring.py

  • Committer: Jean-Paul Calderone
  • Date: 2014-06-29 20:33:04 UTC
  • mfrom: (2749.1.1 remove-epsilon-1325289)
  • Revision ID: exarkun@twistedmatrix.com-20140629203304-gdkmbwl1suei4m97
mergeĀ lp:~exarkun/divmod.org/remove-epsilon-1325289

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
"""
3
 
Tests for L{imaginary.wiring}
4
 
 
5
 
These tests are not particularly good at the moment.  They are, however, a
6
 
minor step up from nothing.
7
 
"""
8
 
 
9
 
from zope.interface.verify import verifyObject
10
 
 
11
 
from twisted.trial.unittest import TestCase
12
 
from twisted.python.filepath import FilePath
13
 
 
14
 
from axiom.store import Store
15
 
from axiom.dependency import installOn
16
 
from axiom.userbase import LoginSystem, getAccountNames
17
 
 
18
 
from xmantissa.ixmantissa import ITerminalServerFactory
19
 
from xmantissa.offering import installOffering
20
 
from xmantissa.terminal import _AuthenticatedShellViewer
21
 
from axiom.plugins.mantissacmd import Mantissa
22
 
 
23
 
from imaginary.world import ImaginaryWorld
24
 
from imaginary.wiring.textserver import ImaginaryApp
25
 
from xmantissa.plugins.imaginaryoff import imaginaryOffering
26
 
 
27
 
 
28
 
class ImaginaryAppTests(TestCase):
29
 
    """
30
 
    Tests for L{ImaginaryApp}, which provides access to Imaginary via
31
 
    L{ShellServer}, the top-level Mantissa SSH handler.
32
 
    """
33
 
    def test_interface(self):
34
 
        """
35
 
        L{ImaginaryApp} implements L{ITerminalServerFactory}
36
 
        """
37
 
        self.assertTrue(verifyObject(ITerminalServerFactory, ImaginaryApp()))
38
 
 
39
 
 
40
 
    def test_powerup(self):
41
 
        """
42
 
        L{installOn} powers up the target for L{ITerminalServerFactory} with
43
 
        L{ImaginaryApp}.
44
 
        """
45
 
        store = Store()
46
 
        app = ImaginaryApp(store=store)
47
 
        installOn(app, store)
48
 
        self.assertIdentical(ITerminalServerFactory(store), app)
49
 
 
50
 
 
51
 
    def test_buildTerminalProtocol(self):
52
 
        """
53
 
        L{ImaginaryApp.buildTerminalProtocol} returns a
54
 
        L{CharacterSelectionTextServer} instance with a role representing the
55
 
        store it is in, a reference to the L{ImaginaryWorld} installed on the
56
 
        Imaginary application store, and a list of L{Thing} items shared to the
57
 
        role.
58
 
        """
59
 
        # XXX This is too many stores for a unit test to need to create.
60
 
        siteStore = Store(filesdir=FilePath(self.mktemp()))
61
 
        Mantissa().installSite(siteStore, u'example.com', u'', False)
62
 
        installOffering(siteStore, imaginaryOffering, {})
63
 
        login = siteStore.findUnique(LoginSystem)
64
 
        account = login.addAccount(u'alice', u'example.com', u'password')
65
 
        userStore = account.avatars.open()
66
 
 
67
 
        app = ImaginaryApp(store=userStore)
68
 
        installOn(app, userStore)
69
 
 
70
 
        imaginary = login.accountByAddress(u'Imaginary', None).avatars.open()
71
 
        world = imaginary.findUnique(ImaginaryWorld)
72
 
 
73
 
        # Alice connects to her own ImaginaryApp (all that is possible at the
74
 
        # moment).
75
 
        viewer = _AuthenticatedShellViewer(getAccountNames(userStore))
76
 
        proto = app.buildTerminalProtocol(viewer)
77
 
        self.assertIdentical(proto.world, world)
78
 
        self.assertEqual(proto.role.externalID, u'alice@example.com')
79
 
        self.assertEqual(proto.choices, [])