# Path: oslo_middleware/catch_errors.py
# LOG = logging.getLogger(__name__)
# _TOKEN_RE = re.compile(r'^(X-\w+-Token):.*$', flags=re.MULTILINE)
# class CatchErrors(base.ConfigurableMiddleware):
#     def __call__(self, req):


from unittest import mock
from oslotest import base as test_base
from oslo_middleware import catch_errors
import fixtures
import webob.dec
import webob.exc
#    distributed under the License is distributed on an "AS IS" BASIS, 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.





class CatchErrorsTest(test_base.BaseTestCase):

    def _test_has_request_id(self, application, expected_code=None):
        app = catch_errors.CatchErrors(application)
        req = webob.Request.blank('/test')
        req.environ['HTTP_X_AUTH_TOKEN'] = 'hello=world'
        res = req.get_response(app)
        self.assertEqual(expected_code, res.status_int)

    def test_success_response(self):
        @webob.dec.wsgify
        def application(req):
            return 'Hello, World!!!'

        self._test_has_request_id(application, webob.exc.HTTPOk.code)

    def test_internal_server_error(self):
        @webob.dec.wsgify
        def application(req):
            raise Exception()


# Path: oslo_middleware/catch_errors.py
# LOG = logging.getLogger(__name__)
# _TOKEN_RE = re.compile(r'^(X-\w+-Token):.*$', flags=re.MULTILINE)
# class CatchErrors(base.ConfigurableMiddleware):
#     def __call__(self, req):


# Path: oslo_middleware/tests/test_catch_errors.py
from unittest import mock
from oslotest import base as test_base
from oslo_middleware import catch_errors
import fixtures
import webob.dec
import webob.exc

#    distributed under the License is distributed on an "AS IS" BASIS, 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.





class CatchErrorsTest(test_base.BaseTestCase):

    def _test_has_request_id(self, application, expected_code=None):
        app = catch_errors.CatchErrors(application)
        req = webob.Request.blank('/test')
        req.environ['HTTP_X_AUTH_TOKEN'] = 'hello=world'
        res = req.get_response(app)
        self.assertEqual(expected_code, res.status_int)

    def test_success_response(self):
        @webob.dec.wsgify
        def application(req):
            return 'Hello, World!!!'

        self._test_has_request_id(application, webob.exc.HTTPOk.code)

    def test_internal_server_error(self):
        @webob.dec.wsgify
        def application(req):
            raise Exception()


        with mock.patch.object(catch_errors.LOG, 'exception') as log_exc: