Exemplo n.º 1
0
async def test_build_post(fs: FakeFilesystem, root: Path,
                          config: Config) -> None:
    """
    Test ``build_post``.
    """
    path = Path(root / "posts/first/index.mkd")

    # create post
    with freeze_time("2021-01-01T00:00:00Z"):
        fs.create_file(path, contents=POST_CONTENT)
        local_date = formatdate(1609459200.0, localtime=True)

    config.announcers = {"antenna": AnnouncerModel(plugin="antenna")}

    post = build_post(root, config, path)

    assert post.path == path
    assert post.title == "This is your first post"
    assert post.timestamp == datetime(2021, 1, 1, 0, 0, tzinfo=timezone.utc)
    assert post.metadata == {
        "keywords": "welcome, blog",
        "summary": "Hello, world!",
    }
    assert post.tags == {"welcome", "blog"}
    assert post.categories == {"stem"}
    assert post.type == "post"
    assert post.url == "first/index"
    assert (post.content == """# Welcome #

This is your first post. It should be written using Markdown.

Read more about [Nefelibata](https://nefelibata.readthedocs.io/).""")
    assert post.announcers == {"antenna"}

    # check to file was updated with the ``date`` header
    with open(path, encoding="utf-8") as input_:
        content = input_.read()
    assert (content == f"""subject: This is your first post
keywords: welcome, blog
summary: Hello, world!
date: {local_date}
announce-on: antenna

# Welcome #

This is your first post. It should be written using Markdown.

Read more about [Nefelibata](https://nefelibata.readthedocs.io/).""")

    # build again, and test that the file wasn't modified since it
    # already has all the required headers
    last_update = path.stat().st_mtime
    build_post(root, config, path)
    assert path.stat().st_mtime == last_update
Exemplo n.º 2
0
def test_get_announcers(
    mocker: MockerFixture,
    make_entry_point: Type[MockEntryPoint],
    root: Path,
    config: Config,
) -> None:
    """
    Test ``get_announcers``.
    """
    DummyAnnouncer = make_dummy_announcer("DummyAnnouncer", [Scope.SITE])
    entry_points = [
        make_entry_point("dummy_announcer", DummyAnnouncer),
    ]
    mocker.patch(
        "nefelibata.announcers.base.iter_entry_points",
        return_value=entry_points,
    )
    mocker.patch(
        "nefelibata.announcers.base.get_builders",
    )

    config.builders = {
        "site_builder": BuilderModel(
            **{
                "plugin": "site_builder",
                "announce-on": ["dummy_announcer"],
                "publish-to": [],
                "home": "https://example.com/",
                "path": "generic",
            }
        ),
    }
    config.announcers = {
        "dummy_announcer": AnnouncerModel(
            **{
                "plugin": "dummy_announcer",
            }
        ),
    }
    announcers = get_announcers(root, config, Scope.SITE)
    assert len(announcers) == 1

    announcers = get_announcers(root, config, Scope.POST)
    assert len(announcers) == 0