def validate1(spec, dryrun, **_): if not dryrun and spec.get('field') == 'wrong': raise kopf.AdmissionError("Meh! I don't like it. Change the field.")
def validate2(**_): raise kopf.AdmissionError("I'm too lazy anyway. Go away!", code=555)
memories=memories, memobase=object(), indices=indices, ) assert 'warnings' not in response['response'] assert 'patchType' not in response['response'] assert 'patch' not in response['response'] assert 'status' not in response['response'] assert response['response']['allowed'] is True @pytest.mark.parametrize('error, exp_msg, exp_code', [ (Exception("No!"), "No!", 500), (kopf.PermanentError("No!"), "No!", 500), (kopf.TemporaryError("No!"), "No!", 500), (kopf.AdmissionError("No!"), "No!", 500), (kopf.AdmissionError("No!", code=123), "No!", 123), ]) @pytest.mark.parametrize('decorator', [kopf.on.validate, kopf.on.mutate]) async def test_errors_deny_admission(settings, registry, resource, memories, insights, indices, adm_request, decorator, error, exp_msg, exp_code): @decorator(*resource) def fn(**_): raise error response = await serve_admission_request( adm_request, settings=settings, registry=registry, insights=insights,