示例#1
0
class ConnectionOutTest(unittest.TestCase):
    def setUp(self):
        self.client = Client()
        self.cli = CLI(self.client)
        self.cli.timeout = 2
        self.cli._testing = True

        self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

        self.client.parser.parse('HOST: localhost')
        self.client.port = str(random.randint(9000, 12000))
        self.server.bind(('localhost', int(self.client.port)))
        self.server.listen(5)

        self.client.parser.parse('CONNECT: joe Cake Man')
        self.con, addr = self.server.accept()
        self.data = self.con.recv(1024)
        self.client.tcp.connected = True

    def test_client_connect_to_server(self):
        self.assertEquals(self.data, 'CONNECT: "joe" "Cake Man" {0}\r\n'.format(get_git_version()))

    def test_client_raises_exception_if_host_not_set(self):
        self.client.host = None
        self.assertRaises(Warning, self.client.connect, [None, None, 'sap saaap'])

    def test_da_ping_is_ponged(self):
        self.client.parser.parse('PING: 133337')
        self.data = self.con.recv(1024)
        self.assertEquals(self.data, 'PONG: 133337\r\n')

    def test_join_channel(self):
        self.client.parser.parse('JOIN: #Lobby')
        self.data = self.con.recv(1024)
        self.assertEquals(self.data, 'JOIN: #Lobby\r\n')

    def test_send_message(self):
        self.client.parser.parse('MSG #Lobby: WAZZAAAAAA?!')
        self.data = self.con.recv(1024)
        self.assertEquals(self.data, 'MSG #Lobby: WAZZAAAAAA?!\r\n')

    def test_send_talk(self):
        self.client.parser.parse('TALK John: Request')
        self.data = self.con.recv(1024)
        self.assertEquals(self.data, 'TALK John: Request\r\n')
        self.assertEquals(sys.stdout.getvalue().strip(), '[VoIP] Awaiting response from John...')

    def test_request_response_accept(self):
        self.cli.prompt_by_requester = 'John'
        voix.interface.cli.raw_input = lambda: 'y'
        self.cli.main_loop()
        self.data = self.con.recv(1024)
        self.assertEquals(self.data, 'TALK John: Accept\r\n')

    def tearDown(self):
        self.client.close()
        self.server.close()
示例#2
0
文件: main.py 项目: suhongrui/Voix
def main():
    if options.verbose:
        logging.basicConfig(
            level=logging.DEBUG,
            format=
            "%(levelname)s %(asctime)s %(funcName)s %(lineno)d %(message)s")

    client = Client()

    if options.cli:
        cli = CLI(client)
        cli.main_loop()
    else:
        app = wx.App()
        GUI(None, -1, 'Voix')
        app.MainLoop()
示例#3
0
文件: main.py 项目: Tehnix/Voix
def main():
    if options.verbose:
        logging.basicConfig(
            level=logging.DEBUG,
            format="%(levelname)s %(asctime)s %(funcName)s %(lineno)d %(message)s"
        )

    client = Client()

    if options.cli:
        cli = CLI(client)
        cli.main_loop()
    else:
        app = wx.App()
        GUI(None, -1, 'Voix')
        app.MainLoop()
示例#4
0
    def setUp(self):
        self.client = Client()
        self.cli = CLI(self.client)
        self.cli.timeout = 2
        self.cli._testing = True

        self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

        self.client.parser.parse('HOST: localhost')
        self.client.port = str(random.randint(9000, 12000))
        self.server.bind(('localhost', int(self.client.port)))
        self.server.listen(5)

        self.client.parser.parse('CONNECT: joe Cake Man')
        self.con, addr = self.server.accept()
        self.data = self.con.recv(1024)
        self.client.tcp.connected = True
示例#5
0
    def setUp(self):
        self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.client = Client()
        self.cli = CLI(self.client)
        self.client.port = str(random.randint(9000, 12000))
        self.server.bind(('localhost', int(self.client.port)))
        self.server.listen(5)
        self.client.tcp.connected = True

        self.client.nick = 'John'
        self.client.tcp.connect(('localhost', int(self.client.port)))
        self.con, addr = self.server.accept()
        self.client.tcp.send(bytes('CONNECT: John Cake Man 1.0.0\r\n'))
        self.data = self.con.recv(1024)
示例#6
0
    def setUp(self):
        self.client = Client()
        self.client.host = 'localhost'
        self.client.tcp.connected = True
        self.client.port = str(random.randint(9000, 12000))
        self.cli = CLI(self.client)
        self.cli.timeout = 2

        self.tcpsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.tcpsock.bind(('localhost', int(self.client.port)))
        self.tcpsock.listen(5)

        self.udpsock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        self.udpsock.bind(('localhost', int(self.client.port) + 1))

        self.client.tcp.connect(('localhost', int(self.client.port)))
        self.tcpcon, addr = self.tcpsock.accept()

        wf = wave.open('assets/audio_test/noise.wav')
        self.data = wf.readframes(1024)[:1024]