Ejemplo n.º 1
0
def test_activity_cause(mocker):
    logger = mocker.Mock()
    activity = mocker.Mock()
    cause = ActivityCause(
        activity=activity,
        logger=logger,
    )
    assert cause.activity is activity
    assert cause.logger is logger
Ejemplo n.º 2
0
def test_activity_kwargs(resource, activity):
    cause = ActivityCause(
        logger=logging.getLogger('kopf.test.fake.logger'),
        activity=activity,
        settings=OperatorSettings(),
    )
    kwargs = build_kwargs(cause=cause, extrakwarg=123)
    assert set(kwargs) == {'extrakwarg', 'logger', 'activity'}
    assert kwargs['extrakwarg'] == 123
    assert kwargs['logger'] is cause.logger
    assert kwargs['activity'] is activity
Ejemplo n.º 3
0
def test_activity_cause(mocker):
    logger = mocker.Mock()
    activity = mocker.Mock()
    settings = mocker.Mock()
    cause = ActivityCause(
        activity=activity,
        settings=settings,
        logger=logger,
    )
    assert cause.activity is activity
    assert cause.settings is settings
    assert cause.logger is logger
Ejemplo n.º 4
0
 def make_cause(
     cls=ResourceChangingCause,
     *,
     resource=resource,
     type=None,
     raw=None,
     body=None,
     diff=(),
     reason='some-reason',
     initial=False,
     activity=None,
     settings=None,
 ):
     if cls is ActivityCause or cls is ActivityRegistry:
         return ActivityCause(
             logger=logging.getLogger('kopf.test.fake.logger'),
             activity=activity,
             settings=settings,
         )
     if cls is ResourceCause or cls is ResourceRegistry or cls is SimpleRegistry:
         return ResourceCause(
             logger=logging.getLogger('kopf.test.fake.logger'),
             resource=resource,
             patch=Patch(),
             memo=Memo(),
             body=Body(body if body is not None else {}),
         )
     if cls is ResourceWatchingCause or cls is ResourceWatchingRegistry:
         return ResourceWatchingCause(
             logger=logging.getLogger('kopf.test.fake.logger'),
             resource=resource,
             patch=Patch(),
             memo=Memo(),
             body=Body(body if body is not None else {}),
             type=type,
             raw=raw,
         )
     if cls is ResourceChangingCause or cls is ResourceChangingRegistry:
         return ResourceChangingCause(
             logger=logging.getLogger('kopf.test.fake.logger'),
             resource=resource,
             patch=Patch(),
             memo=Memo(),
             body=Body(body if body is not None else {}),
             diff=Diff(DiffItem(*d) for d in diff),
             initial=initial,
             reason=reason,
         )
     raise TypeError(
         f"Cause/registry type {cls} is not supported by this fixture.")
Ejemplo n.º 5
0
def test_activity_kwargs(resource, activity, indices):
    cause = ActivityCause(
        memo=Memo(),
        logger=logging.getLogger('kopf.test.fake.logger'),
        indices=indices,
        activity=activity,
        settings=OperatorSettings(),
    )
    kwargs = build_kwargs(cause=cause, extrakwarg=123)
    assert set(kwargs) == {
        'extrakwarg', 'memo', 'logger', 'index1', 'index2', 'activity'
    }
    assert kwargs['extrakwarg'] == 123
    assert kwargs['index1'] is indices['index1']
    assert kwargs['index2'] is indices['index2']
    assert kwargs['logger'] is cause.logger
    assert kwargs['activity'] is activity
Ejemplo n.º 6
0
def test_activity_cause(mocker):
    memo = mocker.Mock()
    logger = mocker.Mock()
    indices = mocker.Mock()
    activity = mocker.Mock()
    settings = mocker.Mock()
    cause = ActivityCause(
        activity=activity,
        settings=settings,
        indices=indices,
        logger=logger,
        memo=memo,
    )
    assert cause.activity is activity
    assert cause.settings is settings
    assert cause.indices is indices
    assert cause.logger is logger
    assert cause.memo is memo
Ejemplo n.º 7
0
 def make_cause(
     cls=ResourceChangingCause,
     *,
     resource=resource,
     type=None,
     raw=None,
     body=None,
     diff=(),
     old=None,
     new=None,
     reason='some-reason',
     initial=False,
     activity=None,
     settings=None,
 ):
     if cls is ActivityCause or cls is ActivityRegistry:
         return ActivityCause(
             memo=Memo(),
             logger=logging.getLogger('kopf.test.fake.logger'),
             indices=OperatorIndexers().indices,
             activity=activity,
             settings=settings,
         )
     if cls is ResourceCause or cls is ResourceRegistry:
         return ResourceCause(
             logger=logging.getLogger('kopf.test.fake.logger'),
             indices=OperatorIndexers().indices,
             resource=resource,
             patch=Patch(),
             memo=Memo(),
             body=Body(body if body is not None else {}),
         )
     if cls is ResourceWatchingCause or cls is ResourceWatchingRegistry:
         return ResourceWatchingCause(
             logger=logging.getLogger('kopf.test.fake.logger'),
             indices=OperatorIndexers().indices,
             resource=resource,
             patch=Patch(),
             memo=Memo(),
             body=Body(body if body is not None else {}),
             type=type,
             raw=raw,
         )
     if cls is ResourceChangingCause or cls is ResourceChangingRegistry:
         return ResourceChangingCause(
             logger=logging.getLogger('kopf.test.fake.logger'),
             indices=OperatorIndexers().indices,
             resource=resource,
             patch=Patch(),
             memo=Memo(),
             body=Body(body if body is not None else {}),
             diff=Diff(DiffItem(*d) for d in diff),
             old=old,
             new=new,
             initial=initial,
             reason=reason,
         )
     if cls is ResourceSpawningCause or cls is ResourceSpawningRegistry:
         return ResourceSpawningCause(
             logger=logging.getLogger('kopf.test.fake.logger'),
             indices=OperatorIndexers().indices,
             resource=resource,
             patch=Patch(),
             memo=Memo(),
             body=Body(body if body is not None else {}),
             reset=False,
         )
     if cls is ResourceWebhookCause or cls is ResourceWebhooksRegistry:
         return ResourceWebhookCause(
             logger=logging.getLogger('kopf.test.fake.logger'),
             indices=OperatorIndexers().indices,
             resource=resource,
             patch=Patch(),
             memo=Memo(),
             body=Body(body if body is not None else {}),
             dryrun=False,
             sslpeer={},
             headers={},
             userinfo={},
             warnings=[],
             reason=None,
             webhook=None,
             operation=None,
         )
     raise TypeError(
         f"Cause/registry type {cls} is not supported by this fixture.")