def test_watch_stop_iter(client: lightkube.Client): respx.get("https://localhost:9443/api/v1/nodes?watch=true").respond(content=make_watch_list()) respx.get("https://localhost:9443/api/v1/nodes?watch=true&resourceVersion=1").respond(status_code=404) i = None for i, _ in enumerate(client.watch(Node, on_error=types.on_error_raise)): break assert i == 0
def test_watch_on_error(client: lightkube.Client): respx.get("https://localhost:9443/api/v1/nodes?watch=true").respond(content=make_watch_list()) respx.get("https://localhost:9443/api/v1/nodes?watch=true&resourceVersion=1").respond(status_code=404) i = None for i, (op, node) in enumerate(client.watch(Node, on_error=types.on_error_stop)): assert node.metadata.name == f'p{i}' assert op == 'ADDED' assert i == 9
def test_watch(client: lightkube.Client): respx.get("https://localhost:9443/api/v1/nodes?watch=true").respond(content=make_watch_list()) respx.get("https://localhost:9443/api/v1/nodes?watch=true&resourceVersion=1").respond(status_code=404) i = None with pytest.raises(httpx.HTTPError) as exi: for i, (op, node) in enumerate(client.watch(Node)): assert node.metadata.name == f'p{i}' assert op == 'ADDED' assert i == 9 assert exi.value.response.status_code == 404