Skip to content

Commit 257d79c

Browse files
committed
Added test for templating with static file reference
1 parent f6ebf20 commit 257d79c

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<!DOCTYPE html>
2+
<head>
3+
<title>Welcome - Ellar ASGI Python Framework</title>
4+
<link rel="stylesheet" href="{{ url_for('static', path='watever.txt') }}"/>
5+
</head>

tests/test_templating/test_renderer.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import re
22
from pathlib import Path
33

4-
from ellar.common import Controller, get
4+
from ellar.common import Controller, get, render
55
from ellar.core import ControllerBase, TestClientFactory
66
from ellar.core.templating import (
77
TemplateResponse,
@@ -30,6 +30,15 @@ def another_index2(self, first_name: str, last_name: str):
3030
)
3131

3232

33+
@Controller(prefix="/template-static")
34+
class TemplateWithStaticsController(ControllerBase):
35+
@get("/index", response={200: TemplateResponse})
36+
@render("watever.html")
37+
def index(self):
38+
"""Looks for ellar/index since use_mvc=True"""
39+
return {}
40+
41+
3342
tm = TestClientFactory.create_test_module(
3443
controllers=(EllarController,), base_directory=BASEDIR, template_folder="templates"
3544
)
@@ -52,3 +61,19 @@ def test_render_template():
5261
content == '<!DOCTYPE html> <html lang="en"> '
5362
'<head> <meta charset="UTF-8"> <title>Index Page</title> </head> <body> </body> </html>'
5463
)
64+
65+
66+
def test_render_template_with_static_ref():
67+
test_module = TestClientFactory.create_test_module(
68+
controllers=(TemplateWithStaticsController,),
69+
template_folder="templates",
70+
base_directory=Path(__file__).resolve().parent,
71+
)
72+
client = test_module.get_client()
73+
response = client.get("/template-static/index")
74+
assert response.status_code == 200
75+
content = re.sub("\\s+", " ", response.text).strip()
76+
assert (
77+
content
78+
== '<!DOCTYPE html> <head> <title>Welcome - Ellar ASGI Python Framework</title> <link rel="stylesheet" href="http://testserver/static/watever.txt"/> </head>'
79+
)

0 commit comments

Comments
 (0)