def test_to_html_html_format(self):
     filename = 'blah'
     content = 'This is just a random file'
     config = {'format': 'html'}
     page = Page(filename=filename, config=config, content=content)
     should_be = 'This is just a random file'
     assert page.to_html() == should_be
Beispiel #2
0
 def test_to_html_html_format(self):
     filename = 'blah'
     content = 'This is just a random file'
     config = {'format': 'html'}
     page = Page(filename=filename, config=config, content=content)
     should_be = 'This is just a random file'
     assert page.to_html() == should_be
Beispiel #3
0
 def test_to_html_unknown_format(self):
     filename = 'blah'
     content = 'This is just a random file'
     config = {'format': 'pdf'}
     page = Page(filename=filename, config=config, content=content)
     should_be = 'This is just a random file'
     with pytest.raises(NoRenderEngineError):
         page.to_html()
 def test_to_html_unknown_format(self):
     filename = 'blah'
     content = 'This is just a random file'
     config = {'format': 'pdf'}
     page = Page(filename=filename, config=config, content=content)
     should_be = 'This is just a random file'
     with pytest.raises(NoRenderEngineError):
         page.to_html()
Beispiel #5
0
    def test_wiki_page_valid(self, client):
        src = """
        ---
        title: A Dummy File
        ---

        The body of some file
        """.strip()
        headers, body = Page.parse_text(src)

        site_folder = os.path.join(current_app.config['WIKI_DIR'], '_site')
        _, temporary_file = tempfile.mkstemp(dir=site_folder, suffix='.txt')
        open(temporary_file, 'w').write(src)
        assert os.path.exists(temporary_file)

        relative_filename = temporary_file.replace(site_folder, '')
        relative_filename = relative_filename[1:]

        url = url_for('main.wiki_page', page_path=relative_filename)
        r = client.get(url)
        assert r.status_code == 200

        assert body in r.get_data(as_text=True)

        os.remove(temporary_file)
        assert not os.path.exists(temporary_file)
Beispiel #6
0
    def test_parse_no_ending_dash(self):
        src = """
        ---
        title: Blah

        This is the body.
        """.strip()
        with pytest.raises(ParseError):
            header, body = Page.parse_text(src)
Beispiel #7
0
 def test_parse_no_newline_after_header(self):
     src = """
     ---
     title: Blah
     ---
     This is the body.
     """.strip()
     with pytest.raises(ParseError):
         header, body = Page.parse_text(src)
 def test_parse_no_newline_after_header(self):
     src = """
     ---
     title: Blah
     ---
     This is the body.
     """.strip()
     with pytest.raises(ParseError):
         header, body = Page.parse_text(src)
    def test_parse_no_ending_dash(self):
        src = """
        ---
        title: Blah

        This is the body.
        """.strip()
        with pytest.raises(ParseError):
            header, body = Page.parse_text(src)
Beispiel #10
0
    def test_init_with_title_in_config(self):
        _, filename = tempfile.mkstemp()
        content = "This is just a random file"
        config = {'title': 'blah'}

        with pytest.raises(ValueError):
            p = Page(filename=filename, content=content, config=config)

        os.remove(filename)
        assert not exists(filename)
Beispiel #11
0
    def test_parse_valid(self):
        src = """
        ---
        title: Blah
        ---

        This is the body.
        """.strip()
        header, body = Page.parse_text(src)
        assert header == {'title': 'Blah'}
        assert body == 'This is the body.'
    def test_parse_valid(self):
        src = """
        ---
        title: Blah
        ---

        This is the body.
        """.strip()
        header, body = Page.parse_text(src)
        assert header == {'title': 'Blah'}
        assert body == 'This is the body.'
Beispiel #13
0
    def test_init_no_config(self):
        _, filename = tempfile.mkstemp(suffix='.md')
        title = filename_to_title(filename)
        content = "This is just a random file"

        p = Page(filename=filename, content=content)

        assert p.config['title'] == title
        assert p.filename == filename
        assert p.content == content
        assert p.title == title

        os.remove(filename)
        assert not exists(filename)
Beispiel #14
0
    def test_init_with_config(self):
        _, filename = tempfile.mkstemp(suffix='.md')
        title = filename_to_title(filename)
        content = "This is just a random file"
        config = {'extra': 'blah'}

        p = Page(filename=filename, content=content, config=config)

        assert p.config['title'] == title
        assert p.config == config
        assert p.filename == filename
        assert p.content == content

        os.remove(filename)
        assert not exists(filename)
    def test_from_file_invalid_file(self):
        src = """
        ---
        title: A Dummy File

        ---

        Woops, did I accidentally put a newline in the header?
        """.strip()

        _, filename = tempfile.mkstemp()
        open(filename, 'w').write(src)
        assert os.path.exists(filename)

        with pytest.raises(ParseError):
            some_page = Page.from_file(filename)

        os.remove(filename)
        assert not exists(filename)
Beispiel #16
0
    def test_from_file_invalid_file(self):
        src = """
        ---
        title: A Dummy File

        ---

        Woops, did I accidentally put a newline in the header?
        """.strip()

        _, filename = tempfile.mkstemp()
        open(filename, 'w').write(src)
        assert os.path.exists(filename)

        with pytest.raises(ParseError):
            some_page = Page.from_file(filename)

        os.remove(filename)
        assert not exists(filename)
    def test_from_file_valid(self):
        _, filename = tempfile.mkstemp()
        title = filename_to_title(filename)

        src = """
        ---
        title: {}
        ---

        The body of some file
        """.format(title).strip()

        open(filename, 'w').write(src)
        assert os.path.exists(filename)

        some_page = Page.from_file(filename)

        assert some_page.config == {'title': title}
        assert some_page.content == 'The body of some file'

        os.remove(filename)
        assert not exists(filename)
Beispiel #18
0
    def test_from_file_valid(self):
        _, filename = tempfile.mkstemp()
        title = filename_to_title(filename)

        src = """
        ---
        title: {}
        ---

        The body of some file
        """.format(title).strip()

        open(filename, 'w').write(src)
        assert os.path.exists(filename)

        some_page = Page.from_file(filename)

        assert some_page.config == {'title': title}
        assert some_page.content == 'The body of some file'

        os.remove(filename)
        assert not exists(filename)
 def test_from_file_FileNotFound(self):
     with pytest.raises(FileNotFoundError):
         some_page = Page.from_file('non/existent/file.md')
 def test_to_html_no_markup_specified(self):
     filename = 'blah'
     content = 'This is just a random file'
     page = Page(filename=filename, content=content)
     should_be = '<p>This is just a random file</p>'
     assert page.to_html() == should_be
Beispiel #21
0
 def test_empty_file(self):
     src = ''
     with pytest.raises(ParseError):
         header, body = Page.parse_text(src)
 def test_empty_file(self):
     src = ''
     with pytest.raises(ParseError):
         header, body = Page.parse_text(src)
Beispiel #23
0
 def test_from_file_FileNotFound(self):
     with pytest.raises(FileNotFoundError):
         some_page = Page.from_file('non/existent/file.md')
Beispiel #24
0
def page(git_repo):
    filename = join(git_repo.working_tree_dir, 'a_dummy_file.txt')
    content = "This is just a random file"

    return Page(filename=filename, content=content, repo=git_repo)
Beispiel #25
0
 def test_to_html_no_markup_specified(self):
     filename = 'blah'
     content = 'This is just a random file'
     page = Page(filename=filename, content=content)
     should_be = '<p>This is just a random file</p>'
     assert page.to_html() == should_be