def test_ls_non_existing(): with mock.patch("async_etcd_client.etcd.Client") as MockClient: resp = MockResp() resp.key = "/test" resp.value = "testing" 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.ls(resp.key)) 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()
def test_ls_existing(): 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.ls( resp.key)) == 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()