From 62a4a0beef0ee8967d0dabd97759e0b1bc425f89 Mon Sep 17 00:00:00 2001 From: Sergey Vasilyev Date: Mon, 27 May 2019 23:05:00 +0200 Subject: [PATCH] Add few missing kwargs to the handler invocation (used in docs) --- kopf/reactor/invocation.py | 3 +++ tests/invocations/test_callbacks.py | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/kopf/reactor/invocation.py b/kopf/reactor/invocation.py index 446e8f0a..ec8b9d86 100644 --- a/kopf/reactor/invocation.py +++ b/kopf/reactor/invocation.py @@ -49,6 +49,9 @@ async def invoke( spec=cause.body.setdefault('spec', {}), meta=cause.body.setdefault('metadata', {}), status=cause.body.setdefault('status', {}), + uid=cause.body.get('metadata', {}).get('uid'), + name=cause.body.get('metadata', {}).get('name'), + namespace=cause.body.get('metadata', {}).get('namespace'), ) if is_async_fn(fn): diff --git a/tests/invocations/test_callbacks.py b/tests/invocations/test_callbacks.py index b0bc2573..cc1b4679 100644 --- a/tests/invocations/test_callbacks.py +++ b/tests/invocations/test_callbacks.py @@ -163,7 +163,7 @@ async def test_explicit_args_passed_properly(fn): @fns async def test_special_kwargs_added(fn): fn = MagicMock(fn) - cause = MagicMock(body={}) + cause = MagicMock(body={'metadata': {'uid': 'uid', 'name': 'name', 'namespace': 'ns'}}) await invoke(fn, cause=cause) assert fn.called @@ -181,3 +181,6 @@ async def test_special_kwargs_added(fn): assert fn.call_args[1]['new'] is cause.new assert fn.call_args[1]['patch'] is cause.patch assert fn.call_args[1]['logger'] is cause.logger + assert fn.call_args[1]['uid'] is cause.body['metadata']['uid'] + assert fn.call_args[1]['name'] is cause.body['metadata']['name'] + assert fn.call_args[1]['namespace'] is cause.body['metadata']['namespace']