def test_get_versions(self): """ Assert that a path can get all versions """ pages = [ self.page_1, self.page_2, self.page_3, self.page_4 ] pages_1 = Page.get_versions(self.page_1.path, pages) pages_2 = Page.get_versions(self.page_2.path, pages) pages_3 = Page.get_versions(self.page_3.path, pages) pages_4 = Page.get_versions(self.page_4.path, pages) assert self.page_1 in pages_1 assert self.page_2 not in pages_1 assert self.page_3 not in pages_1 assert self.page_4 not in pages_1 assert self.page_1 not in pages_2 assert self.page_2 in pages_2 assert self.page_3 in pages_2 assert self.page_4 not in pages_2 assert self.page_1 not in pages_3 assert self.page_2 in pages_3 assert self.page_3 in pages_3 assert self.page_4 not in pages_3 assert self.page_1 not in pages_4 assert self.page_2 not in pages_4 assert self.page_3 not in pages_4 assert self.page_4 in pages_4
def test_highest_version_of_file(self): """ Assert that get_highest_version_of_file_path gets the highest version for all paths """ assert Page.get_highest_version_of_file_path(self.page_1.path) == self.page_1.path assert Page.get_highest_version_of_file_path(self.page_2.path) == self.page_3.path assert Page.get_highest_version_of_file_path(self.page_3.path) == self.page_3.path assert Page.get_highest_version_of_file_path(self.page_4.path) == self.page_4.path
def setUp(self): super(PageTestCase, self).setUp() page_path_1 = self.create_file(PAGE_NAME_1, PAGE_CONTENT_1) page_path_2 = self.create_file(PAGE_NAME_2, PAGE_CONTENT_2) page_path_3 = self.create_file(PAGE_NAME_3, PAGE_CONTENT_3) page_path_4 = self.create_file(PAGE_NAME_4, PAGE_CONTENT_4) self.page_1 = Page(page_path_1, URL_1) self.page_2 = Page(page_path_2, URL_2) self.page_3 = Page(page_path_3, URL_3) self.page_4 = Page(page_path_4, URL_4)
def home(): pages = current_wiki.index() page = Page.get_highest_page_from_unversioned_file(pages, 'home') # page = current_wiki.get('home') if page: return display(page.url) return render_template('home.html')
def search(self, term, ignore_case=True): try: results = self.repo.grep(term, G=True, i=ignore_case).split('\n') # split filename:match for file names only (matched text can be # used to output in the future). return [Page(self, r.split(':')[0][:-3]) for r in results] except git.exc.GitCommandError: return super(WikiGit, self).search(term)
def get_archived_pages(page): """ Given page P, returns array of archive pages for P :param page: Wiki Page Object :return: page[] - Array of wiki page objects in archive """ purge_old_pages(page) pages = [] archive_dir = get_file_archive_dir(page.path) if path.isdir(archive_dir): for file in listdir(archive_dir): p = path.join(archive_dir, file) new_page = Page(p, get_page_url_from_path(p)) new_page.title = datetime.strptime( remove_file_extension(file), DEFAULT_DATE_FORMAT).strftime(DISPLAY_DATE_FORMAT) pages.append(new_page) return pages
def delete(url): page = current_wiki.get_or_404(url) all_pages = current_wiki.index() pages = Page.get_versions(page.path, all_pages) for p in pages: current_wiki.delete(p.url) flash('Page "%s" was deleted.' % page.title, 'success') return redirect(url_for('wiki.home'))
def tag(name): tagged = current_wiki.index_by_tag(name) new_pages = [] for t in tagged: p = Page.get_highest_version_of_file_path(t.path) if t.path == p and t not in new_pages: new_pages.append(t) return render_template('tag.html', pages=new_pages, tag=name)
def search(): form = SearchForm() if form.validate_on_submit(): results = current_wiki.search(form.term.data, form.ignore_case.data) results = Page.filter_old_versions(results) return render_template('search.html', form=form, results=results, search=form.term.data) return render_template('search.html', form=form, search=None)
class TestWiki(WikiBaseTestCase): dir_path = os.path.dirname(os.path.realpath(__package__)) page = Page(dir_path + '/content/test') def test_search(self): term = "interesting" matched = self.wiki.search(term) print matched # --> []
def tags(): ts = current_wiki.get_tags() new_tags = {} for t in ts: if t not in new_tags: new_tags[t] = [] for p in ts[t]: page = Page.get_highest_version_of_file_path(p.path) if page not in new_tags[t]: new_tags[t].append(page) return render_template('tags.html', tags=new_tags)
def versions(url): """ @file: routes.py @author: Dustin Gulley @date: 04/08/2018 Returns all page versions of a specified url 'myfile_v1' -> [Page with 'path/to/myfile_v1.txt', Page with 'path/to/myfile_v2.txt'] """ page = current_wiki.get(url) all_pages = current_wiki.index() pages = Page.get_versions(page.path, all_pages) return render_template('versions.html', pages=pages)
class PageTestCase(WikiBaseTestCase): """ Contains various tests for the :class:`~wiki.core.Page` class. """ page_content = PAGE_CONTENT def setUp(self): super(PageTestCase, self).setUp() self.page_path = self.create_file('test.md', self.page_content) self.page = Page(self.page_path, 'test') def test_page_loading(self): """ Assert that content is loaded correctly from disk. """ assert self.page.content == PAGE_CONTENT def test_page_meta(self): """ Assert meta data is interpreted correctly. """ assert self.page.title == u'Test' assert self.page.tags == u'one, two, 3, jö' def test_page_saving(self): """ Assert that saving a page back to disk persists it correctly. """ self.page.save() with open(self.page_path, 'r', encoding='utf-8') as fhd: saved = fhd.read() assert saved == self.page_content
def test_filter_old_versions(self): """ Assert that old versions are filtered from pages. """ pages = [ self.page_1, self.page_2, self.page_3, self.page_4 ] filtered_pages = Page.filter_old_versions(pages) assert self.page_1 in filtered_pages assert self.page_2 not in filtered_pages assert self.page_3 in filtered_pages assert self.page_4 in filtered_pages
def move(url): page = current_wiki.get_or_404(url) form = URLForm(obj=page) if form.validate_on_submit(): newurl = form.url.data current_wiki.move(url, newurl) # Delete non-moved pages all_pages = current_wiki.index() pages = Page.get_versions(page.path, all_pages) for p in pages: current_wiki.delete(p.url) flash('Page "%s" was deleted.' % page.title, 'success') return redirect(url_for('wiki.display', url=newurl)) return render_template('move.html', form=form, page=page)
def edit(url): page = current_wiki.get(url) form = EditorForm(obj=page) if form.validate_on_submit(): if not page: page = current_wiki.get_bare(url) form.populate_obj(page) page.save() new_path = Page.get_highest_version_of_file_path(page.path) pages = current_wiki.index() new_page = None for p in pages: if p.path == new_path: new_page = p if new_page is None: new_page = page flash('"%s" was saved.' % new_page.title, 'success') return redirect(url_for('wiki.display', url=new_page.url)) return render_template('editor.html', form=form, page=page)
def test_page_loading_fails(self): """ Assert that content is loaded correctly from disk. """ with pytest.raises(InvalidFileException): Page(self.page_path, 'test')
def setUp(self): super(PageTestCase, self).setUp() self.page_path = self.create_file('test.md', self.page_content) self.page = Page(self.page_path, 'test')
def index(): pages = current_wiki.index() pages = Page.filter_old_versions(pages) return render_template('index.html', pages=pages)