123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- from ..parser import parse
- def test_parser_converts_unmarked_links_to_hrefs(request_mock, user, snapshot):
- text = "Lorem ipsum http://test.com"
- result = parse(text, request_mock, user, minify=False)
- snapshot.assert_match(result["parsed_text"])
- def test_parser_skips_links_in_inline_code_markdown(request_mock, user, snapshot):
- text = "Lorem ipsum `http://test.com`"
- result = parse(text, request_mock, user, minify=False)
- snapshot.assert_match(result["parsed_text"])
- def test_parser_skips_links_in_inline_code_bbcode(request_mock, user, snapshot):
- text = "Lorem ipsum [code]http://test.com[/code]"
- result = parse(text, request_mock, user, minify=False)
- snapshot.assert_match(result["parsed_text"])
- def test_parser_skips_links_in_code_bbcode(request_mock, user, snapshot):
- text = """
- [code]
- http://test.com
- [/code]
- """
- result = parse(text, request_mock, user, minify=False)
- snapshot.assert_match(result["parsed_text"])
- def test_absolute_link_to_site_is_changed_to_relative_link(
- request_mock, user, snapshot
- ):
- text = "clean_links step cleans http://example.com"
- result = parse(text, request_mock, user, minify=False)
- snapshot.assert_match(result["parsed_text"])
- def test_absolute_link_to_site_is_added_to_internal_links_list(request_mock, user):
- text = "clean_links step cleans http://example.com"
- result = parse(text, request_mock, user, minify=False)
- assert result["internal_links"] == ["/"]
- def test_absolute_link_to_site_without_schema_is_changed_to_relative_link(
- request_mock, user, snapshot
- ):
- text = "clean_links step cleans example.com"
- result = parse(text, request_mock, user, minify=False)
- snapshot.assert_match(result["parsed_text"])
- def test_absolute_link_to_site_without_schema_is_added_to_internal_links_list(
- request_mock, user
- ):
- text = "clean_links step cleans example.com"
- result = parse(text, request_mock, user, minify=False)
- assert result["internal_links"] == ["/"]
- def test_absolute_link_with_path_to_site_is_changed_to_relative_link(
- request_mock, user, snapshot
- ):
- text = "clean_links step cleans http://example.com/somewhere-something/"
- result = parse(text, request_mock, user, minify=False)
- snapshot.assert_match(result["parsed_text"])
- def test_absolute_link_with_path_to_site_is_added_to_internal_links_list(
- request_mock, user
- ):
- text = "clean_links step cleans http://example.com/somewhere-something/"
- result = parse(text, request_mock, user, minify=False)
- assert result["internal_links"] == ["/somewhere-something/"]
- def test_full_link_with_path_text_is_set_to_domain_and_path(request_mock, user):
- text = "clean_links step cleans http://example.com/somewhere-something/"
- result = parse(text, request_mock, user, minify=False)
- assert ">example.com/somewhere-something/<" in result["parsed_text"]
- def test_outgoing_link_is_added_to_outgoing_links_list(request_mock, user):
- text = "clean_links step cleans https://other.com"
- result = parse(text, request_mock, user, minify=False)
- assert result["outgoing_links"] == ["other.com"]
- def test_outgoing_link_without_scheme_is_added_to_outgoing_links_list(
- request_mock, user
- ):
- text = "clean_links step cleans other.com"
- result = parse(text, request_mock, user, minify=False)
- assert result["outgoing_links"] == ["other.com"]
- def test_outgoing_link_with_path_is_added_to_outgoing_links_list(request_mock, user):
- text = "clean_links step cleans other.com/some/path/"
- result = parse(text, request_mock, user, minify=False)
- assert result["outgoing_links"] == ["other.com/some/path/"]
- def test_local_image_is_changed_to_relative_link(request_mock, user, snapshot):
- text = "clean_links step cleans !(example.com/media/img.png)"
- result = parse(text, request_mock, user, minify=False)
- snapshot.assert_match(result["parsed_text"])
- def test_local_image_is_added_to_images_list(request_mock, user):
- text = "clean_links step cleans !(example.com/media/img.png)"
- result = parse(text, request_mock, user, minify=False)
- assert result["images"] == ["/media/img.png"]
- def test_remote_image_is_added_to_images_list(request_mock, user):
- text = "clean_links step cleans !(other.com/media/img.png)"
- result = parse(text, request_mock, user, minify=False)
- assert result["images"] == ["other.com/media/img.png"]
- def test_local_image_link_is_added_to_images_and_links_lists(request_mock, user):
- text = "clean_links step cleans [!(example.com/media/img.png)](example.com/test/)"
- result = parse(text, request_mock, user, minify=False)
- assert result["internal_links"] == ["/test/"]
- assert result["images"] == ["/media/img.png"]
- def test_remote_image_link_is_added_to_images_and_links_lists(request_mock, user):
- text = "clean_links step cleans [!(other.com/media/img.png)](other.com/test/)"
- result = parse(text, request_mock, user, minify=False)
- assert result["outgoing_links"] == ["other.com/test/"]
- assert result["images"] == ["other.com/media/img.png"]
- def test_parser_adds_shva_to_attachment_link_querystring_if_force_option_is_enabled(
- request_mock, user
- ):
- text = "clean_links step cleans "
- result = parse(text, request_mock, user, minify=False, force_shva=True)
- assert "/a/thumb/test/43/?shva=1" in result["parsed_text"]
- def test_parser_skips_shva_in_attachment_link_querystring_if_force_option_is_omitted(
- request_mock, user
- ):
- text = "clean_links step cleans "
- result = parse(text, request_mock, user, minify=False)
- assert "?shva=1" not in result["parsed_text"]
|