def test_getResourceFor_wraps_render_wo_underlay_raises_no_method(self): root = Resource() maas = Resource() root.putChild(b"MAAS", maas) site = OverlaySite(root) request = DummyRequest([b"MAAS"]) resource = site.getResourceFor(request) self.assertThat(resource, Is(maas)) self.assertRaises(UnsupportedMethod, resource.render, request)
def test_getResourceFor_returns_resource_from_underlay(self): underlay_root = Resource() underlay_maas = Resource() underlay_root.putChild(b"MAAS", underlay_maas) overlay_root = Resource() site = OverlaySite(overlay_root) site.underlay = Site(underlay_root) request = DummyRequest([b"MAAS"]) resource = site.getResourceFor(request) self.assertThat(resource, Is(underlay_maas))
def test_getResourceFor_does_wrapper_render_not_wrapped(self): underlay_root = Resource() overlay_root = Resource() overlay_maas = Resource() original_render = overlay_maas.render overlay_root.putChild(b"MAAS", overlay_maas) site = OverlaySite(overlay_root) site.underlay = Site(underlay_root) request = DummyRequest([b"MAAS"]) resource = site.getResourceFor(request) self.assertIsNot(original_render, resource.render)
def test_getResourceFor_doesnt_wrapper_render_if_already_wrapped(self): underlay_root = Resource() overlay_root = Resource() overlay_maas = Resource() mock_render = self.patch(overlay_maas, "render") mock_render.__overlay_wrapped__ = True overlay_root.putChild(b"MAAS", overlay_maas) site = OverlaySite(overlay_root) site.underlay = Site(underlay_root) request = DummyRequest([b"MAAS"]) resource = site.getResourceFor(request) self.assertIs(mock_render, resource.render)
def test_getResourceFor_wraps_render_wo_underlay(self): root = Resource() maas = Resource() mock_render = self.patch(maas, "render") root.putChild(b"MAAS", maas) site = OverlaySite(root) request = DummyRequest([b"MAAS"]) resource = site.getResourceFor(request) self.assertThat(resource, Is(maas)) self.assertThat(resource.render, Not(Is(mock_render))) resource.render(request) self.assertThat(mock_render, MockCalledOnceWith(request))
def test_getResourceFor_calls_render_on_underlay_when_no_method(self): underlay_root = Resource() underlay_maas = Resource() mock_underlay_maas_render = self.patch(underlay_maas, "render") underlay_root.putChild(b"MAAS", underlay_maas) overlay_root = Resource() overlay_maas = Resource() overlay_root.putChild(b"MAAS", overlay_maas) site = OverlaySite(overlay_root) site.underlay = Site(underlay_root) request = DummyRequest([b"MAAS"]) resource = site.getResourceFor(request) resource.render(request) self.assertThat(mock_underlay_maas_render, MockCalledOnceWith(request))
def test_getResourceFor_returns_no_resource_wo_underlay(self): root = Resource() site = OverlaySite(root) request = DummyRequest([b"MAAS"]) resource = site.getResourceFor(request) self.assertThat(resource, IsInstance(NoResource))