def check(self, path): gene_html( file(os.path.join(self.textdir, path)).read(), settings_overrides={ # ignore docutils system errors 'report_level': 4, })
def save(page_path): if request.form.get('save') == 'Save': page_text = request.form['page_text'] if get_page_text(page_path) == page_text: flash('No change was found.') return redirect(url_for("page", page_path=page_path)) g.db.execute( 'insert or replace into pages (page_path, page_text)' ' values (?, ?)', [page_path, page_text]) g.db.execute( 'insert into page_history (page_path, page_text) values (?, ?)', [page_path, page_text]) g.db.commit() search.update(get_search_index(), page_path, page_text) flash('Saved!') return redirect(url_for("page", page_path=page_path)) elif request.form.get('preview') == 'Preview': page_text = request.form['page_text'] page_html = gene_html(page_text, page_path, _debug=app.config['DEBUG']) if get_page_text(page_path) == page_text: flash('Previewing... No change was found.') else: flash('Previewing... Not yet saved!') return render_template("preview.html", title=path_as_title(page_path), page_path=page_path, page_text=page_text, page_html=page_html) elif request.form.get('cancel') == 'Cancel': flash('Discarded changes!') return redirect(url_for("page", page_path=page_path)) elif request.form.get('delete') == 'Delete': return redirect(url_for("confirm_delete", page_path=page_path))
def check(self, dirdata, file_tree, links, errors=[]): page_text = self.genedir(**dirdata) page_path = 'it does not depend on the page_path' web = MockWeb() DictTable = MockDictTable.new_mock(file_tree) glob_list = Mock(return_value=sorted(file_tree)) setup_wiki(web=web, DictTable=DictTable, glob_list=glob_list) with CaptureStdIO() as stdio: page_html = gene_html(page_text, page_path, _debug=True) stderr = stdio.read_stderr() for key in dirdata['data'].split(): td_tag = '<td>{0}</td>'.format(key) num_td = page_html.count(td_tag) num_data = len(filter(lambda d: key in d, file_tree.itervalues())) eq_( num_td, num_data, "there must be #{0} of '{2}'. #{1} exists".format( num_data, num_td, td_tag)) for link in links: assert '{0}</a>'.format(link) in page_html for error in errors: assert escape(error, True) in page_html assert error in stderr if not errors: assert not stderr
def check(self, dirdata, file_tree, links, errors=[]): page_text = self.genedir(**dirdata) page_path = 'it does not depend on the page_path' web = MockWeb() DictTable = MockDictTable.new_mock(file_tree) glob_list = Mock(return_value=sorted(file_tree)) setup_wiki(web=web, DictTable=DictTable, glob_list=glob_list) with CaptureStdIO() as stdio: page_html = gene_html(page_text, page_path, _debug=True) stderr = stdio.read_stderr() for key in dirdata['data'].split(): td_tag = '<td>{0}</td>'.format(key) num_td = page_html.count(td_tag) num_data = len(filter(lambda d: key in d, file_tree.itervalues())) eq_(num_td, num_data, "there must be #{0} of '{2}'. #{1} exists".format( num_data, num_td, td_tag)) for link in links: assert '{0}</a>'.format(link) in page_html for error in errors: assert escape(error, True) in page_html assert error in stderr if not errors: assert not stderr
def get_page_text_and_html(page_path): page_text = get_page_text(page_path) if page_text: page_html = gene_html(page_text, page_path, _debug=app.config['DEBUG']) else: page_html = '' return (page_text, page_html)
def old(page_path, history_id): page_text = g.db.execute( 'select page_text from page_history where history_id = ?', [history_id]).fetchone() page_html = gene_html(page_text[0], page_path, _debug=app.config['DEBUG']) return render_template("page.html", title=path_as_title(page_path), page_path=page_path, page_html=page_html)
def check(self, page_path, list_descendants): page_text = '.. list-pages::' web = MockWeb(list_descendants=list_descendants) DictTable = None # it will not be called glob_list = None # it will not be called setup_wiki(web=web, DictTable=DictTable, glob_list=glob_list) page_html = gene_html(page_text, page_path, _debug=True) web.list_descendants.assert_called_with(page_path) for subpage in list_descendants: assert subpage in page_html
def check(self, page_text, file_tree, stats): page_path = 'it does not depend on the page_path' web = MockWeb() DictTable = MockDictTable.new_mock(file_tree) glob_list = Mock(return_value=sorted(file_tree)) setup_wiki(web=web, DictTable=DictTable, glob_list=glob_list) page_html = gene_html(page_text, page_path) for (key, val) in stats.iteritems(): eq_(page_html.count(key), val, "page_html must contains %d of '%s'" % (val, key))
def check(self, list_descendants): page_path = 'it does not depend on the page_path' page_text = ".. list-pages::" web = MockWeb(list_descendants=list_descendants) DictTable = object() # DictTable should not be used setup_wiki(web=web, DictTable=DictTable) page_html = gene_html(page_text, page_path) assert 'List of Pages' in page_html html_format = 'href="%(link)s">%(link)s</a>' for sub_link in list_descendants: html_str = html_format % {'link': sub_link} assert html_str in page_html
def check(self, dirdata, files): page_text = self.genedir(**dirdata) page_path = 'it does not depend on the page_path' web = MockWeb() DictTable = None # it will not be called glob_list = Mock(return_value=sorted(files)) setup_wiki(web=web, DictTable=DictTable, glob_list=glob_list) page_html = gene_html(page_text, page_path, _debug=True) datadir = web.app.config['DATADIRPATH'] base_syspath = os.path.join(datadir, dirdata.get('base', '')) glob_list.assert_called_with( map(lambda arg: os.path.join(base_syspath, arg), dirdata['args'])) eq_(page_html.count('<img'), len(files))
def check(self, page_text, file_tree, dictdiff, links): page_path = 'it does not depend on the page_path' web = MockWeb() DictTable = MockDictTable.new_mock(file_tree) glob_list = Mock(return_value=sorted(file_tree)) setup_wiki(web=web, DictTable=DictTable, glob_list=glob_list) page_html = gene_html(page_text, page_path) for key in dictdiff: assert key in page_html if links: for link in links: assert '%s</a>' % link in page_html elif links == []: assert 'link(s)' not in page_html
def gene_from_template(page_path): (temp_path, match) = find_temp_path(page_path) if match: (page_text, tb_text, ) = gene_text_from_temp(page_path, temp_path, match, _mix=False, _debug=app.config['DEBUG']) if page_text is None: page_html = tb_text else: page_html = gene_html(page_text, page_path, _debug=app.config['DEBUG']) return render_template("page.html", title=path_as_title(page_path), temp_path=temp_path, page_path=page_path, page_html=page_html)
def check(self, page_text, links, not_links): page_path = 'it does not depend on the page_path' web = object() # web shuold not be used DictTable = object() # DictTable should not be used setup_wiki(web=web, DictTable=DictTable) page_html = gene_html(page_text, page_path, settings_overrides={ # ignore docutils system errors 'report_level': 4, }) def html_link(link): return 'href="%(link)s">%(link)s</a>' % {'link': link} for l in links: assert html_link(l) in page_html, \ "link '%s' should be in `page_html`" % l for l in not_links: assert html_link(l) not in page_html, \ "link '%s' should NOT be in `page_html`" % l
def check(self, page_text, links, not_links): page_path = 'it does not depend on the page_path' web = object() # web shuold not be used DictTable = object() # DictTable should not be used setup_wiki(web=web, DictTable=DictTable) page_html = gene_html( page_text, page_path, settings_overrides={ # ignore docutils system errors 'report_level': 4, }) def html_link(link): return 'href="%(link)s">%(link)s</a>' % {'link': link} for l in links: assert html_link(l) in page_html, \ "link '%s' should be in `page_html`" % l for l in not_links: assert html_link(l) not in page_html, \ "link '%s' should NOT be in `page_html`" % l
def gene_from_template(page_path): (temp_path, match) = find_temp_path(page_path) if match: ( page_text, tb_text, ) = gene_text_from_temp(page_path, temp_path, match, _mix=False, _debug=app.config['DEBUG']) if page_text is None: page_html = tb_text else: page_html = gene_html(page_text, page_path, _debug=app.config['DEBUG']) return render_template("page.html", title=path_as_title(page_path), temp_path=temp_path, page_path=page_path, page_html=page_html)
def test_gene_html_no_fail(): exception_message = ( '`gene_html` should not fail whatever happen during the ' 'html generation, provided DEBUG=False') page_text = trim(""" .. dictdiff:: * dictdiff is for raising Exception via DictTable """) page_path = 'it does not depend on the page_path' web = MockWeb() DictTable = Mock() DictTable.from_path_list = Mock( side_effect=CheckException(exception_message)) glob_list = Mock(return_value=[]) setup_wiki(web=web, DictTable=DictTable, glob_list=glob_list) # error must be suppressed when _debug=False page_html = gene_html(page_text, page_path, _debug=False) assert exception_message in page_html # TB will be returned # error must NOT be suppressed when _debug=True assert_raises(CheckException, gene_html, page_text, page_path, _debug=True)
def save(page_path): if request.form.get('save') == 'Save': page_text = request.form['page_text'] if get_page_text(page_path) == page_text: flash('No change was found.') return redirect(url_for("page", page_path=page_path)) g.db.execute( 'insert or replace into pages (page_path, page_text)' ' values (?, ?)', [page_path, page_text]) g.db.execute( 'insert into page_history (page_path, page_text) values (?, ?)', [page_path, page_text]) g.db.commit() search.update(get_search_index(), page_path, page_text) flash('Saved!') return redirect(url_for("page", page_path=page_path)) elif request.form.get('preview') == 'Preview': page_text = request.form['page_text'] page_html = gene_html(page_text, page_path, _debug=app.config['DEBUG']) if get_page_text(page_path) == page_text: flash('Previewing... No change was found.') else: flash('Previewing... Not yet saved!') return render_template( "preview.html", title=path_as_title(page_path), page_path=page_path, page_text=page_text, page_html=page_html) elif request.form.get('cancel') == 'Cancel': flash('Discarded changes!') return redirect(url_for("page", page_path=page_path)) elif request.form.get('delete') == 'Delete': return redirect(url_for("confirm_delete", page_path=page_path))
def check(self, dirdata, file_tree, links, errors=[]): page_text = self.genedir(**dirdata) page_path = 'it does not depend on the page_path' web = MockWeb() DictTable = MockDictTable.new_mock(file_tree) glob_list = Mock(return_value=sorted(file_tree)) setup_wiki(web=web, DictTable=DictTable, glob_list=glob_list) with CaptureStdIO() as stdio: page_html = gene_html(page_text, page_path, _debug=True) stderr = stdio.read_stderr() for key in dirdata['data'].split(): td_tag = '<td>{0}</td>'.format(key) assert td_tag in page_html for link in links: assert '{0}</a>'.format(link) in page_html for error in errors: assert escape(error, True) in page_html assert error in stderr if not errors: assert not stderr
def check(self, path): gene_html(file(os.path.join(self.textdir, path)).read(), settings_overrides={ # ignore docutils system errors 'report_level': 4, })
def gene_html_with_encode(*args, **kwds): return gene_html(*args, **kwds).encode('utf-8')