3
Tests for L{imaginary.wiring}
5
These tests are not particularly good at the moment. They are, however, a
6
minor step up from nothing.
9
from zope.interface.verify import verifyObject
11
from twisted.trial.unittest import TestCase
12
from twisted.python.filepath import FilePath
14
from axiom.store import Store
15
from axiom.dependency import installOn
16
from axiom.userbase import LoginSystem, getAccountNames
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
23
from imaginary.world import ImaginaryWorld
24
from imaginary.wiring.textserver import ImaginaryApp
25
from xmantissa.plugins.imaginaryoff import imaginaryOffering
28
class ImaginaryAppTests(TestCase):
30
Tests for L{ImaginaryApp}, which provides access to Imaginary via
31
L{ShellServer}, the top-level Mantissa SSH handler.
33
def test_interface(self):
35
L{ImaginaryApp} implements L{ITerminalServerFactory}
37
self.assertTrue(verifyObject(ITerminalServerFactory, ImaginaryApp()))
40
def test_powerup(self):
42
L{installOn} powers up the target for L{ITerminalServerFactory} with
46
app = ImaginaryApp(store=store)
48
self.assertIdentical(ITerminalServerFactory(store), app)
51
def test_buildTerminalProtocol(self):
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
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()
67
app = ImaginaryApp(store=userStore)
68
installOn(app, userStore)
70
imaginary = login.accountByAddress(u'Imaginary', None).avatars.open()
71
world = imaginary.findUnique(ImaginaryWorld)
73
# Alice connects to her own ImaginaryApp (all that is possible at the
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, [])