def test_instantiate_proto(config) -> None: proto = SlskProtoThread( ui_callback=Mock(), queue=Mock(), bindip='', port=None, config=config, eventprocessor=Mock() ) proto.server_connect() proto.abort()
def test_server_conn(config, monkeypatch) -> None: mock_socket = monkeypatch_socket(monkeypatch, LOGIN_DATAFILE) monkeypatch_select(monkeypatch) proto = SlskProtoThread(ui_callback=Mock(), queue=Queue(0), bindip='', port=None, config=config, eventprocessor=Mock()) proto._queue.put(ServerConn()) sleep(SLSKPROTO_RUN_TIME) proto.abort() if hasattr(socket, 'TCP_KEEPIDLE'): assert mock_socket.setsockopt.call_count == 5 elif hasattr(socket, 'TCP_KEEPALIVE'): assert mock_socket.setsockopt.call_count == 3 elif hasattr(socket, 'SIO_KEEPALIVE_VALS'): assert mock_socket.ioctl.call_count == 1 assert mock_socket.setsockopt.call_count == 2 assert mock_socket.setblocking.call_count == 2 assert mock_socket.bind.call_count == 1 assert mock_socket.connect_ex.call_count == 1 assert mock_socket.listen.call_count == 1 sleep(SLSKPROTO_RUN_TIME) assert mock_socket.close.call_count == 1
def test_server_conn(self): queue = deque() proto = SlskProtoThread( core_callback=Mock(), queue=queue, interface='', bindip='', port=None, port_range=(1, 65535), network_filter=None, eventprocessor=Mock() ) with patch('socket.socket') as mock_socket: mock_socket.set_data(LOGIN_DATAFILE) proto.server_connect() queue.append(ServerConn(addr=('0.0.0.0', 0))) sleep(SLSKPROTO_RUN_TIME) if hasattr(socket, 'TCP_KEEPIDLE'): self.assertEqual(proto.server_socket.setsockopt.call_count, 4) elif hasattr(socket, 'TCP_KEEPALIVE'): self.assertEqual(proto.server_socket.setsockopt.call_count, 3) elif hasattr(socket, 'SIO_KEEPALIVE_VALS'): self.assertEqual(proto.server_socket.ioctl.call_count, 1) self.assertEqual(proto.server_socket.setsockopt.call_count, 1) self.assertEqual(proto.server_socket.setblocking.call_count, 2) self.assertEqual(proto.server_socket.connect_ex.call_count, 1) proto.abort() self.assertIsNone(proto.server_socket)
def test_instantiate_proto() -> None: proto = SlskProtoThread(ui_callback=Mock(), queue=deque(), bindip='', port=None, port_range=(1, 2), network_filter=None, eventprocessor=Mock()) proto.server_connect() proto.abort()
def test_login(config, monkeypatch) -> None: monkeypatch_select(monkeypatch) proto = SlskProtoThread(ui_callback=Mock(), queue=Queue(0), bindip='', port=None, config=config, eventprocessor=Mock()) proto._queue.put(ServerConn()) sleep(SLSKPROTO_RUN_TIME / 2) proto._queue.put(Login('username', 'password', 157)) proto._queue.put(SetWaitPort(1)) sleep(SLSKPROTO_RUN_TIME) proto.abort() pytest.skip('Login succeeded, actual test TBD')
def test_login(): queue = deque() proto = SlskProtoThread( core_callback=Mock(), queue=queue, interface='', bindip='', port=None, port_range=(1, 65535), network_filter=None, eventprocessor=Mock() ) proto.server_connect() queue.append(ServerConn(addr=('0.0.0.0', 0))) sleep(SLSKPROTO_RUN_TIME / 2) queue.append(Login('username', 'password', 160, 1)) queue.append(SetWaitPort(1)) sleep(SLSKPROTO_RUN_TIME) proto.abort()
def test_login(monkeypatch) -> None: monkeypatch_select(monkeypatch) proto = SlskProtoThread(ui_callback=Mock(), queue=deque(), bindip='', port=None, port_range=(1, 2), network_filter=None, eventprocessor=Mock()) proto.server_connect() proto._queue.append(ServerConn()) sleep(SLSKPROTO_RUN_TIME / 2) proto._queue.append(Login('username', 'password', 157)) proto._queue.append(SetWaitPort(1)) sleep(SLSKPROTO_RUN_TIME) proto.abort() pytest.skip('Login succeeded, actual test TBD')