def test_static_buildtree(self): from ptah.view.resources import buildTree abspath, pkg = view.path('ptah.view.tests:static/dir2') self.assertEqual(buildTree(abspath), {'style.css': 1, 'text.txt': 1}) # do not include not allowed files abspath, pkg = view.path('ptah.view.tests:static/dir2') self.assertTrue('~test.html' not in buildTree(abspath)) # subtrees abspath, pkg = view.path('ptah.view.tests:static') self.assertEqual(buildTree(abspath), {os.path.join('dir1','style.css'): 1, os.path.join('dir1','subdir','text.txt'): 1, os.path.join('dir1','text2.txt'): 1, os.path.join('dir2','style.css'): 1, os.path.join('dir2','text.txt'): 1})
def command(self): # load all ptah packages pconfig = testing.setUp() config.initialize(pconfig, self._include, autoinclude=True) registry = config.get_cfg_storage(resources.STATIC_ID) if self.options.dump: basepath = self.options.dump.strip() if not os.path.exists(basepath): os.makedirs(basepath) if not os.path.isdir(basepath): print "Output path is not directory." return items = registry.items() items.sort() for name, (path, pkg) in items: print "* Coping from '%s' %s"%(pkg, path) d = resources.buildTree(path) di = d.items() di.sort() for p, _t in di: bp = os.path.join(basepath, name, p) dest_dir = os.path.split(bp)[0] if not os.path.exists(dest_dir): os.makedirs(dest_dir) forp = '%s/%s'%(pkg, p.split(pkg, 1)[-1]) if os.path.exists(bp): print ' skipping ../%s'%forp else: print ' coping ../%s'%forp shutil.copyfile(os.path.join(path, p), bp) print print basepath return # list static sections if self.options.section: items = registry.items() items.sort() for name, (path, pkg) in items: print grpTitleWrap.fill(name) print nameWrap.fill('by: %s'%pkg) p = path.split(pkg, 1)[-1] print nameTitleWrap.fill(' ../%s%s'%(pkg, p)) print
""" test for static assets api """ import unittest, os.path from ptah import config, view from ptah.view import resources from ptah.view.base import View from ptah.view.resources import buildTree from ptah.view.resources import StaticView from base import Base abspath1, pkg1 = view.path('ptah.view.tests:static/dir1') abspath2, pkg2 = view.path('ptah.view.tests:static/dir2') dirinfo1 = buildTree(abspath1) dirinfo2 = buildTree(abspath2) class TestStaticManagement(Base): def _setup_ptah(self): pass def test_static_registration_errors(self): self.assertRaises( ValueError, view.static, 'tests', 'ptah.view.tests:static/unknown---asdad') self.assertRaises( ValueError, view.static, 'tests', 'ptah.view.tests:static/dir1/style.css') def test_static_register(self):