1. Mike Steder
  2. noirchat

Commits

Mike Steder  committed e90b09a Merge

Merged in changes to PostOffice, replaced polling loop with event driven queue.

  • Participants
  • Parent commits 0112592, c48634c
  • Branches default

Comments (0)

Files changed (10)

File deps/mock-0.6.0.zip

Binary file added.

File deps/unittest2-0.3.0.tar.gz

Binary file added.

File noir/commands.py

View file
     if len(message.parameters) >= 1:
         newnick = message.parameters[0]
         if newnick not in db.nicks:
-            db.nicks.add(newnick)
-            db.nickToUserId[newnick] = userId
-            user.nick = newnick
-            po.send([userId], ":%s NICK %s"%(user.nick, user.nick))
+            if not len(newnick) > irc.MAX_NICK_LENGTH:
+                db.nicks.add(newnick)
+                db.nickToUserId[newnick] = userId
+                user.nick = newnick
+                po.send([userId], ":%s NICK %s"%(user.nick, user.nick))
+            else:
+                po.send([userId], irc.ERR_ERRONEUSNICKNAME)
         else:
             po.send([userId], irc.ERR_NICKNAMEINUSE)
     else:

File noir/irc.py

View file
 
 """
 
+MAX_NICK_LENGTH = 9
+
 _REPLY_CODES = [
     (1, "RPL_WELCOME", "Welcome to the Internet Relay Network <nick>!<user>@<host>"),
     (2,	"RPL_YOURHOST", "Your host is <servername>, running version <ver>"),

File noir/test/commands/__init__.py

View file
+#__init__.py

File noir/test/commands/test_channel.py

View file
+"""
+"""
+
+
+import unittest2
+
+from noir import commands
+from noir import irc
+from noir import messages
+from noir import models
+from noir.test import mocks
+
+
+class TestJOIN(unittest2.TestCase):
+    """at least 9 test cases are in order
+    as JOIN can return any of 9 RPL codes:
+
+    ERR_NEEDMOREPARAMS
+    ERR_BANNEDFROMCHAN
+    ERR_INVITEONLYCHAN
+    ERR_BADCHANNELKEY
+    ERR_CHANNELISFULL
+    ERR_BADCHANMASK
+    ERR_NOSUCHCHANNEL
+    ERR_TOOMANYCHANNELS
+    RPL_TOPIC
+
+    There are also a number of syntaxes and optional args:
+
+    JOIN #foobar         ; join channel #foobar
+    JOIN &foo fubar      ; join channel &foo using key "fubar"
+    JOIN #foo,&bar fubar        ; join channel #foo using key "fubar"
+                                ; and &bar using no key
+    JOIN #foo,#bar fubar,foobar ; Join channel #foo using key "fubar"
+                                ; and channel #bar using key "foobar"
+    JOIN #foo,#bar       ; join channels #foo and #bar.
+    :Wiz JOIN #Twillight_zone   ; JOIN Message from Wiz
+
+    """
+    
+    def setUp(self):
+        self.command = commands.COMMANDS["JOIN"]

File noir/test/commands/test_registration.py

View file
+"""
+"""
+
+
+import unittest2
+
+
+from noir import commands
+from noir import irc
+from noir import messages
+from noir import models
+from noir.test import mocks
+
+
+class TestNICK(unittest2.TestCase):
+    def setUp(self):
+        self.db = models.DB()
+        socket, address = "Fake", "127.0.0.1"
+        self.u = self.db.addUser(socket, address)
+        self.po = mocks.MockPo()
+        self.command = commands.COMMANDS["NICK"]
+
+    def test_set_nick_wo_prefix(self):
+        """Normal nick message without user prefix
+
+        So we're initially setting the users nick as part
+        of the registration process
+
+        """
+        m = messages.Message(None, "NICK", ["bingo"])
+        self.command(self.db, self.po, self.u, m)
+        self.po.send.assert_called_with([self.u], ":bingo NICK bingo")
+
+    def test_set_nick_w_hopcount(self):
+        """Hopcount is used to tell servers about nicknames on
+        other servers.  The server will ignore the hopcount
+        parameter when sent by a client
+        
+        This assumes the user is a client, so their nick
+        should be set and the hopcount should be silently
+        ignored.
+        
+        """
+        
+        m = messages.Message(None, "NICK", ["bingo", "1"])
+        self.command(self.db, self.po, self.u, m)
+        self.po.send.assert_called_with([self.u], ":bingo NICK bingo")
+
+    def test_set_nick_w_prefix(self):
+        """A prefix :bill was sent bug the new prefix is
+        returned.
+
+        """
+        m = messages.Message(":bill", "NICK", ["bingo"])
+        self.command(self.db, self.po, self.u, m)
+        self.po.send.assert_called_with([self.u], ":bingo NICK bingo")
+
+    def test_change_nick(self):
+        """Here we run the nick command twice, once to register
+        and again to change to a new nick."""
+        m = messages.Message(None, "NICK", ["bingo"])
+        self.command(self.db, self.po, self.u, m)
+        self.po.send.assert_called_with([self.u], ":bingo NICK bingo")
+        m = messages.Message(":bingo", "NICK", ["Mike"])
+        self.command(self.db, self.po, self.u, m)
+        self.po.send.assert_called_with([self.u], ":Mike NICK Mike")
+
+    def test_attempt_change_nick_inuse(self):
+        m = messages.Message(None, "NICK", ["bingo"])
+        self.command(self.db, self.po, self.u, m)
+        self.po.send.assert_called_with([self.u], ":bingo NICK bingo")
+        m = messages.Message(":bingo", "NICK", ["bingo"])
+        self.command(self.db, self.po, self.u, m)
+        self.po.send.assert_called_with([self.u], irc.ERR_NICKNAMEINUSE)
+
+    def test_nonicknamegiven(self):
+        m = messages.Message(None, "NICK", [])
+        self.command(self.db, self.po, self.u, m)
+        self.po.send.assert_called_with([self.u], irc.ERR_NONICKNAMEGIVEN)
+
+    def test_erroneousNick_tooLong(self):
+        m = messages.Message(None, "NICK", ["thisisalongnickMaxIs9Chars"])
+        self.command(self.db, self.po, self.u, m)
+        self.po.send.assert_called_with([self.u], irc.ERR_ERRONEUSNICKNAME)
+
+

File noir/test/mocks.py

View file
+"""
+"""
+
+import mock
+
+from noir import models
+from noir import server
+
+MockDb = mock.Mock(spec=models.DB)
+MockPo = mock.Mock(spec=server.PostOffice)

File noir/test/test_parser.py

View file
 """
 """
-import unittest
+import unittest2
 
 from noir import parser
 
 
-class TestParser(unittest.TestCase):
+class TestParser(unittest2.TestCase):
     def test_nick(self):
         message = "NICK steder\r\n"
         m = parser.parse(message)

File noir/test/test_parser.pyc

Binary file removed.