Skip to content

Commit

Permalink
quality: add tests agains social cards integration (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
Guts authored Dec 16, 2023
2 parents 36d261a + e8273b4 commit cea1822
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
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

0 comments on commit cea1822

Please sign in to comment.