Example #1
0
    def test_confusedNewPlugin(self):
        """
        If L{UnguardedWrapper.locateChild} discovers a plugin that implements
        both C{sessionlessProduceResource} and C{resourceFactory}, it should
        prefer the new C{sessionlessProduceResource} method and return that
        resource.
        """
        wrapper = UnguardedWrapper(self.store, None)
        req = FakeRequest()
        test = self
        segments = ('foo', 'bar')
        result = object()
        calledWith = []

        class SiteRootPlugin(object):
            def resourceFactory(self, segments):
                test.fail("Don't call this.")

            def sessionlessProduceResource(self, request, segments):
                calledWith.append((request, segments))
                return result, segments[1:]

        self.store.inMemoryPowerUp(SiteRootPlugin(),
                                   ISessionlessSiteRootPlugin)

        resource, resultSegments = wrapper.locateChild(req, segments)
        self.assertEqual(calledWith, [(req, segments)])
        self.assertIdentical(resource, result)
        self.assertEqual(resultSegments, ('bar', ))
Example #2
0
    def test_confusedNewPlugin(self):
        """
        If L{UnguardedWrapper.locateChild} discovers a plugin that implements
        both C{sessionlessProduceResource} and C{resourceFactory}, it should
        prefer the new C{sessionlessProduceResource} method and return that
        resource.
        """
        wrapper = UnguardedWrapper(self.store, None)
        req = FakeRequest()
        test = self
        segments = ('foo', 'bar')
        result = object()
        calledWith = []
        class SiteRootPlugin(object):
            def resourceFactory(self, segments):
                test.fail("Don't call this.")
            def sessionlessProduceResource(self, request, segments):
                calledWith.append((request, segments))
                return result, segments[1:]
        self.store.inMemoryPowerUp(SiteRootPlugin(), ISessionlessSiteRootPlugin)

        resource, resultSegments = wrapper.locateChild(req, segments)
        self.assertEqual(calledWith, [(req, segments)])
        self.assertIdentical(resource, result)
        self.assertEqual(resultSegments, ('bar',))
Example #3
0
 def test_live(self):
     """
     L{UnguardedWrapper} has a I{live} child which returns a L{LivePage}
     instance.
     """
     request = FakeRequest(uri='/live/foo', currentSegments=[])
     wrapper = UnguardedWrapper(self.store, None)
     resource = wrapper.child_live(request)
     self.assertTrue(isinstance(resource, LivePage))
Example #4
0
 def test_live(self):
     """
     L{UnguardedWrapper} has a I{live} child which returns a L{LivePage}
     instance.
     """
     request = FakeRequest(uri='/live/foo', currentSegments=[])
     wrapper = UnguardedWrapper(self.store, None)
     resource = wrapper.child_live(request)
     self.assertTrue(isinstance(resource, LivePage))
Example #5
0
 def test_static(self):
     """
     L{UnguardedWrapper} has a I{static} child which returns a
     L{StaticContent} instance.
     """
     request = FakeRequest(uri='/static/extra', currentSegments=[])
     wrapper = UnguardedWrapper(self.store, None)
     resource = wrapper.child_static(request)
     self.assertTrue(isinstance(resource, StaticContent))
     self.assertEqual(resource.staticPaths,
                      {baseOffering.name: baseOffering.staticContentPath})
Example #6
0
    def test_jsmodules(self):
        """
        L{UnguardedWrapper} has a I{__jsmodules__} child which returns a
        L{LivePage} instance.
        """
        request = FakeRequest(uri='/__jsmodule__/foo', currentSegments=[])
        wrapper = UnguardedWrapper(None, None)
        resource = wrapper.child___jsmodule__(request)

        # This is weak.  Identity of this object doesn't matter.  The caching
        # and jsmodule serving features are what matter. -exarkun
        self.assertIdentical(resource, theHashModuleProvider)
Example #7
0
 def test_static(self):
     """
     L{UnguardedWrapper} has a I{static} child which returns a
     L{StaticContent} instance.
     """
     request = FakeRequest(uri='/static/extra', currentSegments=[])
     wrapper = UnguardedWrapper(self.store, None)
     resource = wrapper.child_static(request)
     self.assertTrue(isinstance(resource, StaticContent))
     self.assertEqual(
         resource.staticPaths,
         {baseOffering.name: baseOffering.staticContentPath})
Example #8
0
    def test_jsmodules(self):
        """
        L{UnguardedWrapper} has a I{__jsmodules__} child which returns a
        L{LivePage} instance.
        """
        request = FakeRequest(uri='/__jsmodule__/foo', currentSegments=[])
        wrapper = UnguardedWrapper(None, None)
        resource = wrapper.child___jsmodule__(request)

        # This is weak.  Identity of this object doesn't matter.  The caching
        # and jsmodule serving features are what matter. -exarkun
        self.assertIdentical(resource, theHashModuleProvider)
Example #9
0
    def test_sessionlessLegacyPlugin(self):
        """
        L{UnguardedWrapper.locateChild} honors old-style
        L{ISessionlessSiteRootPlugin} providers that only implement a
        C{resourceFactory} method.
        """
        wrapper = UnguardedWrapper(self.store, None)
        req = FakeRequest()
        segments = ('foo', 'bar')
        calledWith = []
        result = object()
        class SiteRootPlugin(object):
            def resourceFactory(self, segments):
                calledWith.append(segments)
                return result
        self.store.inMemoryPowerUp(SiteRootPlugin(), ISessionlessSiteRootPlugin)

        wrapper.locateChild(req, segments)
        self.assertEqual(calledWith, [segments])
Example #10
0
    def test_sessionlessPlugin(self):
        """
        L{UnguardedWrapper.locateChild} looks up L{ISessionlessSiteRootPlugin}
        powerups on its store, and invokes their C{sessionlessProduceResource}
        methods to discover resources.
        """
        wrapper = UnguardedWrapper(self.store, None)
        req = FakeRequest()
        segments = ('foo', 'bar')
        calledWith = []
        result = object()
        class SiteRootPlugin(object):
            def sessionlessProduceResource(self, request, segments):
                calledWith.append((request, segments))
                return result
        self.store.inMemoryPowerUp(SiteRootPlugin(), ISessionlessSiteRootPlugin)

        wrapper.locateChild(req, segments)
        self.assertEqual(calledWith, [(req, ("foo", "bar"))])
Example #11
0
    def test_sessionlessLegacyPlugin(self):
        """
        L{UnguardedWrapper.locateChild} honors old-style
        L{ISessionlessSiteRootPlugin} providers that only implement a
        C{resourceFactory} method.
        """
        wrapper = UnguardedWrapper(self.store, None)
        req = FakeRequest()
        segments = ('foo', 'bar')
        calledWith = []
        result = object()

        class SiteRootPlugin(object):
            def resourceFactory(self, segments):
                calledWith.append(segments)
                return result

        self.store.inMemoryPowerUp(SiteRootPlugin(),
                                   ISessionlessSiteRootPlugin)

        resource = wrapper.locateChild(req, segments)
        self.assertEqual(calledWith, [segments])
Example #12
0
    def test_sessionlessPlugin(self):
        """
        L{UnguardedWrapper.locateChild} looks up L{ISessionlessSiteRootPlugin}
        powerups on its store, and invokes their C{sessionlessProduceResource}
        methods to discover resources.
        """
        wrapper = UnguardedWrapper(self.store, None)
        req = FakeRequest()
        segments = ('foo', 'bar')
        calledWith = []
        result = object()

        class SiteRootPlugin(object):
            def sessionlessProduceResource(self, request, segments):
                calledWith.append((request, segments))
                return result

        self.store.inMemoryPowerUp(SiteRootPlugin(),
                                   ISessionlessSiteRootPlugin)

        resource = wrapper.locateChild(req, segments)
        self.assertEqual(calledWith, [(req, ("foo", "bar"))])