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)
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)
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_empty_file(self): src = '' with pytest.raises(ParseError): header, body = Page.parse_text(src)