Skip to content

Commit 739afd2

Browse files
committed
feature(material_blog): extend tests against new blog integration
1 parent 2c963f2 commit 739afd2

File tree

3 files changed

+90
-6
lines changed

3 files changed

+90
-6
lines changed

tests/fixtures/mkdocs_items_material_blog_enabled.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ site_description: Test RSS with blog plugin also enabled
33
site_url: https://guts.github.io/mkdocs-rss-plugin
44

55
plugins:
6-
- blog:
7-
blog_dir: blog
8-
authors_profiles: true
9-
- rss:
10-
use_material_blog: true
6+
- blog:
7+
blog_dir: blog
8+
authors_profiles: true
9+
- rss
1110

1211
theme:
13-
name: material
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 RSS with blog plugin also enabled
3+
site_url: https://guts.github.io/mkdocs-rss-plugin
4+
5+
plugins:
6+
- blog:
7+
blog_dir: blog
8+
authors_profiles: true
9+
- rss:
10+
use_material_blog: false
11+
12+
theme:
13+
name: material

tests/test_integrations_material_blog.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@
1414
# ##################################
1515

1616
# Standard library
17+
import tempfile
1718
import unittest
1819
from logging import DEBUG, getLogger
1920
from pathlib import Path
21+
from traceback import format_exception
2022

2123
# 3rd party
24+
import feedparser
2225
from mkdocs.config import load_config
2326

2427
# package
@@ -41,6 +44,24 @@ class TestRssPluginIntegrationsMaterialBlog(BaseTest):
4144
"""Test integration of Material Blog plugin with RSS plugin."""
4245

4346
# -- 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_items_material_blog_enabled_but_integration_disabled.yml"
53+
).resolve()
54+
)
55+
)
56+
57+
integration_social_cards = IntegrationMaterialBlog(
58+
mkdocs_config=cfg_mkdocs,
59+
switch_force=cfg_mkdocs.plugins.get("rss").config.use_material_blog,
60+
)
61+
self.assertTrue(integration_social_cards.IS_THEME_MATERIAL)
62+
self.assertTrue(integration_social_cards.IS_BLOG_PLUGIN_ENABLED)
63+
self.assertFalse(integration_social_cards.IS_ENABLED)
64+
4465
def test_plugin_config_blog_enabled(self):
4566
# default reference
4667
cfg_mkdocs = load_config(
@@ -52,6 +73,57 @@ def test_plugin_config_blog_enabled(self):
5273
self.assertTrue(integration_social_cards.IS_BLOG_PLUGIN_ENABLED)
5374
self.assertTrue(integration_social_cards.IS_ENABLED)
5475

76+
def test_simple_build(self):
77+
with tempfile.TemporaryDirectory() as tmpdirname:
78+
cli_result = self.build_docs_setup(
79+
testproject_path="docs",
80+
mkdocs_yml_filepath=Path(
81+
"tests/fixtures/mkdocs_items_material_blog_enabled.yml"
82+
),
83+
output_path=tmpdirname,
84+
strict=False,
85+
)
86+
87+
if cli_result.exception is not None:
88+
e = cli_result.exception
89+
logger.debug(format_exception(type(e), e, e.__traceback__))
90+
91+
self.assertEqual(cli_result.exit_code, 0)
92+
self.assertIsNone(cli_result.exception)
93+
94+
# created items
95+
feed_parsed = feedparser.parse(Path(tmpdirname) / "feed_rss_created.xml")
96+
self.assertEqual(feed_parsed.bozo, 0)
97+
98+
# updated items
99+
feed_parsed = feedparser.parse(Path(tmpdirname) / "feed_rss_updated.xml")
100+
self.assertEqual(feed_parsed.bozo, 0)
101+
102+
with tempfile.TemporaryDirectory() as tmpdirname:
103+
cli_result = self.build_docs_setup(
104+
testproject_path="docs",
105+
mkdocs_yml_filepath=Path(
106+
"tests/fixtures/mkdocs_items_material_blog_enabled_but_integration_disabled.yml"
107+
),
108+
output_path=tmpdirname,
109+
strict=False,
110+
)
111+
112+
if cli_result.exception is not None:
113+
e = cli_result.exception
114+
logger.debug(format_exception(type(e), e, e.__traceback__))
115+
116+
self.assertEqual(cli_result.exit_code, 0)
117+
self.assertIsNone(cli_result.exception)
118+
119+
# created items
120+
feed_parsed = feedparser.parse(Path(tmpdirname) / "feed_rss_created.xml")
121+
self.assertEqual(feed_parsed.bozo, 0)
122+
123+
# updated items
124+
feed_parsed = feedparser.parse(Path(tmpdirname) / "feed_rss_updated.xml")
125+
self.assertEqual(feed_parsed.bozo, 0)
126+
55127

56128
# ##############################################################################
57129
# ##### Stand alone program ########

0 commit comments

Comments
 (0)