Expand test Site tests
This commit is contained in:
+110
-1
@@ -1,6 +1,6 @@
|
||||
from pathlib import Path
|
||||
import pytest
|
||||
from omicron.ssg.output import ContentError, Directory
|
||||
from omicron.ssg.output import ContentError, Directory, OutputError
|
||||
from omicron.ssg.site import ConfigError, Site
|
||||
|
||||
|
||||
@@ -98,3 +98,112 @@ def test_clean_removes_output_directory(make_site):
|
||||
def test_resolve_template_path_raises_for_missing_template():
|
||||
with pytest.raises(ConfigError, match="not found"):
|
||||
Site.resolve_template_path("does-not-exist")
|
||||
|
||||
|
||||
def test_home_url(site_dir):
|
||||
path = site_dir("thin_site")
|
||||
(path / "config.yml").write_text("name: test\ntemplate: plain\n")
|
||||
assert Site(path).home_url() == "/"
|
||||
|
||||
(path / "config.yml").write_text(
|
||||
"name: test\ntemplate: plain\nbase_url: http://example.com/blog\n"
|
||||
)
|
||||
assert Site(path).home_url() == "/blog"
|
||||
|
||||
|
||||
def test_url_for(site_dir):
|
||||
path = site_dir("thin_site")
|
||||
(path / "config.yml").write_text(
|
||||
"name: test\ntemplate: plain\nbase_url: http://example.com/blog\n"
|
||||
)
|
||||
|
||||
site = Site(path)
|
||||
assert site.url_for("assets/style.css") == "/blog/assets/style.css"
|
||||
|
||||
with pytest.raises(OutputError, match="must be relative"):
|
||||
site.url_for("/assets/style.css")
|
||||
|
||||
|
||||
def test_section_url(site_dir):
|
||||
path = site_dir("sections")
|
||||
|
||||
site = Site(path)
|
||||
site.discover()
|
||||
assert site.section_url("posts") == "/posts"
|
||||
assert site.section_url("notes") == "/notes"
|
||||
|
||||
(path / "config.yml").write_text("name: test\ntemplate: plain\nbase_url: /blog\n")
|
||||
site = Site(path)
|
||||
site.discover()
|
||||
assert site.section_url("posts") == "/blog/posts"
|
||||
assert site.section_url("notes") == "/blog/notes"
|
||||
|
||||
|
||||
def test_add_by_section(make_site):
|
||||
site = make_site("sections")
|
||||
site.discover()
|
||||
|
||||
assert set(site.by_section) == {"posts", "notes"}
|
||||
assert {c.title for c in site.by_section["posts"]} == {"First Post", "Second Post"}
|
||||
assert {c.title for c in site.by_section["notes"]} == {"First Note"}
|
||||
|
||||
|
||||
def test_feed_url(site_dir):
|
||||
path = site_dir("tags")
|
||||
|
||||
(path / "config.yml").write_text(
|
||||
"name: test\ntemplate: plain\nbase_url: http://example.com\n"
|
||||
)
|
||||
site = Site(path)
|
||||
site.discover()
|
||||
assert site.feed_url("root", None) == "/atom.xml"
|
||||
|
||||
(path / "config.yml").write_text("name: test\ntemplate: plain\n")
|
||||
site = Site(path)
|
||||
site.discover()
|
||||
assert site.feed_url("root", None) is None
|
||||
|
||||
|
||||
def test_tag_url(site_dir):
|
||||
path = site_dir("tags")
|
||||
|
||||
site = Site(path)
|
||||
site.discover()
|
||||
assert site.tag_url("python") == "/tags/python"
|
||||
|
||||
(path / "config.yml").write_text("name: test\ntemplate: plain\nbase_url: /blog\n")
|
||||
site = Site(path)
|
||||
site.discover()
|
||||
assert site.tag_url("python") == "/blog/tags/python"
|
||||
|
||||
|
||||
def test_tags_url(make_site):
|
||||
site = make_site("tags")
|
||||
site.discover()
|
||||
|
||||
assert site.tags_url() == "/tags"
|
||||
|
||||
|
||||
def test_add_by_source(make_site):
|
||||
site = make_site("tags")
|
||||
site.discover()
|
||||
|
||||
assert site.by_source
|
||||
for content in site.content:
|
||||
assert site.by_source[content.source] is content
|
||||
|
||||
|
||||
def test_tags_by_count(make_site):
|
||||
site = make_site("tags")
|
||||
site.discover()
|
||||
|
||||
assert site.tags_by_count == [("python", 2), ("testing", 1)]
|
||||
|
||||
|
||||
def test_add_by_tag(make_site):
|
||||
site = make_site("tags")
|
||||
site.discover()
|
||||
|
||||
assert set(site.by_tag) == {"python", "testing"}
|
||||
assert {c.title for c in site.by_tag["python"]} == {"One Tag", "Two Tags"}
|
||||
assert {c.title for c in site.by_tag["testing"]} == {"Two Tags"}
|
||||
|
||||
Reference in New Issue
Block a user