def test_lookup_ct(self): filter_ct = dict(callable="outpost.filterinc.replacestr", apply_to=None, path=None, content_type="text/html", settings={ "str": "<body>", "new": "<body>Updated!" }, name="Filter example") fc = filtermanager.FilterConf.fromDict(filter_ct) response = testing.DummyRequest().response response.content_type = "text/html" request = testing.DummyRequest() request.registry.settings = {"filter": (fc, )} filter = [ f for f in filtermanager.lookupFilter("post", response, request, request.url) ] self.assertTrue(len(filter) == 1) response.content_type = "image/png" filter = [ f for f in filtermanager.lookupFilter("post", response, request, request.url) ] self.assertTrue(len(filter) == 0)
def test_lookup_ct(self): filter_ct = dict( callable = "outpost.filterinc.replacestr", apply_to = None, path = None, content_type = "text/html", settings = {"str": "<body>", "new": "<body>Updated!"}, name = "Filter example" ) fc = filtermanager.FilterConf.fromDict(filter_ct) response = testing.DummyRequest().response response.content_type = "text/html" request = testing.DummyRequest() request.registry.settings = {"filter": (fc,)} filter = [f for f in filtermanager.lookupFilter("post", response, request, request.url)] self.assert_(len(filter)==1) response.content_type = "image/png" filter = [f for f in filtermanager.lookupFilter("post", response, request, request.url)] self.assert_(len(filter)==0)
def test_lookup_path(self): filter_path = dict( callable = "outpost.filterinc.replacestr", apply_to = None, path = "index\.html", content_type = None, settings = {"str": "<body>", "new": "<body>Updated!"}, name = "Filter example" ) fc = filtermanager.FilterConf.fromDict(filter_path) response = testing.DummyRequest().response request = testing.DummyRequest() request.url = "http://localhost/files/index.html" request.registry.settings = {"filter": (fc,)} filter = [f for f in filtermanager.lookupFilter("post", response, request, request.url)] self.assert_(len(filter)==1) request.url = "http://localhost/files/image.png" filter = [f for f in filtermanager.lookupFilter("post", response, request, request.url)] self.assert_(len(filter)==0)
def test_lookup_proxy(self): filter_proxy = dict( callable = "outpost.filterinc.replacestr", apply_to = "proxy", path = None, content_type = None, settings = {"str": "<body>", "new": "<body>Updated!"}, name = "Filter example" ) fc = filtermanager.FilterConf.fromDict(filter_proxy) response = testing.DummyRequest().response directlyProvides(response, filtermanager.IProxyRequest) request = testing.DummyRequest() request.registry.settings = {"filter": (fc,)} filter = [f for f in filtermanager.lookupFilter("post", response, request, request.url)] self.assert_(len(filter)==1)
def test_lookup_all(self): filter_all = dict( callable = "outpost.filterinc.replacestr", apply_to = "file", path = "index\.html", content_type = "text/*", settings = {"str": "<body>", "new": "<body>Updated!"}, name = "Filter example" ) fc = filtermanager.FilterConf.fromDict(filter_all) response = testing.DummyRequest().response response.content_type = "text/html" directlyProvides(response, filtermanager.IFileRequest) request = testing.DummyRequest() request.url = "http://localhost/files/index.html" request.registry.settings = {"filter": (fc,)} filter = [f for f in filtermanager.lookupFilter("post", response, request, request.url)] self.assert_(len(filter)==1)
def test_lookup_proxy(self): filter_proxy = dict(callable="outpost.filterinc.replacestr", apply_to="proxy", path=None, content_type=None, settings={ "str": "<body>", "new": "<body>Updated!" }, name="Filter example") fc = filtermanager.FilterConf.fromDict(filter_proxy) response = testing.DummyRequest().response directlyProvides(response, filtermanager.IProxyRequest) request = testing.DummyRequest() request.registry.settings = {"filter": (fc, )} filter = [ f for f in filtermanager.lookupFilter("post", response, request, request.url) ] self.assertTrue(len(filter) == 1)
def test_lookup_all(self): filter_all = dict(callable="outpost.filterinc.replacestr", apply_to="file", path="index\.html", content_type="text/*", settings={ "str": "<body>", "new": "<body>Updated!" }, name="Filter example") fc = filtermanager.FilterConf.fromDict(filter_all) response = testing.DummyRequest().response response.content_type = "text/html" directlyProvides(response, filtermanager.IFileRequest) request = testing.DummyRequest() request.url = "http://localhost/files/index.html" request.registry.settings = {"filter": (fc, )} filter = [ f for f in filtermanager.lookupFilter("post", response, request, request.url) ] self.assertTrue(len(filter) == 1)