Exemplo n.º 1
0
def test_simple_registry_with_minimal_signature(mocker):
    cause = mocker.Mock(event=None, diff=None)

    registry = ResourceRegistry()
    registry.register(some_fn)
    handlers = registry.get_resource_changing_handlers(cause)

    assert len(handlers) == 1
    assert handlers[0].fn is some_fn
Exemplo n.º 2
0
def test_simple_registry_via_list(mocker):
    cause = mocker.Mock(event=None, diff=None)

    registry = ResourceRegistry()
    handlers = registry.get_resource_changing_handlers(cause)

    assert isinstance(handlers, collections.abc.Iterable)
    assert isinstance(handlers, collections.abc.Container)
    assert isinstance(handlers, collections.abc.Collection)
    assert not handlers
Exemplo n.º 3
0
def test_with_prefix(mocker):
    get_fn_id = mocker.patch('kopf.reactor.registries.get_callable_id', return_value='some-id')

    registry = ResourceRegistry(prefix='some-prefix')
    registry.register(some_fn)
    handlers = registry.get_resource_changing_handlers(mocker.MagicMock())

    assert get_fn_id.called

    assert len(handlers) == 1
    assert handlers[0].fn is some_fn
    assert handlers[0].id == 'some-prefix/some-id'
Exemplo n.º 4
0
def test_with_explicit_id_and_prefix_and_suffix(mocker, field):
    get_fn_id = mocker.patch('kopf.reactor.registries.get_callable_id', return_value='some-id')
    diff = [('add', ('some-field', 'sub-field'), 'old', 'new')]

    registry = ResourceRegistry(prefix='some-prefix')
    registry.register(some_fn, id='explicit-id', field=field)
    handlers = registry.get_resource_changing_handlers(mocker.MagicMock(diff=diff))

    assert not get_fn_id.called

    assert len(handlers) == 1
    assert handlers[0].fn is some_fn
    assert handlers[0].id == 'some-prefix/explicit-id/some-field.sub-field'
Exemplo n.º 5
0
def test_simple_registry_via_iter(mocker):
    cause = mocker.Mock(event=None, diff=None)

    registry = ResourceRegistry()
    iterator = registry.iter_resource_changing_handlers(cause)

    assert isinstance(iterator, collections.abc.Iterator)
    assert not isinstance(iterator, collections.abc.Collection)
    assert not isinstance(iterator, collections.abc.Container)
    assert not isinstance(iterator, (list, tuple))

    handlers = list(iterator)
    assert not handlers