MockKubernetesApi#
- class safir.testing.kubernetes.MockKubernetesApi#
Bases:
object
Mock Kubernetes API for testing.
This object simulates (with almost everything left out) the
CoreV1Api
andCustomObjectApi
client objects while keeping simple internal state. It is intended to be used as a mock inside tests.Methods ending with
_for_test
are outside of the API and are intended for use by the test suite.If
error_callback
is set to a callable, it will be called with the method name and any arguments whenever any Kubernetes API method is called and before it takes any action. This can be used to inject exceptions for test purposes.Notes
This class is normally not instantiated directly. Instead, call the
patch_kubernetes
function from a fixture to set up the mock.Methods Summary
create_namespaced_config_map
(namespace, ...)- param namespace:
create_namespaced_custom_object
(group, ...)- param group:
create_namespaced_pod
(namespace, pod)- param namespace:
create_namespaced_secret
(namespace, secret)- param namespace:
delete_namespaced_config_map
(name, namespace)- param name:
delete_namespaced_pod
(name, namespace)- param name:
get_all_objects_for_test
(kind)Return all objects of a given kind sorted by namespace and name.
get_namespaced_custom_object
(group, version, ...)- param group:
list_cluster_custom_object
(group, version, ...)- param group:
list_namespaced_pod
(namespace, *, field_selector)- param namespace:
patch_namespaced_custom_object_status
(group, ...)- param group:
patch_namespaced_secret
(name, namespace, body)- param name:
read_namespaced_pod
(name, namespace)- param name:
read_namespaced_secret
(name, namespace)- param name:
replace_namespaced_custom_object
(group, ...)- param group:
replace_namespaced_secret
(name, namespace, ...)- param name:
Methods Documentation
- async create_namespaced_config_map(namespace, config_map)#
- async create_namespaced_custom_object(group, version, namespace, plural, body)#
- async create_namespaced_pod(namespace, pod)#
- async create_namespaced_secret(namespace, secret)#
- async delete_namespaced_config_map(name, namespace)#
- async delete_namespaced_pod(name, namespace)#
- get_all_objects_for_test(kind)#
Return all objects of a given kind sorted by namespace and name.
- Parameters:
kind (
str
) – The Kubernetes kind, such asSecret
orPod
. This is case-sensitive.- Returns:
objects – All objects of that kind found in the mock, sorted by namespace and then name.
- Return type:
List[
typing.Any
]
- async get_namespaced_custom_object(group, version, namespace, plural, name)#
- async list_cluster_custom_object(group, version, plural)#
- async list_namespaced_pod(namespace, *, field_selector)#
- async patch_namespaced_custom_object_status(group, version, namespace, plural, name, body)#
- async patch_namespaced_secret(name, namespace, body)#
- async read_namespaced_pod(name, namespace)#
- async read_namespaced_secret(name, namespace)#
- async replace_namespaced_custom_object(group, version, namespace, plural, name, body)#