Skip to content

Commit cea1822

Browse files
authored
quality: add tests agains social cards integration (#222)
2 parents 36d261a + e8273b4 commit cea1822

3 files changed

Lines changed: 87 additions & 0 deletions
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
site_name: Test RSS Plugin
2+
site_description: Test a language code set in with territory
3+
site_url: https://guts.github.io/mkdocs-rss-plugin
4+
5+
plugins:
6+
- rss
7+
- social:
8+
enabled: false
9+
cards: true
10+
11+
theme:
12+
name: material
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
site_name: Test RSS Plugin
2+
site_description: Test a language code set in with territory
3+
site_url: https://guts.github.io/mkdocs-rss-plugin
4+
5+
plugins:
6+
- rss:
7+
use_material_social_cards: false
8+
- social:
9+
enabled: true
10+
cards: true
11+
12+
theme:
13+
name: material

tests/test_integrations_material_social_cards.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,25 @@ class TestRssPluginIntegrationsMaterialSocialCards(BaseTest):
4444
"""Test integration of Social Cards plugin with RSS plugin."""
4545

4646
# -- TESTS ---------------------------------------------------------
47+
def test_plugin_config_social_cards_enabled_but_integration_disabled(self):
48+
# default reference
49+
cfg_mkdocs = load_config(
50+
str(
51+
Path(
52+
"tests/fixtures/mkdocs_item_image_social_cards_enabled_but_integration_disabled.yml"
53+
).resolve()
54+
)
55+
)
56+
57+
integration_social_cards = IntegrationMaterialSocialCards(
58+
mkdocs_config=cfg_mkdocs,
59+
switch_force=cfg_mkdocs.plugins.get("rss").config.use_material_social_cards,
60+
)
61+
self.assertTrue(integration_social_cards.IS_THEME_MATERIAL)
62+
self.assertTrue(integration_social_cards.IS_SOCIAL_PLUGIN_ENABLED)
63+
self.assertTrue(integration_social_cards.IS_SOCIAL_PLUGIN_CARDS_ENABLED)
64+
self.assertFalse(integration_social_cards.IS_ENABLED)
65+
4766
def test_plugin_config_social_cards_enabled(self):
4867
# default reference
4968
cfg_mkdocs = load_config(
@@ -62,6 +81,24 @@ def test_plugin_config_social_cards_enabled(self):
6281
self.assertTrue(integration_social_cards.IS_SOCIAL_PLUGIN_CARDS_ENABLED)
6382
self.assertTrue(integration_social_cards.IS_ENABLED)
6483

84+
def test_plugin_config_social_cards_disabled(self):
85+
# default reference
86+
cfg_mkdocs = load_config(
87+
str(
88+
Path(
89+
"tests/fixtures/mkdocs_item_image_social_cards_disabled_site.yml"
90+
).resolve()
91+
)
92+
)
93+
94+
integration_social_cards = IntegrationMaterialSocialCards(
95+
mkdocs_config=cfg_mkdocs
96+
)
97+
self.assertTrue(integration_social_cards.IS_THEME_MATERIAL)
98+
self.assertFalse(integration_social_cards.IS_SOCIAL_PLUGIN_ENABLED)
99+
self.assertFalse(integration_social_cards.IS_SOCIAL_PLUGIN_CARDS_ENABLED)
100+
self.assertFalse(integration_social_cards.IS_ENABLED)
101+
65102
def test_plugin_config_social_plugin_enabled_but_cards_disabled(self):
66103
# default reference
67104
cfg_mkdocs = load_config(
@@ -106,6 +143,31 @@ def test_simple_build(self):
106143
feed_parsed = feedparser.parse(Path(tmpdirname) / "feed_rss_updated.xml")
107144
self.assertEqual(feed_parsed.bozo, 0)
108145

146+
with tempfile.TemporaryDirectory() as tmpdirname:
147+
cli_result = self.build_docs_setup(
148+
testproject_path="docs",
149+
mkdocs_yml_filepath=Path(
150+
"tests/fixtures/mkdocs_item_image_social_cards_disabled_site.yml"
151+
),
152+
output_path=tmpdirname,
153+
strict=False,
154+
)
155+
156+
if cli_result.exception is not None:
157+
e = cli_result.exception
158+
logger.debug(format_exception(type(e), e, e.__traceback__))
159+
160+
self.assertEqual(cli_result.exit_code, 0)
161+
self.assertIsNone(cli_result.exception)
162+
163+
# created items
164+
feed_parsed = feedparser.parse(Path(tmpdirname) / "feed_rss_created.xml")
165+
self.assertEqual(feed_parsed.bozo, 0)
166+
167+
# updated items
168+
feed_parsed = feedparser.parse(Path(tmpdirname) / "feed_rss_updated.xml")
169+
self.assertEqual(feed_parsed.bozo, 0)
170+
109171

110172
# ##############################################################################
111173
# ##### Stand alone program ########

0 commit comments

Comments
 (0)