class ConnectionInTest(unittest.TestCase): 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) def test_receive_message_author_chan(self): self.con.send(bytes('MSG Tehnix #Lobby: <(^.^<)\r\n')) self.client.tcp.handle.start() time.sleep(1) self.assertEquals(sys.stdout.getvalue().strip(), '[#Lobby] Tehnix: <(^.^<)') def test_receive_message_author_recipient(self): self.con.send(bytes('MSG Tehnix JLow: <(^.^<)\r\n')) self.client.tcp.handle.start() time.sleep(1) self.assertEquals(sys.stdout.getvalue().strip(), '[PM: JLow] Tehnix: <(^.^<)') def tearDown(self): self.client.close() self.server.close()
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()
class ConnectionUDPTest(unittest.TestCase): 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] def test_stream_opened(self): self.client.udp.open_stream = lambda: self.assertTrue(True) self.client.parser.parse('TALK John: Accept') def test_stream_closed(self): self.client.udp.close_stream = lambda: self.assertTrue(True) self.client.parser.parse('TALK John: End') def test_udp_stream_server_to_client(self): self.client.parser.parse('TALK Dean John: Accept') self.udpsock.sendto(self.data, (self.client.host, self.client.udp.port)) self.client.udp.output.write = lambda d: self.assertEquals( self.data, d) self.client.udp.in_handle.start() time.sleep(1) def test_udp_stream_client_to_server(self): self.client.parser.parse('TALK Sam: Accept') self.client.udp.input.read = lambda x: self.data self.client.udp.out_handle.start() time.sleep(1) data, addr = self.udpsock.recvfrom(1024) self.assertEquals(self.data, data) def tearDown(self): self.client.close() self.tcpsock.close()
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)
class ConnectionUDPTest(unittest.TestCase): 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] def test_stream_opened(self): self.client.udp.open_stream = lambda: self.assertTrue(True) self.client.parser.parse('TALK John: Accept') def test_stream_closed(self): self.client.udp.close_stream = lambda: self.assertTrue(True) self.client.parser.parse('TALK John: End') def test_udp_stream_server_to_client(self): self.client.parser.parse('TALK Dean John: Accept') self.udpsock.sendto(self.data, (self.client.host, self.client.udp.port)) self.client.udp.output.write = lambda d: self.assertEquals(self.data, d) self.client.udp.in_handle.start() time.sleep(1) def test_udp_stream_client_to_server(self): self.client.parser.parse('TALK Sam: Accept') self.client.udp.input.read = lambda x: self.data self.client.udp.out_handle.start() time.sleep(1) data, addr = self.udpsock.recvfrom(1024) self.assertEquals(self.data, data) def tearDown(self): self.client.close() self.tcpsock.close()
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 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]
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()
def setUp(self): self.client = Client() self.parser = Parser(self.client) self.mock_parser = mox.Mox()