Beispiel #1
0
    def test_process_template_resnpose(self):

        from django.template.response import TemplateResponse

        from urlmiddleware import URLMiddleware

        request = self.factory.get('/foo/bar/')
        template_response = TemplateResponse(request, 'base.html')
        new = TemplateResponse(request, 'base.html')

        class MyTemplateResnponseViewMiddleware(object):
            def process_template_response(self, request, response):
                return new

        def mock_match(self, path, middleware_method=None):
            return [
                MyTemplateResnponseViewMiddleware(),
            ]

        with patch.object(URLMiddleware, 'get_matched_middleware', mock_match):

            m = URLMiddleware()

            self.assertEquals(
                m.process_template_response(request, template_response), new)
    def test_process_template_resnpose_no_op(self):

        from django.template.response import TemplateResponse

        from urlmiddleware import URLMiddleware

        class MyTemplateResnponseViewMiddleware(object):

            def process_template_response(self, request, response):
                return response

        def mock_match(self, path, middleware_method=None):
            return [MyTemplateResnponseViewMiddleware(), ]

        request = self.factory.get('/foo/bar/')
        template_response = TemplateResponse(request, 'base.html')

        with patch.object(URLMiddleware, 'get_matched_middleware', mock_match):

            m = URLMiddleware()

            self.assertEquals(m.process_template_response(request, template_response), template_response)