-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1eed3ca
commit 13923f5
Showing
2 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
from pathlib import Path | ||
from unittest.mock import MagicMock | ||
|
||
from rich.console import Console | ||
|
||
from blurry.markdown.front_matter import get_data | ||
from blurry.schema_validation import validate_front_matter_as_schema | ||
|
||
MARKDOWN_WITH_VALID_TOML_FRONT_MATTER = """ | ||
+++ | ||
"@type" = "WebPage" | ||
name = "Introduction" | ||
abstract = "A Python-powered static site generator with a focus on page speed and SEO." | ||
datePublished = 2023-04-09 | ||
+++ | ||
# Blurry: A Python-powered static site generator | ||
""".strip() | ||
|
||
|
||
def test_validate_front_matter_as_schema_with_valid_front_matter(): | ||
_, front_matter = get_data(MARKDOWN_WITH_VALID_TOML_FRONT_MATTER) | ||
path = Path("pages/intro.md") | ||
test_console = Console() | ||
test_console.print = MagicMock() | ||
validate_front_matter_as_schema(path, front_matter, test_console) | ||
assert not test_console.print.called | ||
|
||
|
||
MARKDOWN_WITH_EXTRA_VALUE_IN_TOML_FRONT_MATTER = """ | ||
+++ | ||
"@type" = "WebPage" | ||
name = "Introduction" | ||
abstract = "A Python-powered static site generator with a focus on page speed and SEO." | ||
datePublished = 2023-04-09 | ||
extra_value = true | ||
+++ | ||
# Blurry: A Python-powered static site generator | ||
""".strip() | ||
|
||
|
||
def test_validate_front_matter_as_schema_with_extra_value(): | ||
_, front_matter = get_data(MARKDOWN_WITH_EXTRA_VALUE_IN_TOML_FRONT_MATTER) | ||
path = Path("pages/intro.md") | ||
test_console = Console() | ||
test_console.print = MagicMock() | ||
validate_front_matter_as_schema(path, front_matter, test_console) | ||
test_console.print.assert_called_with( | ||
"pages/intro.md: WebPage schema validation error: extra fields not permitted: ('extra_value',)" | ||
) | ||
|
||
|
||
MARKDOWN_WITH_NON_SCHEMA_VALUE_IN_TOML_FRONT_MATTER = """ | ||
+++ | ||
"@type" = "WebPage" | ||
name = "Introduction" | ||
abstract = "A Python-powered static site generator with a focus on page speed and SEO." | ||
datePublished = 2023-04-09 | ||
~valid_extra_value = true | ||
+++ | ||
# Blurry: A Python-powered static site generator | ||
""".strip() | ||
|
||
|
||
def test_validate_front_matter_as_schema_with_non_schema_value(): | ||
_, front_matter = get_data(MARKDOWN_WITH_NON_SCHEMA_VALUE_IN_TOML_FRONT_MATTER) | ||
path = Path("pages/intro.md") | ||
test_console = Console() | ||
test_console.print = MagicMock() | ||
validate_front_matter_as_schema(path, front_matter, test_console) | ||
assert not test_console.print.called |