# 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/ingress.py
# class Ingress(Model):
#     class Meta:
#         list_url = "/apis/extensions/v1beta1/ingresses"
#         url_template = "/apis/extensions/v1beta1/namespaces/{namespace}/ingresses/{name}"
#         watch_list_url = "/apis/extensions/v1beta1/watch/ingresses"
# 
#     metadata = Field(ObjectMeta)
#     spec = Field(IngressSpec)
# 
# class IngressSpec(Model):
#     backend = Field(IngressBackend)
#     rules = ListField(IngressRule)
#     tls = ListField(IngressTLS)
# 
# class IngressRule(Model):
#     host = Field(six.text_type)
#     http = Field(HTTPIngressRuleValue)
# 
# class IngressBackend(Model):
#     serviceName = Field(six.text_type)
#     servicePort = Field(six.text_type)
# 
# class HTTPIngressPath(Model):
#     path = Field(six.text_type)
#     backend = Field(IngressBackend)
# 
# class HTTPIngressRuleValue(Model):
#     paths = ListField(HTTPIngressPath)


import mock
import pytest
from k8s.client import NotFound
from k8s.models.common import ObjectMeta
from k8s.models.ingress import Ingress, IngressSpec, IngressRule, IngressBackend, HTTPIngressPath, HTTPIngressRuleValue


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


@pytest.mark.usefixtures("k8s_config")
class TestIngress(object):
    def test_create_blank(self):
        object_meta = ObjectMeta(name=NAME, namespace=NAMESPACE, labels={"test": "true"})
        ingress = Ingress(metadata=object_meta)
        assert ingress.as_dict()[u"metadata"][u"name"] == NAME

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

        assert ingress._new
        ingress.save()
        assert not ingress._new

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

    def test_updated_if_exists(self, get, put):
        mock_response = _create_mock_response()
        get.return_value = mock_response
        ingress = _create_default_ingress()


# 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/ingress.py
# class Ingress(Model):
#     class Meta:
#         list_url = "/apis/extensions/v1beta1/ingresses"
#         url_template = "/apis/extensions/v1beta1/namespaces/{namespace}/ingresses/{name}"
#         watch_list_url = "/apis/extensions/v1beta1/watch/ingresses"
# 
#     metadata = Field(ObjectMeta)
#     spec = Field(IngressSpec)
# 
# class IngressSpec(Model):
#     backend = Field(IngressBackend)
#     rules = ListField(IngressRule)
#     tls = ListField(IngressTLS)
# 
# class IngressRule(Model):
#     host = Field(six.text_type)
#     http = Field(HTTPIngressRuleValue)
# 
# class IngressBackend(Model):
#     serviceName = Field(six.text_type)
#     servicePort = Field(six.text_type)
# 
# class HTTPIngressPath(Model):
#     path = Field(six.text_type)
#     backend = Field(IngressBackend)
# 
# class HTTPIngressRuleValue(Model):
#     paths = ListField(HTTPIngressPath)


# Path: tests/k8s/test_ingress.py
import mock
import pytest
from k8s.client import NotFound
from k8s.models.common import ObjectMeta
from k8s.models.ingress import Ingress, IngressSpec, IngressRule, IngressBackend, HTTPIngressPath, HTTPIngressRuleValue



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


@pytest.mark.usefixtures("k8s_config")
class TestIngress(object):
    def test_create_blank(self):
        object_meta = ObjectMeta(name=NAME, namespace=NAMESPACE, labels={"test": "true"})
        ingress = Ingress(metadata=object_meta)
        assert ingress.as_dict()[u"metadata"][u"name"] == NAME

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

        assert ingress._new
        ingress.save()
        assert not ingress._new

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

    def test_updated_if_exists(self, get, put):
        mock_response = _create_mock_response()
        get.return_value = mock_response
        ingress = _create_default_ingress()


        from_api = Ingress.get_or_create(metadata=ingress.metadata, spec=ingress.spec)