Skip to content

Commit

Permalink
test: add tests for render_partial_to_target
Browse files Browse the repository at this point in the history
  • Loading branch information
danjac committed Jan 10, 2025
1 parent 26c6efb commit edcdb59
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions radiofeed/tests/test_partials.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import pytest
from django_htmx.middleware import HtmxDetails

from radiofeed.partials import render_partial_for_target


class TestRenderPartialForTarget:
@pytest.fixture
def mock_render(self, mocker):
return mocker.patch("radiofeed.partials.render")

def test_target_matches(self, rf, mock_render):
request = rf.get("/", HTTP_HX_TARGET="target", HTTP_HX_REQUEST="true")
request.htmx = HtmxDetails(request)

render_partial_for_target(
request,
"template.html",
target="target",
partial="partial",
)
mock_render.assert_called_once_with(request, "template.html#partial", None)

def test_target_not_matches(self, rf, mock_render):
request = rf.get("/", HTTP_HX_TARGET="other", HTTP_HX_REQUEST="true")
request.htmx = HtmxDetails(request)

render_partial_for_target(
request,
"template.html",
target="target",
partial="partial",
)
mock_render.assert_called_once_with(request, "template.html", None)

def test_target_not_htmx(self, rf, mock_render):
request = rf.get("/")
request.htmx = HtmxDetails(request)

render_partial_for_target(
request,
"template.html",
target="target",
partial="partial",
)
mock_render.assert_called_once_with(request, "template.html", None)

0 comments on commit edcdb59

Please sign in to comment.