-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests for render_partial_to_target
- Loading branch information
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |