add tests for test_fix_html_tags_stripe_tag

This commit is contained in:
Denis-Cosmin NUTIU 2023-06-01 22:19:57 +03:00
parent a2811a73e3
commit 3c20d726cf
4 changed files with 42 additions and 4 deletions

View file

@ -1,5 +1,5 @@
def handle_regex_heuristics(line: str) -> str: def handle_regex_heuristics(line: str) -> str:
""" """
Manipulates a line without tags by using regex heuristics. Manipulates a line by using regex heuristics.
""" """
return line return line

View file

@ -82,7 +82,7 @@ class WordpressMarkdownConverter:
if tags: if tags:
fixed_tags = self.fix_html_tags(tags) fixed_tags = self.fix_html_tags(tags)
if fixed_tags: if fixed_tags:
fixed_lines.extend(fixed_tags) fixed_lines.append("".join(fixed_tags))
def convert_post_content(self, post_content: str) -> str: def convert_post_content(self, post_content: str) -> str:
""" """

View file

@ -15,6 +15,9 @@ from app.tests.utils import make_fake_configurator
], ],
) )
def test_header_rewrite_author(author_rewrite, input_header, expected_header): def test_header_rewrite_author(author_rewrite, input_header, expected_header):
"""
Test the header rewrite author functionality.
"""
configurator = make_fake_configurator( configurator = make_fake_configurator(
"wordpress_markdown_converter", "wordpress_markdown_converter",
ConverterOptions( ConverterOptions(
@ -35,6 +38,9 @@ def test_header_rewrite_author(author_rewrite, input_header, expected_header):
], ],
) )
def test_header_fields_drop(header_fields_drop, input_header, expected_header): def test_header_fields_drop(header_fields_drop, input_header, expected_header):
"""
Test the header fields drop functionality.
"""
configurator = make_fake_configurator( configurator = make_fake_configurator(
"wordpress_markdown_converter", "wordpress_markdown_converter",
ConverterOptions( ConverterOptions(
@ -63,6 +69,36 @@ def test_header_fields_drop(header_fields_drop, input_header, expected_header):
], ],
) )
def test_fix_html_tags_detect_youtube_links(input_lines, expected_lines): def test_fix_html_tags_detect_youtube_links(input_lines, expected_lines):
"""
Ensure fix_html_tags detects youtube links.
"""
configurator = make_fake_configurator(
"wordpress_markdown_converter",
ConverterOptions(),
)
converter = WordpressMarkdownConverter(configurator)
assert converter.fix_html_tags(input_lines) == expected_lines
@pytest.mark.parametrize(
"input_lines, expected_lines",
[
([], []),
([""], ["\n"]),
(["<p>Test</p>"], ["Test"]),
(["<p>Test</p>", "<p>Test</p>"], ["Test", "Test"]),
(["<p>Te<span>st</span></p>"], ["Test"]),
(["<p>Te<span><span>s</span><span class='hi'>t</span></span></p>"], ["Test"]),
(
["<pre>preTe<ImportantC#Tag>st</ImportantC#Tag></pre></pre>"],
["preTest"],
),
],
)
def test_fix_html_tags_stripe_tag(input_lines, expected_lines):
"""
Ensure fix_html_tags removes the tag and tested tags.
"""
configurator = make_fake_configurator( configurator = make_fake_configurator(
"wordpress_markdown_converter", "wordpress_markdown_converter",
ConverterOptions(), ConverterOptions(),

View file

@ -1,6 +1,6 @@
logging_level: "INFO" logging_level: "INFO"
source_path: "/home/denis/PycharmProjects/jekyll-to-hugo/my_test_data/_posts" source_path: "/Users/dnutiu/PycharmProjects/jekyll-to-hugo/my_test_data/_posts"
output_path: "/home/denis/PycharmProjects/jekyll-to-hugo/my_test_data/quickstart/content/posts" output_path: "/Users/dnutiu/NucuLabsProjects/NucuLabsDevBlog/content/posts"
converter: "wordpress_markdown_converter" converter: "wordpress_markdown_converter"
converter_options: converter_options:
author_rewrite: "NucuLabs.dev" author_rewrite: "NucuLabs.dev"
@ -9,6 +9,8 @@ converter_options:
target: "/" target: "/"
- source: "https://nuculabs.wordpress.com/" - source: "https://nuculabs.wordpress.com/"
target: "https://nuculabs.dev/posts/" target: "https://nuculabs.dev/posts/"
- source: "https://twitter.com/metonymyqt"
target: "https://twitter.com/nuculabs"
header_fields_drop: header_fields_drop:
- restapi_import_id - restapi_import_id
- original_post_id - original_post_id