diff --git a/tests/fixtures/mkdocs_item_comments.yml b/tests/fixtures/mkdocs_item_comments.yml new file mode 100644 index 00000000..1cd1332e --- /dev/null +++ b/tests/fixtures/mkdocs_item_comments.yml @@ -0,0 +1,23 @@ +# Project information +site_name: MkDocs RSS Plugin - TEST +site_description: Basic setup to test against MkDocs RSS plugin +site_author: Julien Moura (Guts) +site_url: https://guts.github.io/mkdocs-rss-plugin +copyright: 'Guts - In Geo Veritas' + +# Repository +repo_name: 'guts/mkdocs-rss-plugin' +repo_url: 'https://github.com/guts/mkdocs-rss-plugin' + +use_directory_urls: true + +plugins: + - rss: + comments_path: "#__comments" + +theme: + name: readthedocs + +# Extensions to enhance markdown +markdown_extensions: + - meta diff --git a/tests/fixtures/mkdocs_item_no_comments.yml b/tests/fixtures/mkdocs_item_no_comments.yml new file mode 100644 index 00000000..ddb2a908 --- /dev/null +++ b/tests/fixtures/mkdocs_item_no_comments.yml @@ -0,0 +1,22 @@ +# Project information +site_name: MkDocs RSS Plugin - TEST +site_description: Basic setup to test against MkDocs RSS plugin +site_author: Julien Moura (Guts) +site_url: https://guts.github.io/mkdocs-rss-plugin +copyright: 'Guts - In Geo Veritas' + +# Repository +repo_name: 'guts/mkdocs-rss-plugin' +repo_url: 'https://github.com/guts/mkdocs-rss-plugin' + +use_directory_urls: true + +plugins: + - rss + +theme: + name: readthedocs + +# Extensions to enhance markdown +markdown_extensions: + - meta diff --git a/tests/test_build.py b/tests/test_build.py index b128bf92..06113560 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -116,6 +116,50 @@ def test_simple_build_feed_length(self): self.assertEqual(len(feed_parsed.entries), 3) + def test_simple_build_item_comments_enabled(self): + with tempfile.TemporaryDirectory() as tmpdirname: + cli_result = self.build_docs_setup( + testproject_path="docs", + mkdocs_yml_filepath=Path("tests/fixtures/mkdocs_item_comments.yml"), + output_path=tmpdirname, + strict=True, + ) + if cli_result.exception is not None: + e = cli_result.exception + logger.debug(format_exception(type(e), e, e.__traceback__)) + + self.assertEqual(cli_result.exit_code, 0) + self.assertIsNone(cli_result.exception) + + # created items + feed_parsed = feedparser.parse(Path(tmpdirname) / "feed_rss_created.xml") + self.assertEqual(feed_parsed.bozo, 0) + + for feed_item in feed_parsed.entries: + self.assertTrue("comments" in feed_item) + + def test_simple_build_item_comments_disabled(self): + with tempfile.TemporaryDirectory() as tmpdirname: + cli_result = self.build_docs_setup( + testproject_path="docs", + mkdocs_yml_filepath=Path("tests/fixtures/mkdocs_item_no_comments.yml"), + output_path=tmpdirname, + strict=True, + ) + if cli_result.exception is not None: + e = cli_result.exception + logger.debug(format_exception(type(e), e, e.__traceback__)) + + self.assertEqual(cli_result.exit_code, 0) + self.assertIsNone(cli_result.exception) + + # created items + feed_parsed = feedparser.parse(Path(tmpdirname) / "feed_rss_created.xml") + self.assertEqual(feed_parsed.bozo, 0) + + for feed_item in feed_parsed.entries: + self.assertTrue("comments" not in feed_item) + def test_simple_build_item_length_unlimited(self): with tempfile.TemporaryDirectory() as tmpdirname: cli_result = self.build_docs_setup( @@ -137,10 +181,9 @@ def test_simple_build_item_length_unlimited(self): feed_parsed = feedparser.parse(Path(tmpdirname) / "feed_rss_created.xml") self.assertEqual(feed_parsed.bozo, 0) - for item in feed_parsed.entries: - print(item.title, len(item.description)) - if item.title not in ("Page without meta with short text",): - self.assertGreaterEqual(len(item.description), 150) + for feed_item in feed_parsed.entries: + if feed_item.title not in ("Page without meta with short text",): + self.assertGreaterEqual(len(feed_item.description), 150) def test_rss_feed_validation(self): with tempfile.TemporaryDirectory() as tmpdirname: