def test_on_delete_with_all_kwargs(mocker, optional, cause_factory): registry = GlobalRegistry() resource = Resource('group', 'version', 'plural') cause = cause_factory(resource=resource, reason=Reason.DELETE) mocker.patch('kopf.reactor.registries.match', return_value=True) when = lambda **_: False @kopf.on.delete('group', 'version', 'plural', id='id', timeout=123, registry=registry, optional=optional, labels={'somelabel': 'somevalue'}, annotations={'someanno': 'somevalue'}, when=when) def fn(**_): pass with pytest.deprecated_call(match=r"cease using the internal registries"): handlers = registry.get_cause_handlers(cause) assert len(handlers) == 1 assert handlers[0].fn is fn assert handlers[0].reason == Reason.DELETE assert handlers[0].field is None assert handlers[0].id == 'id' assert handlers[0].timeout == 123 assert handlers[0].labels == {'somelabel': 'somevalue'} assert handlers[0].annotations == {'someanno': 'somevalue'} assert handlers[0].when == when
def test_on_field_with_all_kwargs(mocker, cause_factory): registry = GlobalRegistry() resource = Resource('group', 'version', 'plural') old = {'field': {'subfield': 'old'}} new = {'field': {'subfield': 'new'}} cause = cause_factory(resource=resource, reason=Reason.UPDATE, old=old, new=new, body=new) mocker.patch('kopf.reactor.registries.match', return_value=True) when = lambda **_: False @kopf.on.field('group', 'version', 'plural', field='field.subfield', id='id', timeout=123, registry=registry, labels={'somelabel': 'somevalue'}, annotations={'someanno': 'somevalue'}, when=when) def fn(**_): pass with pytest.deprecated_call(match=r"cease using the internal registries"): handlers = registry.get_cause_handlers(cause) assert len(handlers) == 1 assert handlers[0].fn is fn assert handlers[0].reason is None assert handlers[0].field ==('field', 'subfield') assert handlers[0].id == 'id/field.subfield' assert handlers[0].timeout == 123 assert handlers[0].labels == {'somelabel': 'somevalue'} assert handlers[0].annotations == {'someanno': 'somevalue'} assert handlers[0].when == when
def test_on_create_with_all_kwargs(mocker): registry = GlobalRegistry() resource = Resource('group', 'version', 'plural') cause = mocker.MagicMock(resource=resource, reason=Reason.CREATE) mocker.patch('kopf.reactor.registries.match', return_value=True) @kopf.on.create('group', 'version', 'plural', id='id', timeout=123, registry=registry, labels={'somelabel': 'somevalue'}, annotations={'someanno': 'somevalue'}) def fn(**_): pass handlers = registry.get_cause_handlers(cause) assert len(handlers) == 1 assert handlers[0].fn is fn assert handlers[0].reason == Reason.CREATE assert handlers[0].field is None assert handlers[0].id == 'id' assert handlers[0].timeout == 123 assert handlers[0].labels == {'somelabel': 'somevalue'} assert handlers[0].annotations == {'someanno': 'somevalue'}
def test_on_update_with_all_kwargs(mocker): registry = GlobalRegistry() resource = Resource('group', 'version', 'plural') cause = mocker.MagicMock(resource=resource, reason=Reason.UPDATE) mocker.patch('kopf.reactor.registries.match', return_value=True) when = lambda **_: False @kopf.on.update('group', 'version', 'plural', id='id', timeout=123, registry=registry, labels={'somelabel': 'somevalue'}, annotations={'someanno': 'somevalue'}, when=when) def fn(**_): pass with pytest.deprecated_call( match=r"use OperatorRegistry.get_resource_changing_handlers\(\)"): handlers = registry.get_cause_handlers(cause) assert len(handlers) == 1 assert handlers[0].fn is fn assert handlers[0].reason == Reason.UPDATE assert handlers[0].field is None assert handlers[0].id == 'id' assert handlers[0].timeout == 123 assert handlers[0].labels == {'somelabel': 'somevalue'} assert handlers[0].annotations == {'someanno': 'somevalue'} assert handlers[0].when == when
def test_on_field_with_all_kwargs(mocker, cause_factory): registry = GlobalRegistry() resource = Resource('group', 'version', 'plural') diff = [('op', ('field', 'subfield'), 'old', 'new')] cause = cause_factory(resource=resource, reason=Reason.UPDATE, diff=diff) mocker.patch('kopf.reactor.registries.match', return_value=True) when = lambda **_: False @kopf.on.field('group', 'version', 'plural', 'field.subfield', id='id', timeout=123, registry=registry, labels={'somelabel': 'somevalue'}, annotations={'someanno': 'somevalue'}, when=when) def fn(**_): pass with pytest.deprecated_call( match=r"use OperatorRegistry.get_resource_changing_handlers\(\)"): handlers = registry.get_cause_handlers(cause) assert len(handlers) == 1 assert handlers[0].fn is fn assert handlers[0].reason is None assert handlers[0].field == ('field', 'subfield') assert handlers[0].id == 'id/field.subfield' assert handlers[0].timeout == 123 assert handlers[0].labels == {'somelabel': 'somevalue'} assert handlers[0].annotations == {'someanno': 'somevalue'} assert handlers[0].when == when
def test_on_field_with_all_kwargs(mocker): registry = GlobalRegistry() resource = Resource('group', 'version', 'plural') diff = [('op', ('field', 'subfield'), 'old', 'new')] cause = mocker.MagicMock(resource=resource, reason=Reason.UPDATE, diff=diff) mocker.patch('kopf.reactor.registries.match', return_value=True) @kopf.on.field('group', 'version', 'plural', 'field.subfield', id='id', timeout=123, registry=registry, labels={'somelabel': 'somevalue'}, annotations={'someanno': 'somevalue'}) def fn(**_): pass handlers = registry.get_cause_handlers(cause) assert len(handlers) == 1 assert handlers[0].fn is fn assert handlers[0].reason is None assert handlers[0].field == ('field', 'subfield') assert handlers[0].id == 'id/field.subfield' assert handlers[0].timeout == 123 assert handlers[0].labels == {'somelabel': 'somevalue'} assert handlers[0].annotations == {'someanno': 'somevalue'}
def test_global_registry_with_minimal_signature(mocker, resource): cause = mocker.Mock(resource=resource, event=None, diff=None) registry = GlobalRegistry() registry.register_cause_handler(resource.group, resource.version, resource.plural, some_fn) handlers = registry.get_cause_handlers(cause) assert len(handlers) == 1 assert handlers[0].fn is some_fn
def test_global_registry_via_list(mocker, resource): cause = mocker.Mock(resource=resource, event=None, diff=None) registry = GlobalRegistry() handlers = registry.get_cause_handlers(cause) assert isinstance(handlers, collections.abc.Iterable) assert isinstance(handlers, collections.abc.Container) assert isinstance(handlers, collections.abc.Collection) assert not handlers
def test_global_registry_with_minimal_signature(mocker, resource): cause = mocker.Mock(resource=resource, event=None, diff=None) registry = GlobalRegistry() with pytest.deprecated_call(match=r"use OperatorRegistry.register_resource_changing_handler\(\)"): registry.register_cause_handler(resource.group, resource.version, resource.plural, some_fn) with pytest.deprecated_call(match=r"use OperatorRegistry.get_resource_changing_handlers\(\)"): handlers = registry.get_cause_handlers(cause) assert len(handlers) == 1 assert handlers[0].fn is some_fn
def test_global_registry_via_list(mocker, resource): cause = mocker.Mock(resource=resource, event=None, diff=None) registry = GlobalRegistry() with pytest.deprecated_call(match=r"use OperatorRegistry.get_resource_changing_handlers\(\)"): handlers = registry.get_cause_handlers(cause) assert isinstance(handlers, collections.abc.Iterable) assert isinstance(handlers, collections.abc.Container) assert isinstance(handlers, collections.abc.Collection) assert not handlers
def test_global_registry_via_list(cause_factory): cause = cause_factory() registry = GlobalRegistry() with pytest.deprecated_call(match=r"cease using the internal registries"): handlers = registry.get_cause_handlers(cause) assert isinstance(handlers, collections.abc.Iterable) assert isinstance(handlers, collections.abc.Container) assert isinstance(handlers, collections.abc.Collection) assert not handlers
def test_global_registry_via_list(cause_factory): cause = cause_factory() registry = GlobalRegistry() with pytest.deprecated_call( match=r"use OperatorRegistry.get_resource_changing_handlers\(\)"): handlers = registry.get_cause_handlers(cause) assert isinstance(handlers, collections.abc.Iterable) assert isinstance(handlers, collections.abc.Container) assert isinstance(handlers, collections.abc.Collection) assert not handlers
def test_global_registry_with_minimal_signature(cause_factory, resource): cause = cause_factory() registry = GlobalRegistry() with pytest.deprecated_call(match=r"use @kopf.on"): registry.register_cause_handler(resource.group, resource.version, resource.plural, some_fn) with pytest.deprecated_call(match=r"cease using the internal registries"): handlers = registry.get_cause_handlers(cause) assert len(handlers) == 1 assert handlers[0].fn is some_fn