# 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)
# 
# class LocalObjectReference(Model):
#     name = Field(six.text_type)
# 
# Path: k8s/models/service_account.py
# class ServiceAccount(Model):
#     class Meta:
#         list_url = "/api/v1/serviceaccounts"
#         url_template = "/api/v1/namespaces/{namespace}/serviceaccounts/{name}"
# 
#     metadata = Field(ObjectMeta)
#     imagePullSecrets = ListField(LocalObjectReference)
#     secrets = ListField(LocalObjectReference)
#     automountServiceAccountToken = Field(bool)


import mock
import pytest
from k8s.client import NotFound
from k8s.models.common import ObjectMeta, LocalObjectReference
from k8s.models.service_account import ServiceAccount
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.




NAME = "my-service-account"
NAMESPACE = "my-namespace"


@pytest.mark.usefixtures("k8s_config")
class TestServiceAccount(object):
    def test_created_if_not_exists(self, post, api_get):
        api_get.side_effect = NotFound()
        service_account = _create_default_service_account()
        call_params = service_account.as_dict()
        post.return_value.json.return_value = call_params

        assert service_account._new
        service_account.save()
        assert not service_account._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
        service_account = _create_default_service_account()


# 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)
# 
# class LocalObjectReference(Model):
#     name = Field(six.text_type)
# 
# Path: k8s/models/service_account.py
# class ServiceAccount(Model):
#     class Meta:
#         list_url = "/api/v1/serviceaccounts"
#         url_template = "/api/v1/namespaces/{namespace}/serviceaccounts/{name}"
# 
#     metadata = Field(ObjectMeta)
#     imagePullSecrets = ListField(LocalObjectReference)
#     secrets = ListField(LocalObjectReference)
#     automountServiceAccountToken = Field(bool)


# Path: tests/k8s/test_service_account.py
import mock
import pytest
from k8s.client import NotFound
from k8s.models.common import ObjectMeta, LocalObjectReference
from k8s.models.service_account import ServiceAccount

# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.




NAME = "my-service-account"
NAMESPACE = "my-namespace"


@pytest.mark.usefixtures("k8s_config")
class TestServiceAccount(object):
    def test_created_if_not_exists(self, post, api_get):
        api_get.side_effect = NotFound()
        service_account = _create_default_service_account()
        call_params = service_account.as_dict()
        post.return_value.json.return_value = call_params

        assert service_account._new
        service_account.save()
        assert not service_account._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
        service_account = _create_default_service_account()


        from_api = ServiceAccount.get_or_create(