def testURL(self): request = TestRequest() request._vh_root = support.site path = os.path.join(test_directory, 'testfiles') files = DirectoryResourceFactory(path, checker, 'test_files')(request) files.__parent__ = support.site file = files['test.gif'] self.assertEquals(file(), 'http://127.0.0.1/@@/test_files/test.gif')
def testURL(self): request = TestRequest() request._vh_root = support.site path = os.path.join(test_directory, 'testfiles') files = DirectoryResourceFactory(path, checker, 'test_files')(request) files.__parent__ = support.site file = files['test.gif'] self.assertEquals(file(), 'http://127.0.0.1/@@/test_files/test.gif')
def testURL3Level(self): request = TestRequest() request._vh_root = support.site ob.__parent__ = support.site ob.__name__ = 'ob' path = os.path.join(test_directory, 'testfiles') files = DirectoryResourceFactory(path, checker, 'test_files')(request) files.__parent__ = ob file = files['test.gif'] self.assertEquals(file(), 'http://127.0.0.1/@@/test_files/test.gif') subdir = files['subdir'] self.assert_(zapi.isinstance(subdir, DirectoryResource)) file = subdir['test.gif'] self.assertEquals(file(), 'http://127.0.0.1/@@/test_files/subdir/test.gif')
def testURL3Level(self): request = TestRequest() request._vh_root = support.site ob.__parent__ = support.site ob.__name__ = 'ob' path = os.path.join(test_directory, 'testfiles') files = DirectoryResourceFactory(path, checker, 'test_files')(request) files.__parent__ = ob file = files['test.gif'] self.assertEquals(file(), 'http://127.0.0.1/@@/test_files/test.gif') subdir = files['subdir'] self.assert_(proxy.isinstance(subdir, DirectoryResource)) file = subdir['test.gif'] self.assertEquals(file(), 'http://127.0.0.1/@@/test_files/subdir/test.gif')
def grok(self, name, factory, module_info, config, *kws): factory.module_info = module_info factory_name = factory.__name__.lower() # we need a path to the file containing the resource directory_name = util.class_annotation(factory, 'mars.resource.directory', '') directory = os.path.join(os.path.dirname(module_info.path), directory_name) if not os.path.isdir(directory): raise GrokError("No directory found for %s using path %s." " Please use mars.resource.directory" " to define path to the directory." % (factory.__name__, directory_name), factory) view_layer = determine_class_directive('grok.layer', factory, module_info, default=IDefaultBrowserLayer) view_name = util.class_annotation(factory, 'grok.name', factory_name) checker = NamesChecker(allowed_names) factory = DirectoryResourceFactory(directory, checker, view_name) adapts = (view_layer, ) config.action( discriminator=('adapter', adapts, IBrowserRequest, view_name), callable=zope.component.provideAdapter, args=(factory, adapts, IBrowserRequest, view_name), ) return True
def testProxy(self): path = os.path.join(test_directory, 'testfiles') request = TestRequest() factory = DirectoryResourceFactory(path, checker, 'testfiles') resource = factory(request) file = ProxyFactory(resource['test.txt']) self.assert_(isProxy(file))
def testGetitem(self): path = os.path.join(test_directory, 'testfiles') request = TestRequest() factory = DirectoryResourceFactory(path, checker, 'testfiles') resource = factory(request) self.assertRaises(KeyError, resource.__getitem__, 'doesnotexist') file = resource['test.txt']
def testNotFound(self): path = os.path.join(test_directory, 'testfiles') request = TestRequest() factory = DirectoryResourceFactory(path, checker, 'testfiles') resource = factory(request) self.assertRaises(NotFound, resource.publishTraverse, resource.request, 'doesnotexist') self.assertRaises(NotFound, resource.get, 'doesnotexist')
def testCorrectFactories(self): path = os.path.join(test_directory, 'testfiles') request = TestRequest() resource = DirectoryResourceFactory(path, checker, 'files')(request) image = resource['test.gif'] self.assert_(proxy.isinstance(image, FileResource)) template = resource['test.pt'] self.assert_(proxy.isinstance(template, PageTemplateResource)) file = resource['test.txt'] self.assert_(proxy.isinstance(file, FileResource)) file = resource['png'] self.assert_(proxy.isinstance(file, FileResource))