Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quality: add tests against social cards integration #222

Merged
merged 1 commit into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions tests/fixtures/mkdocs_item_image_social_cards_disabled_site.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
site_name: Test RSS Plugin
site_description: Test a language code set in with territory
site_url: https://guts.github.io/mkdocs-rss-plugin

plugins:
- rss
- social:
enabled: false
cards: true

theme:
name: material
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
site_name: Test RSS Plugin
site_description: Test a language code set in with territory
site_url: https://guts.github.io/mkdocs-rss-plugin

plugins:
- rss:
use_material_social_cards: false
- social:
enabled: true
cards: true

theme:
name: material
62 changes: 62 additions & 0 deletions tests/test_integrations_material_social_cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,25 @@ class TestRssPluginIntegrationsMaterialSocialCards(BaseTest):
"""Test integration of Social Cards plugin with RSS plugin."""

# -- TESTS ---------------------------------------------------------
def test_plugin_config_social_cards_enabled_but_integration_disabled(self):
# default reference
cfg_mkdocs = load_config(
str(
Path(
"tests/fixtures/mkdocs_item_image_social_cards_enabled_but_integration_disabled.yml"
).resolve()
)
)

integration_social_cards = IntegrationMaterialSocialCards(
mkdocs_config=cfg_mkdocs,
switch_force=cfg_mkdocs.plugins.get("rss").config.use_material_social_cards,
)
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.assertFalse(integration_social_cards.IS_ENABLED)

def test_plugin_config_social_cards_enabled(self):
# default reference
cfg_mkdocs = load_config(
Expand All @@ -62,6 +81,24 @@ def test_plugin_config_social_cards_enabled(self):
self.assertTrue(integration_social_cards.IS_SOCIAL_PLUGIN_CARDS_ENABLED)
self.assertTrue(integration_social_cards.IS_ENABLED)

def test_plugin_config_social_cards_disabled(self):
# default reference
cfg_mkdocs = load_config(
str(
Path(
"tests/fixtures/mkdocs_item_image_social_cards_disabled_site.yml"
).resolve()
)
)

integration_social_cards = IntegrationMaterialSocialCards(
mkdocs_config=cfg_mkdocs
)
self.assertTrue(integration_social_cards.IS_THEME_MATERIAL)
self.assertFalse(integration_social_cards.IS_SOCIAL_PLUGIN_ENABLED)
self.assertFalse(integration_social_cards.IS_SOCIAL_PLUGIN_CARDS_ENABLED)
self.assertFalse(integration_social_cards.IS_ENABLED)

def test_plugin_config_social_plugin_enabled_but_cards_disabled(self):
# default reference
cfg_mkdocs = load_config(
Expand Down Expand Up @@ -106,6 +143,31 @@ def test_simple_build(self):
feed_parsed = feedparser.parse(Path(tmpdirname) / "feed_rss_updated.xml")
self.assertEqual(feed_parsed.bozo, 0)

with tempfile.TemporaryDirectory() as tmpdirname:
cli_result = self.build_docs_setup(
testproject_path="docs",
mkdocs_yml_filepath=Path(
"tests/fixtures/mkdocs_item_image_social_cards_disabled_site.yml"
),
output_path=tmpdirname,
strict=False,
)

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)

# updated items
feed_parsed = feedparser.parse(Path(tmpdirname) / "feed_rss_updated.xml")
self.assertEqual(feed_parsed.bozo, 0)


# ##############################################################################
# ##### Stand alone program ########
Expand Down