aboutsummaryrefslogtreecommitdiff
path: root/tests/tasks/test_source_parser.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/tasks/test_source_parser.py')
-rw-r--r--tests/tasks/test_source_parser.py88
1 files changed, 48 insertions, 40 deletions
diff --git a/tests/tasks/test_source_parser.py b/tests/tasks/test_source_parser.py
index 3c3a93e..38752b0 100644
--- a/tests/tasks/test_source_parser.py
+++ b/tests/tasks/test_source_parser.py
@@ -24,7 +24,7 @@ def source_parser_module(app: Flask, monkeypatch: pytest.MonkeyPatch) -> ModuleT
return source_parser
-def test_parse_entry_returns_microformats_entry(
+def test_parse_h_entry_returns_microformats_entry(
source_parser_module: ModuleType,
) -> None:
document = parse_html(
@@ -45,13 +45,13 @@ def test_parse_entry_returns_microformats_entry(
assert element is not None
- entry = source_parser_module.parse_entry(element, SOURCE_URL)
+ entry = source_parser_module.parse_h_entry(element, SOURCE_URL)
assert "h-entry" in entry["type"]
assert entry["properties"]["url"] == [SOURCE_URL]
-def test_parse_entry_rejects_non_entry(source_parser_module: ModuleType) -> None:
+def test_parse_h_entry_rejects_non_entry(source_parser_module: ModuleType) -> None:
document = parse_html(
"""
<article>
@@ -68,10 +68,12 @@ def test_parse_entry_rejects_non_entry(source_parser_module: ModuleType) -> None
source_parser_module.SourceScanError,
match="Expected exactly one parsed h-entry",
):
- source_parser_module.parse_entry(element, SOURCE_URL)
+ source_parser_module.parse_h_entry(element, SOURCE_URL)
-def test_primary_entry_returns_source_entry(source_parser_module: ModuleType) -> None:
+def test_find_primary_h_entry_returns_source_entry(
+ source_parser_module: ModuleType,
+) -> None:
document = parse_html(
f"""
<article class="h-entry" id="source">
@@ -90,14 +92,14 @@ def test_primary_entry_returns_source_entry(source_parser_module: ModuleType) ->
"""
)
- element, entry = source_parser_module.primary_entry(document, SOURCE_URL)
+ element, entry = source_parser_module.find_primary_h_entry(document, SOURCE_URL)
assert element["id"] == "source"
assert entry["properties"]["name"] == ["Example post"]
assert entry["properties"]["url"] == [SOURCE_URL]
-def test_primary_entry_rejects_missing_h_entry(
+def test_find_primary_h_entry_rejects_missing_h_entry(
source_parser_module: ModuleType,
) -> None:
document = parse_html(
@@ -112,10 +114,10 @@ def test_primary_entry_rejects_missing_h_entry(
source_parser_module.SourceScanError,
match="Expected exactly one h-entry, found 0",
):
- source_parser_module.primary_entry(document, SOURCE_URL)
+ source_parser_module.find_primary_h_entry(document, SOURCE_URL)
-def test_primary_entry_rejects_multiple_h_entries(
+def test_find_primary_h_entry_rejects_multiple_h_entries(
source_parser_module: ModuleType,
) -> None:
document = parse_html(
@@ -141,10 +143,12 @@ def test_primary_entry_rejects_multiple_h_entries(
source_parser_module.SourceScanError,
match="Expected exactly one h-entry, found 2",
):
- source_parser_module.primary_entry(document, SOURCE_URL)
+ source_parser_module.find_primary_h_entry(document, SOURCE_URL)
-def test_primary_entry_rejects_nested_h_entry(source_parser_module: ModuleType) -> None:
+def test_find_primary_h_entry_rejects_nested_h_entry(
+ source_parser_module: ModuleType,
+) -> None:
document = parse_html(
f"""
<article class="h-entry">
@@ -170,10 +174,12 @@ def test_primary_entry_rejects_nested_h_entry(source_parser_module: ModuleType)
source_parser_module.SourceScanError,
match="Expected exactly one h-entry, found 2",
):
- source_parser_module.primary_entry(document, SOURCE_URL)
+ source_parser_module.find_primary_h_entry(document, SOURCE_URL)
-def test_primary_entry_rejects_missing_u_url(source_parser_module: ModuleType) -> None:
+def test_find_primary_h_entry_rejects_missing_u_url(
+ source_parser_module: ModuleType,
+) -> None:
document = parse_html(
"""
<article class="h-entry">
@@ -185,10 +191,10 @@ def test_primary_entry_rejects_missing_u_url(source_parser_module: ModuleType) -
)
with pytest.raises(source_parser_module.SourceScanError, match="does not match"):
- source_parser_module.primary_entry(document, SOURCE_URL)
+ source_parser_module.find_primary_h_entry(document, SOURCE_URL)
-def test_primary_entry_rejects_nonmatching_u_url(
+def test_find_primary_h_entry_rejects_nonmatching_u_url(
source_parser_module: ModuleType,
) -> None:
document = parse_html(
@@ -209,10 +215,10 @@ def test_primary_entry_rejects_nonmatching_u_url(
)
with pytest.raises(source_parser_module.SourceScanError, match="does not match"):
- source_parser_module.primary_entry(document, SOURCE_URL)
+ source_parser_module.find_primary_h_entry(document, SOURCE_URL)
-def test_content_element_returns_e_content(source_parser_module: ModuleType) -> None:
+def test_find_e_content_returns_e_content(source_parser_module: ModuleType) -> None:
document = parse_html(
"""
<article class="h-entry">
@@ -227,12 +233,12 @@ def test_content_element_returns_e_content(source_parser_module: ModuleType) ->
assert entry is not None
- content = source_parser_module.content_element(entry)
+ content = source_parser_module.find_e_content(entry)
assert content["id"] == "content"
-def test_content_element_rejects_missing_e_content(
+def test_find_e_content_rejects_missing_e_content(
source_parser_module: ModuleType,
) -> None:
document = parse_html(
@@ -251,10 +257,10 @@ def test_content_element_rejects_missing_e_content(
source_parser_module.SourceScanError,
match="Expected exactly one e-content, found 0",
):
- source_parser_module.content_element(entry)
+ source_parser_module.find_e_content(entry)
-def test_content_element_rejects_multiple_e_content(
+def test_find_e_content_rejects_multiple_e_content(
source_parser_module: ModuleType,
) -> None:
document = parse_html(
@@ -279,10 +285,12 @@ def test_content_element_rejects_multiple_e_content(
source_parser_module.SourceScanError,
match="Expected exactly one e-content, found 2",
):
- source_parser_module.content_element(entry)
+ source_parser_module.find_e_content(entry)
-def test_canonical_url_returns_absolute_url(source_parser_module: ModuleType) -> None:
+def test_declared_canonical_url_returns_absolute_url(
+ source_parser_module: ModuleType,
+) -> None:
document = parse_html(
f"""
<html>
@@ -296,14 +304,14 @@ def test_canonical_url_returns_absolute_url(source_parser_module: ModuleType) ->
"""
)
- result = source_parser_module.canonical_url(
+ result = source_parser_module.declared_canonical_url(
document, relative_path=Path("example/index.html"), base_url=None
)
assert result == SOURCE_URL
-def test_canonical_url_returns_none_when_missing(
+def test_declared_canonical_url_returns_none_when_missing(
source_parser_module: ModuleType,
) -> None:
document = parse_html(
@@ -316,14 +324,14 @@ def test_canonical_url_returns_none_when_missing(
"""
)
- result = source_parser_module.canonical_url(
+ result = source_parser_module.declared_canonical_url(
document, relative_path=Path("example/index.html"), base_url=None
)
assert result is None
-def test_canonical_url_resolves_relative_url_with_base_url(
+def test_declared_canonical_url_resolves_relative_url_with_base_url(
source_parser_module: ModuleType,
) -> None:
source_parser_module.is_http_url.side_effect = [False, True]
@@ -341,7 +349,7 @@ def test_canonical_url_resolves_relative_url_with_base_url(
"""
)
- result = source_parser_module.canonical_url(
+ result = source_parser_module.declared_canonical_url(
document, relative_path=Path("example/index.html"), base_url=BASE_URL
)
@@ -367,7 +375,7 @@ def test_relative_canonical_requires_base_url(source_parser_module: ModuleType)
with pytest.raises(
source_parser_module.SourceScanError, match="relative canonical"
):
- source_parser_module.canonical_url(
+ source_parser_module.declared_canonical_url(
document, relative_path=Path("example/index.html"), base_url=None
)
@@ -389,7 +397,7 @@ def test_empty_canonical_is_rejected(source_parser_module: ModuleType) -> None:
with pytest.raises(
source_parser_module.SourceScanError, match="empty canonical URL"
):
- source_parser_module.canonical_url(
+ source_parser_module.declared_canonical_url(
document, relative_path=Path("example/index.html"), base_url=BASE_URL
)
@@ -907,7 +915,7 @@ def test_scan_source_ignores_reaction_to_matching_hostname(
assert scanned.targets == frozenset()
-def test_canonical_url_rejects_non_http_resolved_url(
+def test_declared_canonical_url_rejects_non_http_resolved_url(
source_parser_module: ModuleType,
) -> None:
source_parser_module.is_http_url.return_value = False
@@ -929,17 +937,17 @@ def test_canonical_url_rejects_non_http_resolved_url(
source_parser_module.SourceScanError,
match="Canonical URL is not a valid HTTP or HTTPS URL",
):
- source_parser_module.canonical_url(
+ source_parser_module.declared_canonical_url(
document, relative_path=Path("example/index.html"), base_url=BASE_URL
)
-def test_property_urls_ignores_non_mapping_properties(
+def test_mf2_string_values_ignores_non_mapping_properties(
source_parser_module: ModuleType,
) -> None:
entry = {"properties": "invalid"}
- assert tuple(source_parser_module.property_urls(entry, "url")) == ()
+ assert tuple(source_parser_module.mf2_string_values(entry, "url")) == ()
@pytest.mark.parametrize(
@@ -960,7 +968,7 @@ def test_property_urls_ignores_non_mapping_properties(
),
],
)
-def test_parse_entry_rejects_invalid_parser_output(
+def test_parse_h_entry_rejects_invalid_parser_output(
source_parser_module: ModuleType,
monkeypatch: MonkeyPatch,
parsed: object,
@@ -981,27 +989,27 @@ def test_parse_entry_rejects_invalid_parser_output(
monkeypatch.setattr(source_parser.mf2py, "parse", lambda **kwargs: parsed)
with pytest.raises(source_parser_module.SourceScanError, match=message):
- source_parser_module.parse_entry(element, SOURCE_URL)
+ source_parser_module.parse_h_entry(element, SOURCE_URL)
-def test_normalize_target_ignores_empty_target(
+def test_normalize_target_url_ignores_empty_target(
source_parser_module: ModuleType,
) -> None:
assert (
- source_parser_module.normalize_target(
+ source_parser_module.normalize_target_url(
" ", base_url=SOURCE_URL, source_url=SOURCE_URL
)
is None
)
-def test_normalize_target_ignores_url_rejected_by_validator(
+def test_normalize_target_url_ignores_url_rejected_by_validator(
source_parser_module: ModuleType,
) -> None:
source_parser_module.is_http_url.return_value = False
assert (
- source_parser_module.normalize_target(
+ source_parser_module.normalize_target_url(
"https://example.com/target", base_url=SOURCE_URL, source_url=SOURCE_URL
)
is None