示例#1
0
def test_sync_ok(M_Conn):
    mock_conn = M_Conn("host", 123)
    mock_conn.read_line.side_effect = [f"OK {len(yaml_resp)}\r\n"]
    mock_conn.read_bytes.side_effect = [yaml_resp]
    C = Client("host", 123)
    body = C.stats()
    assert yaml_dict_rep == body
示例#2
0
def test_errors(M_Conn, method, cd_args, error_response):
    args = ()
    if cd_args:
        args = cd_args.split(",")
    mock_conn = M_Conn("host", 123)
    mock_conn.read_line.side_effect = [error_response]
    C = Client("host", 123)
    with pytest.raises(CommandError) as excinfo:
        getattr(C, method)(*args)
    assert excinfo.value.error_code == error_response.rstrip()
示例#3
0
def test_success(M_Conn, method, cd_args, response_line, response_body,
                 expected):
    args = ()
    if cd_args:
        args = cd_args.split(",")
    mock_conn = M_Conn("host", 123)
    mock_conn.read_line.side_effect = [response_line]
    mock_conn.read_bytes.side_effect = [response_body]
    C = Client("host", 123)
    resp = getattr(C, method)(*args)
    assert resp == expected
def test_end_to_end():
    C = Client("127.0.0.1", 11300)
    before = C.stats()
    for i in range(10):
        tube = f"tube-{i}"
        C.use(tube)
        for c in range(10):
            C.put(f"Msg-{i}-{c}")
        watching = C.watching()
        C.watch(tube)
        for w in [w for w in watching if not w == tube]:
            C.ignore(w)
        for c in range(10):
            body, j_id = C.reserve()
            assert body == f"Msg-{i}-{c}"
            C.delete(j_id)
    after = C.stats()
    assert after.get("total-jobs") == before.get("total-jobs") + 100
def test_connection_close():
    C = Client("127.0.0.1", 11300)
    before = C.stats().get("total-connections")
    C.disconnect()
    after = C.stats().get("total-connections")
    assert before < after
def test_connection_error():
    # Invalid IP Forces EAI_NONAME
    C = Client("999.0.999.0", 43594)
    with pytest.raises(BeanstalkdConnection):
        C.stats()
示例#7
0
def test_close(M_Conn):
    C = Client("Host", 123)
    C.disconnect()
    M_Conn.assert_called_with("Host", 123)
    M_Conn.return_value.close.assert_called_once()