def test_requires_finalizer_no_deletion_handler():
    registry = GlobalRegistry()
    resource = Resource('group', 'version', 'plural')

    @kopf.on.create('group', 'version', 'plural', registry=registry)
    def fn1(**_):
        pass

    requires_finalizer = registry.requires_finalizer(resource=resource,
                                                     body=OBJECT_BODY)
    assert requires_finalizer is False
def test_requires_finalizer_deletion_handler(optional, expected):
    registry = GlobalRegistry()
    resource = Resource('group', 'version', 'plural')

    @kopf.on.delete('group', 'version', 'plural',
                    registry=registry, optional=optional)
    def fn(**_):
        pass

    requires_finalizer = registry.requires_finalizer(resource=resource, cause=CAUSE)
    assert requires_finalizer == expected
def test_requires_finalizer_no_deletion_handler():
    registry = GlobalRegistry()
    resource = Resource('group', 'version', 'plural')

    @kopf.on.create('group', 'version', 'plural', registry=registry)
    def fn1(**_):
        pass

    with pytest.deprecated_call(match=r"cease using the internal registries"):
        requires_finalizer = registry.requires_finalizer(resource=resource,
                                                         cause=CAUSE)
    assert requires_finalizer is False
def test_requires_finalizer_deletion_handler(optional, expected):
    registry = GlobalRegistry()
    resource = Resource('group', 'version', 'plural')

    @kopf.on.delete('group',
                    'version',
                    'plural',
                    registry=registry,
                    optional=optional)
    def fn(**_):
        pass

    with pytest.deprecated_call(match=r"cease using the internal registries"):
        requires_finalizer = registry.requires_finalizer(resource=resource,
                                                         cause=CAUSE)
    assert requires_finalizer == expected
def test_requires_finalizer_deletion_handler_matches_labels(
        labels, optional, expected):
    registry = GlobalRegistry()
    resource = Resource('group', 'version', 'plural')

    @kopf.on.delete('group',
                    'version',
                    'plural',
                    labels=labels,
                    registry=registry,
                    optional=optional)
    def fn(**_):
        pass

    requires_finalizer = registry.requires_finalizer(resource=resource,
                                                     body=OBJECT_BODY)
    assert requires_finalizer == expected
def test_requires_finalizer_deletion_handler_mismatches_annotations(
        annotations, optional, expected):
    registry = GlobalRegistry()
    resource = Resource('group', 'version', 'plural')

    @kopf.on.delete('group',
                    'version',
                    'plural',
                    annotations=annotations,
                    registry=registry,
                    optional=optional)
    def fn(**_):
        pass

    with pytest.deprecated_call(
            match=r"use registry.resource_changing_handlers"):
        requires_finalizer = registry.requires_finalizer(resource=resource,
                                                         cause=CAUSE)
    assert requires_finalizer == expected
示例#7
0
def test_requires_finalizer_deletion_handler_matches_labels(
        labels, optional, expected, cause_factory):
    registry = GlobalRegistry()
    resource = Resource('group', 'version', 'plural')
    cause = cause_factory(resource=resource, body=OBJECT_BODY)

    @kopf.on.delete('group',
                    'version',
                    'plural',
                    labels=labels,
                    registry=registry,
                    optional=optional)
    def fn(**_):
        pass

    with pytest.deprecated_call(match=r"cease using the internal registries"):
        requires_finalizer = registry.requires_finalizer(resource=resource,
                                                         cause=cause)
    assert requires_finalizer == expected
def test_requires_finalizer_multiple_handlers(optional, expected):
    registry = GlobalRegistry()
    resource = Resource('group', 'version', 'plural')

    @kopf.on.create('group', 'version', 'plural', registry=registry)
    def fn1(**_):
        pass

    @kopf.on.delete('group',
                    'version',
                    'plural',
                    registry=registry,
                    optional=optional)
    def fn2(**_):
        pass

    requires_finalizer = registry.requires_finalizer(resource=resource,
                                                     body=OBJECT_BODY)
    assert requires_finalizer == expected
def test_requires_finalizer_multiple_handlers(optional, expected):
    registry = GlobalRegistry()
    resource = Resource('group', 'version', 'plural')

    @kopf.on.create('group', 'version', 'plural', registry=registry)
    def fn1(**_):
        pass

    @kopf.on.delete('group',
                    'version',
                    'plural',
                    registry=registry,
                    optional=optional)
    def fn2(**_):
        pass

    with pytest.deprecated_call(
            match=r"use registry.resource_changing_handlers"):
        requires_finalizer = registry.requires_finalizer(resource=resource,
                                                         cause=CAUSE)
    assert requires_finalizer == expected