Skip to content

Commit

Permalink
Add few missing kwargs to the handler invocation (used in docs)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Vasilyev committed May 27, 2019
1 parent 4f98bd5 commit 62a4a0b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions kopf/reactor/invocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 4 additions & 1 deletion tests/invocations/test_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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']

0 comments on commit 62a4a0b

Please sign in to comment.