jean-web/tests/test_site.py

33 lines
973 B
Python

from pathlib import Path
from pyfakefs.fake_filesystem import FakeFilesystem
from pytest import fixture
from jwebsite.site import Site
@fixture
def site_dir(datadir: Path, fs: FakeFilesystem):
fs.add_real_directory(datadir)
yield fs
def test_render_page(datadir: Path, site_dir: FakeFilesystem):
site = Site(datadir)
site.render("index.j2", "index.html")
with open(datadir / "build" / "index.html", encoding="utf-8") as ouput_file:
assert ouput_file.read() == "<p>Peter</p><p>Steven</p>"
def test_output_file(datadir: Path, site_dir: FakeFilesystem):
site = Site(datadir)
build_dir = datadir / "build"
site.render("output-file.j2", "output-file.html")
with open(build_dir / "assets/steven-avatar", encoding="utf-8") as ouput_file:
assert ouput_file.read() == "Yipee\n"
with open(build_dir / "output-file.html", encoding="utf-8") as ouput_file:
assert ouput_file.read() == "/assets/steven-avatar\n"