diff --git a/tests/fixtures/mkdocs_item_image_social_cards_blog_directory_url_disabled.yml b/tests/fixtures/mkdocs_item_image_social_cards_blog_directory_url_disabled.yml new file mode 100644 index 0000000..49ff755 --- /dev/null +++ b/tests/fixtures/mkdocs_item_image_social_cards_blog_directory_url_disabled.yml @@ -0,0 +1,18 @@ +site_name: Test RSS Plugin with social cards, blog plugin and directory URL disabled +site_description: Test RSS with social and blog plugins enabled but directory URLS disabled. Related to https://github.com/Guts/mkdocs-rss-plugin/issues/319. +site_url: https://guts.github.io/mkdocs-rss-plugin + +use_directory_urls: false + +plugins: + - blog: + blog_dir: blog + authors_profiles: true + - rss: + match_path: blog/posts/.* + - social: + enabled: true + cards: true + +theme: + name: material diff --git a/tests/test_integrations_material_social_cards.py b/tests/test_integrations_material_social_cards.py index eab4e1c..a2baed3 100644 --- a/tests/test_integrations_material_social_cards.py +++ b/tests/test_integrations_material_social_cards.py @@ -25,6 +25,7 @@ from mkdocs.config import load_config # package +from mkdocs_rss_plugin.__about__ import __title_clean__ from mkdocs_rss_plugin.integrations.theme_material_social_plugin import ( IntegrationMaterialSocialCards, ) @@ -136,6 +137,55 @@ def test_plugin_config_social_cards_enabled_with_blog_plugin(self): ) self.assertTrue(integration_social_cards.IS_ENABLED) + def test_plugin_config_social_cards_enabled_with_directory_urls_disabled(self): + """Test case described in https://github.com/Guts/mkdocs-rss-plugin/issues/319.""" + # default reference + cfg_mkdocs = load_config( + str( + Path( + "tests/fixtures/mkdocs_item_image_social_cards_blog_directory_url_disabled.yml" + ).resolve() + ) + ) + + integration_social_cards = IntegrationMaterialSocialCards( + mkdocs_config=cfg_mkdocs + ) + self.assertTrue(integration_social_cards.IS_THEME_MATERIAL) + self.assertTrue(integration_social_cards.IS_SOCIAL_PLUGIN_ENABLED) + self.assertTrue(integration_social_cards.IS_SOCIAL_PLUGIN_CARDS_ENABLED) + self.assertIsInstance(integration_social_cards.social_cards_dir, str) + self.assertTrue(integration_social_cards.social_cards_cache_dir.is_dir()) + + with tempfile.TemporaryDirectory( + prefix=f"{__title_clean__.lower()}_", delete=False + ) as tmpdirname: + cli_result = self.build_docs_setup( + testproject_path="docs", + mkdocs_yml_filepath=Path( + "tests/fixtures/mkdocs_item_image_social_cards_blog_directory_url_disabled.yml" + ), + output_path=tmpdirname, + strict=False, + ) + print(tmpdirname) + 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(hasattr(feed_item, "enclosures")) + + # updated items + feed_parsed = feedparser.parse(Path(tmpdirname) / "feed_rss_updated.xml") + self.assertEqual(feed_parsed.bozo, 0) + def test_simple_build(self): with tempfile.TemporaryDirectory() as tmpdirname: cli_result = self.build_docs_setup(