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', ))
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',))
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))
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})
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)
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})
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])
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"))])
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])
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"))])