Skip to content

Commit

Permalink
[refactor] DRY external attributes assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
ftnext committed Aug 8, 2024
1 parent 67ee82b commit 15cb170
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 4 additions & 0 deletions tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ def extract_references(html_path: Path):

def assert_reference_is_external(reference, expected_url: str) -> None:
assert reference["href"] == expected_url
assert_reference_attributes(reference)


def assert_reference_attributes(reference) -> None:
assert "external" in reference["class"]
assert reference["target"] == "_blank"
assert reference["rel"] == ["noopener", "noreferrer"]
6 changes: 2 additions & 4 deletions tests/test_custom_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest

from .helpers import extract_references
from .helpers import assert_reference_attributes, extract_references


@pytest.fixture
Expand Down Expand Up @@ -40,6 +40,4 @@ def test_should_open_new_tab(built_html_path: Path) -> None:
references = extract_references(built_html_path)

assert len(references) == 1
ref = references[0]
assert ref["target"] == "_blank"
assert ref["rel"] == ["noopener", "noreferrer"]
assert_reference_attributes(references[0])

0 comments on commit 15cb170

Please sign in to comment.