예제 #1
0
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
예제 #2
0
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')
예제 #3
0
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')