def test_resource_changing_cause_with_all_args(mocker): logger = mocker.Mock() resource = mocker.Mock() reason = mocker.Mock() initial = mocker.Mock() body = mocker.Mock() patch = mocker.Mock() memo = mocker.Mock() diff = mocker.Mock() old = mocker.Mock() new = mocker.Mock() cause = ResourceChangingCause( resource=resource, logger=logger, reason=reason, initial=initial, body=body, patch=patch, memo=memo, diff=diff, old=old, new=new, ) assert cause.resource is resource assert cause.logger is logger assert cause.reason is reason assert cause.initial is initial assert cause.body is body assert cause.patch is patch assert cause.memo is memo assert cause.diff is diff assert cause.old is old assert cause.new is new with pytest.deprecated_call(match=r"use cause.reason"): assert cause.event is reason
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, ) raise TypeError( f"Cause/registry type {cls} is not supported by this fixture.")
def test_no_args(): with pytest.raises(TypeError): ResourceChangingCause()