def test_static_file(self): # stango.files.files_from_dir uses the stango.views.static_file view strip = self.data_path.count('/') + 2 path = os.path.join(self.data_path, 'static') self.manager.files += files_from_dir('foo', path, strip=strip) self.manager.generate(self.tmp) self.eq(filelist(self.tmp), [ 'foo/file.txt', 'foo/other.txt', ]) with open(os.path.join(self.tmp, 'foo/file.txt')) as fobj: self.eq(fobj.read(), 'This is a test file\n') with open(os.path.join(self.tmp, 'foo/other.txt')) as fobj: self.eq(fobj.read(), 'This is also a test file\n')
def test_static_file(self): # stango.files.files_from_dir uses the stango.views.static_file view strip = self.data_path.count('/') + 2 path = os.path.join(self.data_path, 'static') self.manager.files += files_from_dir('foo', path, strip=strip) self.manager.generate(self.tmp) self.eq( filelist(self.tmp), [ 'foo/file.txt', 'foo/other.txt', ] ) with open(os.path.join(self.tmp, 'foo/file.txt')) as fobj: self.eq(fobj.read(), 'This is a test file\n') with open(os.path.join(self.tmp, 'foo/other.txt')) as fobj: self.eq(fobj.read(), 'This is also a test file\n')
def test_files_from_dir_empty_basepath(self): path = os.path.join(self.data_path, 'static') files = files_from_dir('', path) self.eq( sorted((x.path, x.view, x.kwargs) for x in files), [ ( os.path.join(self.data_path, 'static/file.txt'), static_file, {'path': os.path.join(self.data_path, 'static/file.txt')}, ), ( os.path.join(self.data_path, 'static/other.txt'), static_file, {'path': os.path.join(self.data_path, 'static/other.txt')}, ), ], )
def test_files_from_dir_strip(self): strip = self.data_path.count('/') + 2 path = os.path.join(self.data_path, 'static') files = files_from_dir('foo', path, strip=strip) self.eq( sorted((x.path, x.view, x.kwargs) for x in files), [ ( 'foo/file.txt', static_file, {'path': os.path.join(self.data_path, 'static/file.txt')}, ), ( 'foo/other.txt', static_file, {'path': os.path.join(self.data_path, 'static/other.txt')}, ), ], )
return render_template('%s/index.html' % name, ctx) def redirect(context, url): return context.render_template('redirect.html', url=url) files = Files( # Index ('', render_template('index.html')), # About ('about/', render_template('about.html')), # Static files files_from_dir('', 'static', strip=1), # Blog blog.files, # Jansson ('jansson/', project('jansson')), # Sala ('sala/', project('sala')), # Stango ('stango/', project('stango')), # Autotoolized Lua ('autotoolized-lua/', project('autotoolized-lua')),