Skip to content

Commit

Permalink
remove render_from_request class method
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuadavidthomas committed Feb 23, 2024
1 parent fe79fce commit df0df68
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 24 deletions.
6 changes: 0 additions & 6 deletions src/django_simple_nav/nav.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions src/django_simple_nav/templatetags/django_simple_nav.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
24 changes: 9 additions & 15 deletions tests/test_nav.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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"}
Expand Down

0 comments on commit df0df68

Please sign in to comment.