Esempio n. 1
0
File: test.py Progetto: sublee/etc
def etcd(request):
    mode = request.param
    if mode == 'etcd':
        etcd = etc.etcd(ETC_TEST_ETCD_URL)
    elif mode == 'mock':
        etcd = etc.etcd(mock=True)
    else:
        raise AssertionError
    result = etcd.get('/', recursive=True)
    for node in result.nodes:
        dir_ = isinstance(node, etc.Directory)
        etcd.delete(node.key, dir=dir_, recursive=True)
    return etcd
Esempio n. 2
0
File: test.py Progetto: sublee/etc
def test_chunked_encoding_error(spawn):
    server = socket.socket()
    server.bind(('', 0))
    server.listen(0)
    __, port = server.getsockname()
    def bad_web_server():
        header = '\r\n'.join([
            'HTTP/1.1 200 OK',
            'Content-Type: application/json',
            'X-Etcd-Cluster-Id: 42',
            'X-Etcd-Index: 42',
            'X-Raft-Index: 42',
            'X-Raft-Term: 42',
            'Transfer-Encoding: chunked'
        ]) + '\r\n\r\n'
        data = ('{"action":"set","node":{"key":"/etc","value":'
                '"ok","modifiedIndex":42,"createdIndex":42}}')
        # Bad response.
        conn, __ = server.accept()
        conn.send(header.encode())
        conn.close()
        # Good response.
        conn, __ = server.accept()
        response = header + '%x\r\n%s\r\n0\r\n\r\n' % (len(data), data)
        conn.send(response.encode())
        conn.close()
    spawn(bad_web_server)
    etcd = etc.etcd('http://127.0.0.1:%d' % port)
    r = etcd.wait('/etc')
    assert isinstance(r, etc.Set)
    assert r.modified_index == r.created_index == 42
Esempio n. 3
0
File: test.py Progetto: sublee/etc
def test_session(monkeypatch):
    etcd = etc.etcd(ETC_TEST_ETCD_URL)
    etcd.get('/')
    monkeypatch.setattr(socket.socket, 'connect', lambda *a, **k: 0 / 0)
    etcd.get('/')
    etcd.clear()
    with pytest.raises(ZeroDivisionError):
        etcd.get('/')
Esempio n. 4
0
File: test.py Progetto: sublee/etc
def test_default_address():
    assert etc.etcd().url == 'http://127.0.0.1:4001'
Esempio n. 5
0
File: test.py Progetto: sublee/etc
def test_etcd():
    e = etc.etcd()
    assert isinstance(e, etc.Client)