From df0df6843aafffe657c2bbf3be861434e1bf89dd Mon Sep 17 00:00:00 2001 From: Josh Date: Fri, 23 Feb 2024 14:10:20 -0600 Subject: [PATCH] remove `render_from_request` class method --- src/django_simple_nav/nav.py | 6 ----- .../templatetags/django_simple_nav.py | 6 ++--- tests/test_nav.py | 24 +++++++------------ 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/src/django_simple_nav/nav.py b/src/django_simple_nav/nav.py index 73be0fd..3957ec4 100644 --- a/src/django_simple_nav/nav.py +++ b/src/django_simple_nav/nav.py @@ -33,12 +33,6 @@ def render(self, request: HttpRequest, template_name: str | None = None) -> str: context=context, ) - @classmethod - def render_from_request( - cls, request: HttpRequest, template_name: str | None = None - ) -> str: - return cls().render(request, template_name) - @dataclass(frozen=True) class NavGroup: diff --git a/src/django_simple_nav/templatetags/django_simple_nav.py b/src/django_simple_nav/templatetags/django_simple_nav.py index b5f9d59..ca5c5cc 100644 --- a/src/django_simple_nav/templatetags/django_simple_nav.py +++ b/src/django_simple_nav/templatetags/django_simple_nav.py @@ -39,10 +39,10 @@ def render(self, context): ) from err if isinstance(self.nav, str): - nav = import_string(self.nav) + nav = import_string(self.nav)() else: nav = self.nav - assert hasattr(nav, "render_from_request") + assert hasattr(nav, "render") - return nav.render_from_request(context["request"], self.template_name) + return nav.render(context["request"], self.template_name) diff --git a/tests/test_nav.py b/tests/test_nav.py index e5e864b..c022149 100644 --- a/tests/test_nav.py +++ b/tests/test_nav.py @@ -50,16 +50,18 @@ def test_nav_render(user, expected_count, req): user = baker.make(get_user_model()) req.user = user - rendered_template = DummyNav.render_from_request(req) + + rendered_template = DummyNav().render(req) assert count_anchors(rendered_template) == expected_count -def test_dotted_path_rendering(req): +def test_dotted_path_nav_render(req): req.user = baker.make(get_user_model()) + nav = import_string("tests.navs.DummyNav") - assert nav.render_from_request(req) + assert nav().render(req) @pytest.mark.parametrize( @@ -88,15 +90,15 @@ def test_nav_render_with_permissions(req, permission, expected_count): user.save() req.user = user - rendered_template = DummyNav.render_from_request(req) + rendered_template = DummyNav().render(req) assert count_anchors(rendered_template) == expected_count -def test_nav_render_from_request_with_template_name(req): +def test_nav_render_with_template_name(req): req.user = AnonymousUser() - rendered_template = DummyNav.render_from_request(req, "tests/alternate.html") + rendered_template = DummyNav().render(req, "tests/alternate.html") assert "This is an alternate template." in rendered_template @@ -207,15 +209,7 @@ def get_context_data(self, request): assert context["foo"] == "bar" -def test_render(req): - req.user = baker.make(get_user_model()) - - rendered_template = DummyNav().render(req) - - assert count_anchors(rendered_template) == 10 - - -def test_render_override(req): +def test_get_context_data_override_render(req): class OverrideNav(DummyNav): def get_context_data(self, request): return {"foo": "bar"}