Пример #1
0
def test_get_pod_raises_not_found_api_exception(mocker: MockFixture, k8s_api_client_mock: K8SAPIClient):
    mocker.patch.object(k8s_api_client_mock.v1_api_client, 'list_namespaced_pod').side_effect = \
        ApiException(status=HTTPStatus.NOT_FOUND)

    pod = k8s_api_client_mock.get_pod(namespace=MY_FAKE_NAMESPACE, label_selector=FAKE_LABEL_SELECTOR)

    assert pod is None
Пример #2
0
def test_get_pod_finds_no_pod(mocker: MockFixture, k8s_api_client_mock: K8SAPIClient):
    fake_pods = []
    fake_pods_list = k8s_models.V1PodList(items=fake_pods)

    mocker.patch.object(k8s_api_client_mock.v1_api_client, 'list_namespaced_pod').return_value = fake_pods_list

    found_pod = k8s_api_client_mock.get_pod(namespace=MY_FAKE_NAMESPACE, label_selector=FAKE_LABEL_SELECTOR)

    assert found_pod is None
Пример #3
0
def test_get_pod_finds_many_pods(mocker: MockFixture, k8s_api_client_mock: K8SAPIClient):
    fake_pod = k8s_models.V1Pod(metadata=k8s_models.V1ObjectMeta(name=FAKE_OBJECT_NAME))
    fake_second_pod = k8s_models.V1Pod(metadata=k8s_models.V1ObjectMeta(name=FAKE_OBJECT_NAME+'-2'))
    fake_pods = [fake_pod, fake_second_pod]
    fake_pods_list = k8s_models.V1PodList(items=fake_pods)

    mocker.patch.object(k8s_api_client_mock.v1_api_client, 'list_namespaced_pod').return_value = fake_pods_list

    found_pod = k8s_api_client_mock.get_pod(namespace=MY_FAKE_NAMESPACE, label_selector=FAKE_LABEL_SELECTOR)

    assert found_pod in (fake_pod, fake_second_pod)
Пример #4
0
def test_get_pod_raises_other_api_exception(mocker: MockFixture, k8s_api_client_mock: K8SAPIClient):
    mocker.patch.object(k8s_api_client_mock.v1_api_client, 'list_namespaced_pod').side_effect = \
        ApiException(status=HTTPStatus.BAD_REQUEST)

    with raises(ApiException):
        k8s_api_client_mock.get_pod(namespace=MY_FAKE_NAMESPACE, label_selector=FAKE_LABEL_SELECTOR)