Exemplo n.º 1
0
    def test_stub_request(self):
        html_request = self.stub_request()
        js_request = self.stub_request(
            content_type='text/javascript', status=401, interfaces=IFoo)
        iface_request = self.stub_request(interfaces=[IFoo, IBar])

        self.replay()

        self.assertTrue(IDefaultBrowserLayer.providedBy(html_request))
        self.assertTrue(IBrowserRequest.providedBy(html_request))
        self.assertEqual(html_request.debug, False)
        self.assertEqual(html_request.response.getHeader(
                'Content-Type'), 'text/html')
        self.assertEqual(html_request.response.getStatus(), 200)

        self.assertTrue(IDefaultBrowserLayer.providedBy(js_request))
        self.assertTrue(IBrowserRequest.providedBy(js_request))
        self.assertTrue(IFoo.providedBy(js_request))
        self.assertEqual(js_request.debug, False)
        self.assertEqual(js_request.response.getHeader(
                'Content-Type'), 'text/javascript')
        self.assertEqual(js_request.response.getStatus(), 401)

        self.assertTrue(IFoo.providedBy(iface_request))
        self.assertTrue(IBar.providedBy(iface_request))
        self.assertTrue(IDefaultBrowserLayer.providedBy(iface_request))
        self.assertTrue(IBrowserRequest.providedBy(iface_request))
        self.assertEqual(html_request.debug, False)
        self.assertEqual(html_request.response.getHeader(
                'Content-Type'), 'text/html')
        self.assertEqual(html_request.response.getStatus(), 200)
Exemplo n.º 2
0
    def test_stub_request(self):
        html_request = self.stub_request()
        js_request = self.stub_request(content_type='text/javascript',
                                       status=401,
                                       interfaces=IFoo)
        iface_request = self.stub_request(interfaces=[IFoo, IBar])

        self.replay()

        self.assertTrue(IDefaultBrowserLayer.providedBy(html_request))
        self.assertTrue(IBrowserRequest.providedBy(html_request))
        self.assertEqual(html_request.debug, False)
        self.assertEqual(html_request.response.getHeader('Content-Type'),
                         'text/html')
        self.assertEqual(html_request.response.getStatus(), 200)

        self.assertTrue(IDefaultBrowserLayer.providedBy(js_request))
        self.assertTrue(IBrowserRequest.providedBy(js_request))
        self.assertTrue(IFoo.providedBy(js_request))
        self.assertEqual(js_request.debug, False)
        self.assertEqual(js_request.response.getHeader('Content-Type'),
                         'text/javascript')
        self.assertEqual(js_request.response.getStatus(), 401)

        self.assertTrue(IFoo.providedBy(iface_request))
        self.assertTrue(IBar.providedBy(iface_request))
        self.assertTrue(IDefaultBrowserLayer.providedBy(iface_request))
        self.assertTrue(IBrowserRequest.providedBy(iface_request))
        self.assertEqual(html_request.debug, False)
        self.assertEqual(html_request.response.getHeader('Content-Type'),
                         'text/html')
        self.assertEqual(html_request.response.getStatus(), 200)
Exemplo n.º 3
0
 def traverse(self, path, validated_hook):
     if IDefaultBrowserLayer.providedBy(self):
         return Object()
     else:
         tracer.exceptions['__call__'] = [ValueError]
         return Object()
Exemplo n.º 4
0
 def traverse(self, path, validated_hook):
     if IDefaultBrowserLayer.providedBy(self):
         return Object()
     else:
         tracer.exceptions['__call__'] = [ValueError]
         return Object()
Exemplo n.º 5
0
 def __init__(self, context, request):
     request = IBrowserRequest(request)
     if not IDefaultBrowserLayer.providedBy(request):
         interface.alsoProvides(request, IDefaultBrowserLayer)  # We lie
     super(resource, self).__init__(context, request)