# Path: k8s/client.py
# class NotFound(K8sClientException):
#     """The resource was not found, and the operation could not be completed"""
# 
# Path: k8s/models/common.py
# class ObjectMeta(Model):
#     annotations = Field(dict)
#     creationTimestamp = ReadOnlyField(datetime.datetime)
#     deletionGracePeriodSeconds = ReadOnlyField(int)
#     deletionTimestamp = ReadOnlyField(datetime.datetime)
#     finalizers = ListField(six.text_type)
#     generateName = Field(six.text_type)
#     generation = ReadOnlyField(int)
#     labels = Field(dict)
#     name = Field(six.text_type)
#     namespace = Field(six.text_type, "default")
#     ownerReferences = ListField(OwnerReference)
#     resourceVersion = ReadOnlyField(six.text_type)
#     selfLink = ReadOnlyField(six.text_type)
#     uid = ReadOnlyField(six.text_type)
# 
# Path: k8s/models/cronjob.py
# class CronJob(Model):
#     class Meta:
#         list_url = "/apis/batch/v1beta1/cronjobs"
#         url_template = "/apis/batch/v1beta1/namespaces/{namespace}/cronjobs/{name}"
# 
#     metadata = Field(ObjectMeta)
#     spec = Field(CronJobSpec)
#     status = Field(CronJobStatus)
# 
# class CronJobSpec(Model):
#     concurrencyPolicy = Field(six.text_type)
#     failedJobsHistoryLimit = Field(int)
#     jobTemplate = Field(JobTemplateSpec)
#     schedule = Field(six.text_type)
#     startingDeadlineSeconds = Field(int)
#     successfulJobsHistoryLimit = Field(int)
#     suspend = Field(bool)
# 
# Path: k8s/models/job.py
# class JobSpec(Model):
#     template = Field(PodTemplateSpec)
#     backoffLimit = Field(int)
#     activeDeadlineSeconds = Field(int)
#     completions = Field(int)
#     manualSelector = Field(bool)
#     parallelism = Field(int)
#     selector = Field(LabelSelector)
# 
# class JobTemplateSpec(Model):
#     metadata = Field(ObjectMeta)
#     spec = Field(JobSpec)
# 
# Path: k8s/models/pod.py
# class Container(Model):
#     name = Field(six.text_type)
#     image = Field(six.text_type)
#     ports = ListField(ContainerPort)
#     env = ListField(EnvVar)
#     envFrom = ListField(EnvFromSource)
#     resources = Field(ResourceRequirements)
#     volumeMounts = ListField(VolumeMount)
#     lifecycle = Field(Lifecycle)
#     livenessProbe = Field(Probe)
#     readinessProbe = Field(Probe)
#     imagePullPolicy = Field(six.text_type, "IfNotPresent")
#     command = ListField(six.text_type)
#     args = ListField(six.text_type)
# 
# class PodTemplateSpec(Model):
#     metadata = Field(ObjectMeta)
#     spec = Field(PodSpec)
# 
# class PodSpec(Model):
#     volumes = ListField(Volume)
#     containers = ListField(Container)
#     restartPolicy = Field(six.text_type, "Always")
#     terminationGracePeriodSeconds = Field(int)
#     activeDeadlineSeconds = Field(int)
#     dnsPolicy = Field(six.text_type, "ClusterFirst")
#     nodeName = Field(six.text_type)
#     nodeSelector = Field(dict)
#     selector = Field(dict)
#     serviceAccountName = Field(six.text_type, "default")
#     automountServiceAccountToken = Field(bool)
#     imagePullSecrets = ListField(LocalObjectReference)
#     initContainers = ListField(Container)


import mock
import pytest
from k8s.client import NotFound
from k8s.models.common import ObjectMeta
from k8s.models.cronjob import CronJob, CronJobSpec
from k8s.models.job import JobSpec, JobTemplateSpec
from k8s.models.pod import Container, PodTemplateSpec, PodSpec





NAME = "my-name"
NAMESPACE = "my-namespace"


@pytest.mark.usefixtures("k8s_config")
class TestCronJobs(object):
    def test_create_blank_job(self):
        object_meta = ObjectMeta(name=NAME, namespace=NAMESPACE)
        cronjob = CronJob(metadata=object_meta)
        assert cronjob.as_dict()[u"metadata"][u"name"] == NAME

    def test_created_if_not_exists(self, post, api_get):
        api_get.side_effect = NotFound()
        cronjob = _create_default_cronjob()
        call_params = cronjob.as_dict()
        post.return_value.json.return_value = call_params

        assert cronjob._new
        cronjob.save()
        assert not cronjob._new

        pytest.helpers.assert_any_call(post, _uri(NAMESPACE), call_params)


def _create_default_cronjob():

# Path: k8s/client.py
# class NotFound(K8sClientException):
#     """The resource was not found, and the operation could not be completed"""
# 
# Path: k8s/models/common.py
# class ObjectMeta(Model):
#     annotations = Field(dict)
#     creationTimestamp = ReadOnlyField(datetime.datetime)
#     deletionGracePeriodSeconds = ReadOnlyField(int)
#     deletionTimestamp = ReadOnlyField(datetime.datetime)
#     finalizers = ListField(six.text_type)
#     generateName = Field(six.text_type)
#     generation = ReadOnlyField(int)
#     labels = Field(dict)
#     name = Field(six.text_type)
#     namespace = Field(six.text_type, "default")
#     ownerReferences = ListField(OwnerReference)
#     resourceVersion = ReadOnlyField(six.text_type)
#     selfLink = ReadOnlyField(six.text_type)
#     uid = ReadOnlyField(six.text_type)
# 
# Path: k8s/models/cronjob.py
# class CronJob(Model):
#     class Meta:
#         list_url = "/apis/batch/v1beta1/cronjobs"
#         url_template = "/apis/batch/v1beta1/namespaces/{namespace}/cronjobs/{name}"
# 
#     metadata = Field(ObjectMeta)
#     spec = Field(CronJobSpec)
#     status = Field(CronJobStatus)
# 
# class CronJobSpec(Model):
#     concurrencyPolicy = Field(six.text_type)
#     failedJobsHistoryLimit = Field(int)
#     jobTemplate = Field(JobTemplateSpec)
#     schedule = Field(six.text_type)
#     startingDeadlineSeconds = Field(int)
#     successfulJobsHistoryLimit = Field(int)
#     suspend = Field(bool)
# 
# Path: k8s/models/job.py
# class JobSpec(Model):
#     template = Field(PodTemplateSpec)
#     backoffLimit = Field(int)
#     activeDeadlineSeconds = Field(int)
#     completions = Field(int)
#     manualSelector = Field(bool)
#     parallelism = Field(int)
#     selector = Field(LabelSelector)
# 
# class JobTemplateSpec(Model):
#     metadata = Field(ObjectMeta)
#     spec = Field(JobSpec)
# 
# Path: k8s/models/pod.py
# class Container(Model):
#     name = Field(six.text_type)
#     image = Field(six.text_type)
#     ports = ListField(ContainerPort)
#     env = ListField(EnvVar)
#     envFrom = ListField(EnvFromSource)
#     resources = Field(ResourceRequirements)
#     volumeMounts = ListField(VolumeMount)
#     lifecycle = Field(Lifecycle)
#     livenessProbe = Field(Probe)
#     readinessProbe = Field(Probe)
#     imagePullPolicy = Field(six.text_type, "IfNotPresent")
#     command = ListField(six.text_type)
#     args = ListField(six.text_type)
# 
# class PodTemplateSpec(Model):
#     metadata = Field(ObjectMeta)
#     spec = Field(PodSpec)
# 
# class PodSpec(Model):
#     volumes = ListField(Volume)
#     containers = ListField(Container)
#     restartPolicy = Field(six.text_type, "Always")
#     terminationGracePeriodSeconds = Field(int)
#     activeDeadlineSeconds = Field(int)
#     dnsPolicy = Field(six.text_type, "ClusterFirst")
#     nodeName = Field(six.text_type)
#     nodeSelector = Field(dict)
#     selector = Field(dict)
#     serviceAccountName = Field(six.text_type, "default")
#     automountServiceAccountToken = Field(bool)
#     imagePullSecrets = ListField(LocalObjectReference)
#     initContainers = ListField(Container)


# Path: tests/k8s/test_cronjob.py
import mock
import pytest
from k8s.client import NotFound
from k8s.models.common import ObjectMeta
from k8s.models.cronjob import CronJob, CronJobSpec
from k8s.models.job import JobSpec, JobTemplateSpec
from k8s.models.pod import Container, PodTemplateSpec, PodSpec






NAME = "my-name"
NAMESPACE = "my-namespace"


@pytest.mark.usefixtures("k8s_config")
class TestCronJobs(object):
    def test_create_blank_job(self):
        object_meta = ObjectMeta(name=NAME, namespace=NAMESPACE)
        cronjob = CronJob(metadata=object_meta)
        assert cronjob.as_dict()[u"metadata"][u"name"] == NAME

    def test_created_if_not_exists(self, post, api_get):
        api_get.side_effect = NotFound()
        cronjob = _create_default_cronjob()
        call_params = cronjob.as_dict()
        post.return_value.json.return_value = call_params

        assert cronjob._new
        cronjob.save()
        assert not cronjob._new

        pytest.helpers.assert_any_call(post, _uri(NAMESPACE), call_params)


def _create_default_cronjob():

    object_meta = ObjectMeta(name=NAME, namespace=NAMESPACE)