def test_get_exception():
    with mock.patch("async_etcd_client.etcd.Client") as MockClient:
        resp = MockResp()
        resp.key = "/test"
        with pytest.raises(etcd.EtcdKeyNotFound):
            ret_val = asyncio.Future()
            ret_val.set_exception(etcd.EtcdKeyNotFound)

            expected_output = "etcd.EtcdKeyNotFound: None"

            MockClient.return_value.read.return_value = ret_val
            async_client = AsyncEtcdClient(host, port)

            loop = asyncio.get_event_loop()
            loop.run_until_complete(async_client.get(resp.key))

        MockClient.assert_called_once_with(host, port)
        MockClient.return_value.read.assert_called_once_with(resp.key)
        MockClient.return_value.close.assert_called_once()
def test_get():
    with mock.patch("async_etcd_client.etcd.Client") as MockClient:
        resp = MockResp()
        resp.value = "testing"
        resp.key = "/test"

        ret_val = asyncio.Future()
        ret_val.set_result(resp)

        MockClient.return_value.read.return_value = ret_val
        async_client = AsyncEtcdClient(host, port)

        loop = asyncio.get_event_loop()
        assert (loop.run_until_complete(async_client.get(
            resp.key)) == resp.value)

        MockClient.assert_called_once_with(host, port)
        MockClient.return_value.read.assert_called_once_with(resp.key)
        MockClient.return_value.close.assert_called_once()
def test_get_prefix():
    with mock.patch("async_etcd_client.etcd.Client") as MockClient:
        resp = MockResp()
        resp.key = "/test"
        resp.value = "testing"
        prefix_resp = MockResp()
        prefix_resp.children.append(resp)
        expected_output = ["/test: testing"]

        ret_val = asyncio.Future()
        ret_val.set_result(prefix_resp)

        MockClient.return_value.read.return_value = ret_val
        async_client = AsyncEtcdClient(host, port)

        loop = asyncio.get_event_loop()
        assert (loop.run_until_complete(async_client.get(
            resp.key, True)) == expected_output)

        MockClient.assert_called_once_with(host, port)
        MockClient.return_value.read.assert_called_once_with(resp.key,
                                                             recursive=True,
                                                             sorted=True)
        MockClient.return_value.close.assert_called_once()