'Tests that the XFrameOptionsMiddleware method that determines the
X-Frame-Options header value can be overridden based on something in
the request or response.'

def test_is_extendable(self):

    class OtherXFrameOptionsMiddleware(XFrameOptionsMiddleware, ):
        def get_xframe_options_value(self, request, response):
            if getattr(request, u'sameorigin', False):
                return u'SAMEORIGIN'
            if getattr(response, u'sameorigin', False):
                return u'SAMEORIGIN'
            return u'DENY'
    with override_settings(X_FRAME_OPTIONS=u'DENY'):
        response = HttpResponse()
        response.sameorigin = True
        r = OtherXFrameOptionsMiddleware().process_response(HttpRequest(), response)
        self.assertEqual(r[u'X-Frame-Options'], u'SAMEORIGIN')
        request = HttpRequest()
        request.sameorigin = True
        r = OtherXFrameOptionsMiddleware().process_response(request, HttpResponse())
        self.assertEqual(r[u'X-Frame-Options'], u'SAMEORIGIN')
    with override_settings(X_FRAME_OPTIONS=u'SAMEORIGIN'):
        r = OtherXFrameOptionsMiddleware().process_response(HttpRequest(), HttpResponse())
        self.assertEqual(r[u'X-Frame-Options'], u'DENY')
