Skip to content
This repository has been archived by the owner on Sep 14, 2020. It is now read-only.

Commit

Permalink
Merge pull request #80 from nolar/79-absent-handler-kwargs
Browse files Browse the repository at this point in the history
Add few missing kwargs to the handler invocation (used in docs)
  • Loading branch information
Sergey Vasilyev authored May 28, 2019
2 parents 4f98bd5 + 62a4a0b commit ff34f5f
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 ff34f5f

Please sign in to comment.