コード例 #1
0
def test_create_get_kind_call(mocked_get_kind: mock.MagicMock):
    """
    GIVEN mocked body and mocked get_kind
    WHEN create is called with the body
    THEN get_kind is called with the body.
    """
    mock_body = mock.MagicMock()

    operations.create(body=mock_body)

    mocked_get_kind.assert_called_once_with(body=mock_body)
コード例 #2
0
def test_create_get_api_version_call(mocked_get_api_version: mock.MagicMock):
    """
    GIVEN mocked body and mocked get_api_version
    WHEN create is called with the body
    THEN get_api_version is called with the body.
    """
    mock_body = mock.MagicMock()

    operations.create(body=mock_body)

    mocked_get_api_version.assert_called_once_with(body=mock_body)
コード例 #3
0
def test_create_client_function_call(mocked_get_function: mock.MagicMock):
    """
    GIVEN mocked body and mocked get_function that returns a client function and False
        for namespaced
    WHEN create is called with the body
    THEN the client function is called with the body.
    """
    mock_body = mock.MagicMock()
    mock_client_function = mock.MagicMock()
    mocked_get_function.return_value = helpers.GetFunctionReturn(
        mock_client_function, False
    )

    operations.create(body=mock_body)

    mock_client_function.assert_called_once_with(body=mock_body)
コード例 #4
0
def test_create_get_function_call(
    mocked_get_api_version: mock.MagicMock,
    mocked_get_kind: mock.MagicMock,
    mocked_get_function: mock.MagicMock,
):
    """
    GIVEN mocked get_api_version, get_kind and get_function
    WHEN create is called with the body
    THEN get_function is called with get_api_version and get_kind return value and the
        create operation.
    """
    operations.create(body=mock.MagicMock())

    mocked_get_function.assert_called_once_with(
        api_version=mocked_get_api_version.return_value,
        kind=mocked_get_kind.return_value,
        operation="create",
    )
コード例 #5
0
def test_create_get_kind_raises(mocked_get_kind: mock.MagicMock):
    """
    GIVEN mocked body and mocked get_kind that raises KindMissingError
    WHEN create is called with the body
    THEN failure response is returned.
    """
    mocked_get_kind.side_effect = exceptions.KindMissingError

    return_value = operations.create(body=mock.MagicMock())

    assert return_value == operations.CreateReturn("FAILURE", "kind is required.", None)
コード例 #6
0
def test_create_client_function_return(mocked_get_function: mock.MagicMock):
    """
    GIVEN  mocked get_function that returns a client function that returns the
        metadata with a name and False for namespaced
    WHEN create is called
    THEN success response is returned.
    """
    mock_client_function = mock.MagicMock()
    mock_return = mock.MagicMock()
    mock_return.metadata.name = "name 1"
    mock_client_function.return_value = mock_return
    mocked_get_function.return_value = helpers.GetFunctionReturn(
        mock_client_function, False
    )

    return_value = operations.create(body=mock.MagicMock())

    assert return_value == operations.CreateReturn("SUCCESS", None, "name 1")
コード例 #7
0
def test_deployment_create(nginx_deployment_info):
    """
    GIVEN deployment as dictionary
    WHEN create is called with the deployment dictionary as a body
    THEN the deployment is created.
    """
    deployment_dict, namespace, name = nginx_deployment_info

    result = operations.create(body=deployment_dict)

    # Check result
    assert result.status == "SUCCESS"
    assert result.physical_name == f"{namespace}/{name}"
    # Check that the deployment is created
    apps_v1_api = kubernetes.client.AppsV1Api()
    response = apps_v1_api.list_namespaced_deployment(namespace=namespace)
    assert response.items
    assert response.items[0].metadata.name == name
コード例 #8
0
def test_cluster_role_create(cluster_role_info):
    """
    GIVEN cluster role as dictionary
    WHEN create is called with the cluster role dictionary as a body
    THEN the cluster role is created.
    """
    cluster_role_dict, name = cluster_role_info

    result = operations.create(body=cluster_role_dict)

    # Check result
    assert result.status == "SUCCESS"
    assert result.physical_name == name
    # Check that the cluster role is created
    rbac_v1_api = kubernetes.client.RbacAuthorizationV1Api()
    response = rbac_v1_api.list_cluster_role()
    assert response.items
    assert name in {item.metadata.name for item in response.items}
コード例 #9
0
def test_create_client_function_namespace_raises(mocked_get_function: mock.MagicMock):
    """
    GIVEN mocked get_function that returns a client function that raises ApiException
        and True for namespaced
    WHEN create is called
    THEN failure response is returned.
    """
    mock_client_function = mock.MagicMock()
    mock_client_function.side_effect = kubernetes.client.rest.ApiException(
        "400", "reason 1"
    )
    mocked_get_function.return_value = helpers.GetFunctionReturn(
        mock_client_function, True
    )

    return_value = operations.create(body=mock.MagicMock())

    assert return_value == operations.CreateReturn(
        "FAILURE", "(400)\nReason: reason 1\n", None
    )
コード例 #10
0
def _nginx_deployment(nginx_deployment_info):
    """Create Kubernetes deployment."""
    deployment_dict, _namespace, _name = nginx_deployment_info
    result = operations.create(body=deployment_dict)

    assert result.status == "SUCCESS"
コード例 #11
0
def _cluster_role(cluster_role_info):
    """Create Kubernetes cluster role."""
    cluster_role_dict, _name = cluster_role_info
    result = operations.create(body=cluster_role_dict)

    assert result.status == "SUCCESS"