Esempio n. 1
0
    def test_receive_nothing_to_receive(self):
        with patch('socket.socket') as socket_socket_mock:
            with patch('select.select') as select_select_mock:
                socket_obj_mock = Mock()
                socket_socket_mock.return_value = socket_obj_mock

                select_select_mock.return_value = ([],[],[])
                
                sC = SocketClient()
                data = sC.Receive(1.5)
                del sC

                select_select_mock.assert_called_with([socket_obj_mock],[],[],1.5)
                assert not socket_obj_mock.recv.called
                assert data == ""
Esempio n. 2
0
    def test_receive(self):
        with patch('socket.socket') as socket_socket_mock:
            with patch('select.select') as select_select_mock:
                socket_obj_mock = Mock()
                socket_obj_mock.recv.return_value = b"ABCD"
                socket_socket_mock.return_value = socket_obj_mock

                select_select_mock.return_value = ([socket_obj_mock],[],[])
                
                sC = SocketClient()
                data = sC.Receive(1.5)
                del sC

                select_select_mock.assert_called_with([socket_obj_mock],[],[],1.5)
                socket_obj_mock.recv.assert_called_with(1024)
                assert data == b"ABCD"
import sys
from SocketClient import SocketClient
from CheckInput import CheckInput
from GaduGaduClient import GaduGaduClient
server_ip_address = "127.0.0.1"
if len(sys.argv) >= 2:
    server_ip_address = sys.argv[1]

client = SocketClient(server_ip_address)
ggClient = GaduGaduClient(client)
print("Enter 'exit' to close client")
nick = input("Enter your nick: ")
ggClient.Login(nick)
print("You can chat with your friends")
while True:
    msg = CheckInput()
    if msg == 'exit':
        break
    if "" != msg:
        ggClient.SendMsg(msg)
    data = client.Receive()
    if "" != data:
        print (data.decode())