Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion ellar/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
"""Ellar - Python ASGI web framework for building fast, efficient, and scalable RESTful APIs and server-side applications."""

__version__ = "0.8.4"

9 changes: 8 additions & 1 deletion ellar/core/templating/service.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import typing as t
from functools import lru_cache

Expand All @@ -13,8 +14,14 @@

@lru_cache(1200)
def get_template_name(template_name: str) -> str:
if not template_name.endswith(".html"):
# Split the filename and extension
name, ext = os.path.splitext(template_name)

# If there's no extension, add .html
if not ext:
return template_name + ".html"

# Otherwise, return the original name
return template_name


Expand Down
27 changes: 27 additions & 0 deletions tests/test_templating/ test_get_template_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import pytest
from ellar.core.templating.service import get_template_name


@pytest.mark.parametrize(
"input_name, expected_output",
[
("template", "template.html"),
("page.html", "page.html"),
("document.txt", "document.txt"),
("sds.rd.xml", "sds.rd.xml"),
("nested/path/file", "nested/path/file.html"),
("nested/path/file.jpg", "nested/path/file.jpg"),
("", ".html"), # Edge case: empty string
(".gitignore", ".gitignore"), # Edge case: hidden file
],
)
def test_get_template_name(input_name, expected_output):
assert get_template_name(input_name) == expected_output


def test_get_template_name_caching():
# Test that the function is actually cached
assert get_template_name.cache_info().hits == 0
get_template_name("test")
get_template_name("test")
assert get_template_name.cache_info().hits == 1
Loading