Example #1
0
    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
Example #2
0
    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
Example #3
0
    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
Example #4
0
    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))
Example #5
0
    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))
Example #6
0
    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
Example #7
0
    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
Example #8
0
    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
Example #9
0
def serve(port, root=None, debug=None, browser=None):
    from neorg.web import app, update_system_info, update_search_index
    from neorg.config import load_config
    from neorg.wiki import setup_wiki
    load_config(app, dirpath=root)
    if debug is not None:
        app.config['DEBUG'] = debug
    update_search_index()
    update_system_info()
    if browser:
        from threading import Timer
        from webbrowser import open_new_tab
        Timer(1, open_new_tab, args=['http://localhost:%d' % port]).start()
    setup_wiki()
    app.run(port=port)
Example #10
0
    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))
Example #11
0
    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
Example #12
0
    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
Example #13
0
    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))
Example #14
0
def serve(port, root=None, debug=None, browser=None):
    from neorg.web import app, update_system_info, update_search_index
    from neorg.config import load_config
    from neorg.wiki import setup_wiki
    load_config(app, dirpath=root)
    if debug is not None:
        app.config['DEBUG'] = debug
    update_search_index()
    update_system_info()
    if browser:
        from threading import Timer
        from webbrowser import open_new_tab
        Timer(1, open_new_tab,
              args=['http://localhost:%d' % port]).start()
    setup_wiki()
    app.run(port=port)
Example #15
0
def setup_app():
    web.app.config.from_object(DefaultConfig)
    (db_fd, web.app.config['DATABASE']) = tempfile.mkstemp(prefix=TMP_PREFIX)
    dirpath = tempfile.mkdtemp(prefix=TMP_PREFIX)  # = NEORG_ROOT
    set_config(web.app.config, dirpath)
    os.mkdir(web.app.config['NEORG_DIR'])
    web.app.config['SECRET_KEY'] = 'key for testing'
    app = web.app.test_client()
    web.init_db()
    web.update_search_index()

    from neorg.wiki import setup_wiki, gene_html
    setup_wiki()

    def gene_html_with_encode(*args, **kwds):
        return gene_html(*args, **kwds).encode('utf-8')

    return (app, db_fd, gene_html_with_encode)
Example #16
0
def setup_app():
    web.app.config.from_object(DefaultConfig)
    (db_fd, web.app.config['DATABASE']) = tempfile.mkstemp(prefix=TMP_PREFIX)
    dirpath = tempfile.mkdtemp(prefix=TMP_PREFIX)  # = NEORG_ROOT
    set_config(web.app.config, dirpath)
    os.mkdir(web.app.config['NEORG_DIR'])
    web.app.config['SECRET_KEY'] = 'key for testing'
    app = web.app.test_client()
    web.init_db()
    web.update_search_index()

    from neorg.wiki import setup_wiki, gene_html
    setup_wiki()

    def gene_html_with_encode(*args, **kwds):
        return gene_html(*args, **kwds).encode('utf-8')

    return (app, db_fd, gene_html_with_encode)
Example #17
0
    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
Example #18
0
    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
Example #19
0
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)
Example #20
0
    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
Example #21
0
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)
Example #22
0
    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