def test_get_deployment_status_raises_exception_when_deployment_cannot_be_found(
    mock_k8s_apps_api: MagicMock,
    service_stage_deployment_object: kubernetes.client.V1Deployment,
):
    mock_k8s_apps_api().list_namespaced_deployment.return_value = (
        kubernetes.client.V1DeploymentList(items=[]))
    with raises(RuntimeError):
        _get_deployment_status(service_stage_deployment_object)
def test_get_deployment_status_raises_exception_when_status_cannot_be_determined(
        mock_k8s_apps_api: MagicMock,
        service_stage_deployment_object: kubernetes.client.V1Deployment):
    mock_k8s_apps_api().list_namespaced_deployment.return_value = (
        kubernetes.client.V1DeploymentList(items=[
            kubernetes.client.V1Deployment(
                metadata=kubernetes.client.V1ObjectMeta(
                    name='bodywork-test-project--serve'),
                status=kubernetes.client.V1DeploymentStatus(
                    available_replicas=0, unavailable_replicas=0))
        ]))
    with raises(RuntimeError, match='cannot determine status for deployment'):
        _get_deployment_status(service_stage_deployment_object)
def test_get_deployment_status_correctly_determines_complete_status(
        mock_k8s_apps_api: MagicMock,
        service_stage_deployment_object: kubernetes.client.V1Deployment):
    mock_k8s_apps_api().list_namespaced_deployment.return_value = (
        kubernetes.client.V1DeploymentList(items=[
            kubernetes.client.V1Deployment(
                metadata=kubernetes.client.V1ObjectMeta(
                    name='bodywork-test-project--serve'),
                status=kubernetes.client.V1DeploymentStatus(
                    available_replicas=1, unavailable_replicas=None))
        ]))
    assert (_get_deployment_status(service_stage_deployment_object) ==
            DeploymentStatus.COMPLETE)