Skip to content

Commit 18ddc5c

Browse files
add tests for django_simple_nav templatetag to round out coverage (#107)
1 parent 4c5c350 commit 18ddc5c

File tree

2 files changed

+50
-5
lines changed

2 files changed

+50
-5
lines changed

src/django_simple_nav/templatetags/django_simple_nav.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@ def get_nav(self, context: Context) -> Nav:
6666
f"Not a valid `Nav` instance: {nav_instance}"
6767
)
6868

69-
if not hasattr(nav_instance, "render"):
70-
raise template.TemplateSyntaxError(
71-
f"`Nav` instance does not have a 'render' method: {nav_instance}"
72-
)
73-
7469
return nav_instance
7570

7671
def get_template_name(self, context: Context) -> str | None:

tests/test_templatetags.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,53 @@ def test_nested_templatetag(req):
115115
rendered_template = template.render(Context({"request": req}))
116116

117117
assert count_anchors(rendered_template) == 14
118+
119+
120+
def test_invalid_dotted_string(req):
121+
template = Template(
122+
"{% load django_simple_nav %} {% django_simple_nav 'path.to.DoesNotExist' %}"
123+
)
124+
125+
with pytest.raises(TemplateSyntaxError):
126+
template.render(Context({"request": req}))
127+
128+
129+
class InvalidNav: ...
130+
131+
132+
def test_invalid_nav_instance(req):
133+
template = Template(
134+
"{% load django_simple_nav %} {% django_simple_nav 'tests.test_templatetags.InvalidNav' %}"
135+
)
136+
137+
with pytest.raises(TemplateSyntaxError):
138+
template.render(Context({"request": req}))
139+
140+
141+
def test_template_name_variable_does_not_exist(req):
142+
template = Template(
143+
"{% load django_simple_nav %} {% django_simple_nav 'tests.navs.DummyNav' nonexistent_template_name_variable %}"
144+
)
145+
146+
with pytest.raises(TemplateSyntaxError):
147+
template.render(Context({"request": req}))
148+
149+
150+
def test_request_not_in_context():
151+
template = Template(
152+
"{% load django_simple_nav %} {% django_simple_nav 'tests.navs.DummyNav' %}"
153+
)
154+
155+
with pytest.raises(TemplateSyntaxError):
156+
template.render(Context())
157+
158+
159+
def test_invalid_request():
160+
class InvalidRequest: ...
161+
162+
template = Template(
163+
"{% load django_simple_nav %} {% django_simple_nav 'tests.navs.DummyNav' %}"
164+
)
165+
166+
with pytest.raises(TemplateSyntaxError):
167+
template.render(Context({"request": InvalidRequest()}))

0 commit comments

Comments
 (0)