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_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"))])