Skip to content

Commit 96e8f2b

Browse files
committed
Add tests
1 parent 2d7aac6 commit 96e8f2b

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

src/render_engine_cli/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ def sitemap(xml: bool, output: click.File, module_site: str):
431431
if output:
432432
Path(output).write_text(content)
433433
else:
434-
print(content)
434+
click.echo(content)
435435

436436

437437
if __name__ == "__main__":

tests/test_cli_commands.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,3 +387,46 @@ def test_serve_command_with_reload(runner, test_site_module, monkeypatch):
387387

388388
assert result.exit_code == 0, result.output
389389
mock_get_paths.assert_called_once_with(mock_site)
390+
391+
392+
@pytest.mark.parametrize(
393+
"params, expected",
394+
[
395+
([], ["console", "html"]),
396+
(["-x"], ["console", "xml"]),
397+
(["-x", "-o", "sitemap.xml"], ["file", "xml"]),
398+
(["-o", "sitemap.html"], ["file", "html"]),
399+
],
400+
)
401+
def test_sitemap(runner, test_site_module, monkeypatch, params, expected):
402+
"""Tests sitemap generation command"""
403+
404+
class MockSiteMap:
405+
def __init__(self, *args, **kwargs): ...
406+
407+
@property
408+
def html(self):
409+
return "sitemap"
410+
411+
class MockPage:
412+
def __init__(self, *args, **kwargs): ...
413+
414+
def _render_content(self, *args, **kwargs):
415+
return "sitemap"
416+
417+
with (
418+
patch("render_engine_cli.cli.get_site") as mock_get_site,
419+
):
420+
monkeypatch.setattr("render_engine_cli.cli.SiteMap", MockSiteMap)
421+
monkeypatch.setattr("render_engine_cli.cli.Page", MockPage)
422+
mock_site = Mock()
423+
mock_get_site.return_value = mock_site
424+
with runner.isolated_filesystem():
425+
result = runner.invoke(app, ["sitemap", "--module-site", "test:test", *params])
426+
output_loc, output_type = expected
427+
expected_out = f"sitemap.{output_type}"
428+
match output_loc:
429+
case "console":
430+
assert result.output.strip() == "sitemap"
431+
case "file":
432+
assert Path(expected_out).read_text().strip() == "sitemap"

0 commit comments

Comments
 (0)