add tests for rewrite author
This commit is contained in:
parent
ffd9e152a8
commit
57fc728bd6
4 changed files with 62 additions and 3 deletions
|
@ -43,7 +43,9 @@ class WordpressMarkdownConverter:
|
||||||
with key_error_silence():
|
with key_error_silence():
|
||||||
del header[field]
|
del header[field]
|
||||||
# rewrite header fields
|
# rewrite header fields
|
||||||
|
with key_error_silence():
|
||||||
header["guid"] = header["guid"].replace("http://localhost", "")
|
header["guid"] = header["guid"].replace("http://localhost", "")
|
||||||
|
with key_error_silence():
|
||||||
header["author"] = self.configurator.converter_options.author_rewrite
|
header["author"] = self.configurator.converter_options.author_rewrite
|
||||||
return header
|
return header
|
||||||
|
|
||||||
|
@ -53,7 +55,7 @@ class WordpressMarkdownConverter:
|
||||||
if line == "":
|
if line == "":
|
||||||
fixed_lines.append("\n")
|
fixed_lines.append("\n")
|
||||||
continue
|
continue
|
||||||
soup = BeautifulSoup(line)
|
soup = BeautifulSoup(line, features="html.parser")
|
||||||
for content in soup.contents:
|
for content in soup.contents:
|
||||||
if isinstance(content, Tag):
|
if isinstance(content, Tag):
|
||||||
# Check if it is a youtube video and add it as a shortcode.
|
# Check if it is a youtube video and add it as a shortcode.
|
||||||
|
|
0
app/tests/converter/__init__.py
Normal file
0
app/tests/converter/__init__.py
Normal file
27
app/tests/converter/wordpress_markdown_test.py
Normal file
27
app/tests/converter/wordpress_markdown_test.py
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from app.config import ConverterOptions
|
||||||
|
from app.converter import WordpressMarkdownConverter
|
||||||
|
from app.tests.utils import make_fake_configurator
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"author_rewrite, input_header, expected_header",
|
||||||
|
[
|
||||||
|
("", {"author": "author"}, {"author": ""}),
|
||||||
|
("", {}, {"author": ""}),
|
||||||
|
("", {"a": 1}, {"a": 1, "author": ""}),
|
||||||
|
("NucuLabs.dev", {"author": "Denis"}, {"author": "NucuLabs.dev"}),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_fix_hugo_header_rewrite_author(author_rewrite, input_header, expected_header):
|
||||||
|
configurator = make_fake_configurator(
|
||||||
|
"wordpress_markdown_converter",
|
||||||
|
ConverterOptions(
|
||||||
|
author_rewrite=author_rewrite,
|
||||||
|
links_rewrite=[],
|
||||||
|
header_fields_drop=[],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
converter = WordpressMarkdownConverter(configurator)
|
||||||
|
assert converter.fix_hugo_header(input_header) == expected_header
|
30
app/tests/utils.py
Normal file
30
app/tests/utils.py
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
from app.config import ConverterOptions, Configurator
|
||||||
|
|
||||||
|
|
||||||
|
def make_fake_configurator(converter: str, converter_options: ConverterOptions):
|
||||||
|
class FakeConfigurator(Configurator):
|
||||||
|
logging_level: str = "INFO"
|
||||||
|
source_path: str = ""
|
||||||
|
output_path: str = ""
|
||||||
|
converter: str = ""
|
||||||
|
converter_options = ConverterOptions(
|
||||||
|
author_rewrite="",
|
||||||
|
links_rewrite=[],
|
||||||
|
header_fields_drop=[],
|
||||||
|
)
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
env_file_encoding = "utf-8"
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def customise_sources(
|
||||||
|
cls,
|
||||||
|
init_settings,
|
||||||
|
env_settings,
|
||||||
|
file_secret_settings,
|
||||||
|
):
|
||||||
|
return (init_settings,)
|
||||||
|
|
||||||
|
configurator = FakeConfigurator()
|
||||||
|
configurator.converter_options = converter_options
|
||||||
|
return configurator
|
Loading…
Reference in a new issue