Exemplo n.º 1
0
 def setUp(self):
     self.protocol = ChatProtocol()
     self.transport = StringTransportWithDisconnection()
     self.protocol.factory = ChatProtocolFactory()
     
     fl = os.open(ChatProtocolFactory.filename, os.O_CREAT |
                                                os.O_RDWR)
                                                 
     os.write(fl, 'hey ho\n')
     os.close(fl)
Exemplo n.º 2
0
class TestProtocol(TestCase):
    def setUp(self):
        self.protocol = ChatProtocol()
        self.transport = StringTransportWithDisconnection()
        self.protocol.factory = ChatProtocolFactory()
        
        fl = os.open(ChatProtocolFactory.filename, os.O_CREAT |
                                                   os.O_RDWR)
                                                    
        os.write(fl, 'hey ho\n')
        os.close(fl)

    def test_connect_disconnect(self):
        self.assertFalse(self.protocol in 
                                self.protocol.factory.clientProtocols)
        self.assertFalse(self.protocol in 
                                self.protocol.factory.activeUsers)
        
        self.protocol.makeConnection(self.transport)
        self.transport.protocol = self.protocol
        
        self.assertTrue(self.protocol in 
                                self.protocol.factory.clientProtocols)
        self.assertFalse(self.protocol in 
                                self.protocol.factory.activeUsers)
        
        self.protocol.lineReceived("CONNECT hey ho")
        self.assertTrue(self.protocol in 
                                self.protocol.factory.activeUsers)
        

        self.protocol.transport.loseConnection()
        self.assertFalse(self.protocol in 
                                self.protocol.factory.activeUsers)
        self.assertFalse(self.protocol in 
                                self.protocol.factory.clientProtocols)
Exemplo n.º 3
0
class TestProtocol(TestCase):
    def setUp(self):
        self.protocol = ChatProtocol()
        self.transport = StringTransportWithDisconnection()
        self.protocol.factory = ChatProtocolFactory()
        self.protocol.makeConnection(self.transport)
        self.transport.protocol = self.protocol
        fl = os.open(self.protocol.factory.filename, os.O_CREAT |
                                                   os.O_RDWR)
                                                    
        os.write(fl, 'hey ho\n')
        os.close(fl)
    
    def split_commands(self):
        return self.transport.value().splitlines()
        
    def assertCommands(self, args):
        commands = self.split_commands()
        cmd_list = [parsingCommand(cmd) for cmd in commands]
        arg_list = [parsingCommand(arg) for arg in args]
        for (cmd, arg) in zip(cmd_list, arg_list):
            self.assertEquals(arg[1], cmd[1])
            if arg[2]:
                self.assertEquals(arg[2], cmd[2])
        
    def test_connect_command(self):
        self.protocol.lineReceived("CONNECT hey ho")
        self.assertCommands(['OK', 'SERVICE', 'NAMES'])
       
    def test_new_command_error_incorrect_data(self):
        self.protocol.lineReceived("NEW gahhahjjkjsfkkfkk ho")
        self.assertCommands(["ERROR '%s'" % 
                             err_text['err_incorrect_data']])
       
    
    def test_new_command_error_usr_exist(self):
        self.protocol.lineReceived("NEW hey ho")
        self.assertCommands(["ERROR '%s'" % 
                              err_text['err_user_exist']])
    
    def test_msg_command(self):
        self.protocol.lineReceived("CONNECT hey ho")
        self.protocol.lineReceived("!hey MSG * 'message'")
        
        self.assertCommands(['OK', 'SERVICE', 'NAMES', 'MSG'])
        
    def test_nick_command(self):
        self.protocol.lineReceived("CONNECT hey ho")
        self.protocol.lineReceived("!hey NICK newnick")

        self.assertCommands(['OK', 'SERVICE', 'NAMES']*2)
    
    def tearDown(self):
        self.protocol.transport.loseConnection()