def test_convert_tag_sting_to_tag_list(html_string, expected, schema):
    conversion_settings = ConversionSettings()
    conversion_settings.metadata_schema = schema
    metadata_processor = MetaDataProcessor(conversion_settings)

    metadata_processor.parse_html_metadata(html_string)

    metadata_processor.convert_tag_sting_to_tag_list()

    assert metadata_processor.metadata == expected
def test_add_text_metadata_to_content(md_string, markdown_conversion_input,
                                      expected):
    conversion_settings = ConversionSettings()
    conversion_settings.markdown_conversion_input = markdown_conversion_input
    conversion_settings.metadata_schema = ['title', 'ctime', 'mtime', 'tag']
    metadata_processor = MetaDataProcessor(conversion_settings)
    metadata_processor.parse_md_metadata(md_string)
    content = "hello"

    result = metadata_processor.add_text_metadata_to_content(content)

    assert result == expected
def test_add_tag_prefix_if_required(md_string, expected):
    conversion_settings = ConversionSettings()
    conversion_settings.tag_prefix = '#'
    conversion_settings.metadata_schema = ['']
    metadata_processor = MetaDataProcessor(conversion_settings)

    # md_string = "---\nctime: '202102122352'\nmtime: '202104242208'\ntag:\n- Tag1\n- Tag1/SubTag1\n- Tag1/SubTag1/SubSubTag1\n- Tag2\ntitle: test page\n---\n\n# This is H1"
    # expected = {'ctime': '202102122352', 'mtime': '202104242208', 'tag': ['#Tag1', '#Tag1/SubTag1', '#Tag1/SubTag1/SubSubTag1', '#Tag2'], 'title': 'test page'}

    metadata_processor.parse_md_metadata(md_string)

    metadata_processor.add_tag_prefix_if_required()

    assert metadata_processor.metadata == expected
def test_split_tags_if_required_with_tags_key(html_string, expected):
    conversion_settings = ConversionSettings()
    conversion_settings.split_tags = True
    conversion_settings.metadata_schema = ['']
    metadata_processor = MetaDataProcessor(conversion_settings)

    metadata_processor.parse_html_metadata(html_string)

    metadata_processor.convert_tag_sting_to_tag_list()

    if 'tags' in metadata_processor.metadata:
        assert sorted(metadata_processor.metadata['tags']) == expected

    if 'tag' in metadata_processor.metadata:
        assert sorted(metadata_processor.metadata['tag']) == expected