This file is indexed.

/usr/lib/python2.7/dist-packages/oslo_middleware/tests/test_base.py is in python-oslo.middleware 3.34.0-0ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
# Copyright (c) 2015 Hewlett-Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# 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.

import webob

from oslo_middleware.base import ConfigurableMiddleware
from oslo_middleware.base import Middleware
from oslotest.base import BaseTestCase


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


class TestBase(BaseTestCase):
    """Test the base middleware class."""

    def test_extend_with_request(self):
        """Assert that a newer middleware behaves as appropriate.

        This tests makes sure that the request is passed to the
        middleware's implementation.
        """
        # Bootstrap the application
        self.application = RequestBase(application)

        # Send a request through.
        request = webob.Request({}, method='GET')
        request.get_response(self.application)

        self.assertTrue(self.application.called_with_request)

    def test_extend_without_request(self):
        """Assert that an older middleware behaves as appropriate.

        This tests makes sure that the request method is NOT passed to the
        middleware's implementation, and that there are no other expected
        errors.
        """
        # Bootstrap the application
        self.application = NoRequestBase(application)

        # Send a request through.
        request = webob.Request({}, method='GET')
        request.get_response(self.application)

        self.assertTrue(self.application.called_without_request)

    def test_no_content_type_added(self):
        class TestMiddleware(Middleware):
            @staticmethod
            def process_request(req):
                return "foobar"

        m = TestMiddleware(None)
        request = webob.Request({}, method='GET')
        response = request.get_response(m)
        self.assertNotIn('Content-Type', response.headers)

    def test_paste_deploy_legacy(self):
        app = LegacyMiddlewareTest.factory(
            {'global': True}, local=True)(application)
        self.assertEqual({}, app.conf)

    def test_paste_deploy_configurable(self):
        app = ConfigurableMiddlewareTest.factory(
            {'global': True}, local=True)(application)
        self.assertEqual({'global': True, 'local': True}, app.conf)


class NoRequestBase(Middleware):
    """Test middleware, implements old model."""
    def process_response(self, response):
        self.called_without_request = True
        return response


class RequestBase(Middleware):
    """Test middleware, implements new model."""
    def process_response(self, response, request):
        self.called_with_request = True
        return response


class ConfigurableMiddlewareTest(ConfigurableMiddleware):
    pass


class LegacyMiddlewareTest(Middleware):
    pass