Browse files

Start of UI

  • Loading branch information...
1 parent f4ffa59 commit 924077adacf9b3dbd94610dc798dd2eb0074c8b8 @iffy committed Nov 17, 2011
Showing with 106 additions and 1 deletion.
  1. +6 −1 TODO
  2. +31 −0 camp/ui/line.py
  3. +69 −0 camp/ui/test/test_line.py
View
7 TODO
@@ -22,7 +22,6 @@ Activate(robot)
-
1. get user (from Store)
2. get avatar (from user)
3. insert avatar into World if not there yet
@@ -33,5 +32,11 @@ cli port
web port
insults port
+Authentication
+----------------
+ssh * - prior
+web cli - prior
+telnet cli - cli handles auth (for testing/debugging)
+
./startserver --web-port 1234 --telnet-cli 9087 --ssh-insults 1982 thestore.db
View
31 camp/ui/line.py
@@ -0,0 +1,31 @@
+"""
+Line-by-line protocols.
+"""
+
+import os
+
+from twisted.protocols import basic
+
+
+
+class LineProtocol(basic.LineReceiver, basic.StatefulStringProtocol):
+
+ user = None
+ avatar = None
+ delimiter = os.linesep
+ state = 'username'
+
+
+ def lineReceived(self, line):
+ self.stringReceived(line)
+
+
+ def proto_username(self, username):
+ self.username = username
+ return 'password'
+
+
+
+class LineFactory:
+
+ protocol = LineProtocol
View
69 camp/ui/test/test_line.py
@@ -0,0 +1,69 @@
+from twisted.trial.unittest import TestCase
+from twisted.protocols import basic
+from twisted.test.proto_helpers import StringTransport
+
+import os
+
+from camp.ui.line import LineProtocol, LineFactory
+
+
+
+class LineFactoryTest(TestCase):
+
+
+ def test_protocol(self):
+ """
+ Should be LineProtocol by default
+ """
+ self.assertEqual(LineFactory.protocol, LineProtocol)
+
+
+
+class LineProtocolTest(TestCase):
+
+
+ def test_LineReceiver(self):
+ self.assertTrue(issubclass(LineProtocol, basic.LineReceiver))
+ self.assertTrue(issubclass(LineProtocol, basic.StatefulStringProtocol))
+
+
+ def test_attrs(self):
+ """
+ Should have these attributes
+ """
+ p = LineProtocol()
+ self.assertEqual(p.user, None)
+ self.assertEqual(p.avatar, None)
+ self.assertEqual(p.state, 'username')
+ self.assertEqual(p.delimiter, os.linesep)
+
+
+ def test_lineReceived(self):
+ """
+ Should call stringReceived
+ """
+ p = LineProtocol()
+ called = []
+ p.stringReceived = called.append
+
+ p.lineReceived('foo')
+ self.assertEqual(called, ['foo'])
+
+
+ def test_init(self):
+ """
+ should get the username, then try for password
+ """
+ p = LineProtocol()
+ t = StringTransport()
+ p.transport = t
+
+ r = p.proto_username('foo')
+ self.assertEqual(p.username, 'foo')
+ self.assertEqual(r, 'password')
+
+
+
+
+
+

0 comments on commit 924077a

Please sign in to comment.