# Path: lamvery/clients/apigateway.py
# class ApiGatewayClient(BaseClient):
# 
#     def __init__(self, *args, **kwargs):
#         super(ApiGatewayClient, self).__init__(*args, **kwargs)
#         self._api = self._session.client('apigateway')
# 
#     def get_rest_api(self, api_id):
#         if api_id is None:
#             return None
# 
#         try:
#             return self._api.get_rest_api(restApiId=api_id)
#         except botocore.exceptions.ClientError:
#             return None
# 
#     def get_export(self, api_id, stage):
#         if api_id is None:
#             return {}
# 
#         try:
#             ret = self._api.get_export(
#                 restApiId=api_id,
#                 stageName=stage,
#                 exportType='swagger',
#                 parameters={'extensions': 'integrations'})
#             return json.loads(ret['body'].read())
# 
#         except botocore.exceptions.ClientError:
#             return {}
# 
#     def import_rest_api(self, api_conf):
#         return self._api.import_rest_api(body=json.dumps(api_conf))
# 
#     def put_rest_api(self, api_id, api_conf):
#         return self._api.put_rest_api(
#             restApiId=api_id,
#             mode='overwrite',
#             body=json.dumps(api_conf))
# 
#     def delete_rest_api(self, api_id):
#         self._api.delete_rest_api(api_id)
# 
#     def create_deployment(self, api_id, stage):
#         return self._api.create_deployment(
#             restApiId=api_id,
#             stageName=stage)


import botocore
from unittest import TestCase
from nose.tools import eq_
from mock import Mock
from lamvery.clients.apigateway import ApiGatewayClient

    def setUp(self):
        self.client = ApiGatewayClient(region='us-east-1')
        self.client._api = Mock()

    def test_get_rest_api(self):
        self.client._api.get_rest_api = Mock(return_value={'foo': 'bar'})
        eq_(self.client.get_rest_api(None), None)
        eq_(self.client.get_rest_api('baz'), {'foo': 'bar'})

        self.client._api.get_rest_api = Mock(
            side_effect=botocore.exceptions.ClientError({'Error': {}}, 'bar'))
        eq_(self.client.get_rest_api('baz'), None)

    def test_get_export(self):
        m = Mock()
        m.read = Mock(return_value='{"foo": "bar"}')
        self.client._api.get_export = Mock(return_value={'body': m})
        eq_(self.client.get_export(None, 'baz'), {})
        eq_(self.client.get_export('baz', 'qux'), {'foo': 'bar'})

        self.client._api.get_export = Mock(
            side_effect=botocore.exceptions.ClientError({'Error': {}}, 'bar'))
        eq_(self.client.get_export('baz', 'qux'), {})

    def test_import_rest_api(self):
        self.client._api.import_rest_api = Mock(return_value={'foo': 'bar'})
        eq_(self.client.import_rest_api({'baz': 'qux'}), {'foo': 'bar'})

    def test_put_rest_api(self):

# Path: lamvery/clients/apigateway.py
# class ApiGatewayClient(BaseClient):
# 
#     def __init__(self, *args, **kwargs):
#         super(ApiGatewayClient, self).__init__(*args, **kwargs)
#         self._api = self._session.client('apigateway')
# 
#     def get_rest_api(self, api_id):
#         if api_id is None:
#             return None
# 
#         try:
#             return self._api.get_rest_api(restApiId=api_id)
#         except botocore.exceptions.ClientError:
#             return None
# 
#     def get_export(self, api_id, stage):
#         if api_id is None:
#             return {}
# 
#         try:
#             ret = self._api.get_export(
#                 restApiId=api_id,
#                 stageName=stage,
#                 exportType='swagger',
#                 parameters={'extensions': 'integrations'})
#             return json.loads(ret['body'].read())
# 
#         except botocore.exceptions.ClientError:
#             return {}
# 
#     def import_rest_api(self, api_conf):
#         return self._api.import_rest_api(body=json.dumps(api_conf))
# 
#     def put_rest_api(self, api_id, api_conf):
#         return self._api.put_rest_api(
#             restApiId=api_id,
#             mode='overwrite',
#             body=json.dumps(api_conf))
# 
#     def delete_rest_api(self, api_id):
#         self._api.delete_rest_api(api_id)
# 
#     def create_deployment(self, api_id, stage):
#         return self._api.create_deployment(
#             restApiId=api_id,
#             stageName=stage)


# Path: tests/lamvery/clients/apigateway_test.py
import botocore
from unittest import TestCase
from nose.tools import eq_
from mock import Mock
from lamvery.clients.apigateway import ApiGatewayClient


    def setUp(self):
        self.client = ApiGatewayClient(region='us-east-1')
        self.client._api = Mock()

    def test_get_rest_api(self):
        self.client._api.get_rest_api = Mock(return_value={'foo': 'bar'})
        eq_(self.client.get_rest_api(None), None)
        eq_(self.client.get_rest_api('baz'), {'foo': 'bar'})

        self.client._api.get_rest_api = Mock(
            side_effect=botocore.exceptions.ClientError({'Error': {}}, 'bar'))
        eq_(self.client.get_rest_api('baz'), None)

    def test_get_export(self):
        m = Mock()
        m.read = Mock(return_value='{"foo": "bar"}')
        self.client._api.get_export = Mock(return_value={'body': m})
        eq_(self.client.get_export(None, 'baz'), {})
        eq_(self.client.get_export('baz', 'qux'), {'foo': 'bar'})

        self.client._api.get_export = Mock(
            side_effect=botocore.exceptions.ClientError({'Error': {}}, 'bar'))
        eq_(self.client.get_export('baz', 'qux'), {})

    def test_import_rest_api(self):
        self.client._api.import_rest_api = Mock(return_value={'foo': 'bar'})
        eq_(self.client.import_rest_api({'baz': 'qux'}), {'foo': 'bar'})

    def test_put_rest_api(self):

        self.client._api.put_rest_api = Mock(return_value={'foo': 'bar'})