1
1
import re
2
2
from pathlib import Path
3
3
4
- from ellar .common import Controller , get
4
+ from ellar .common import Controller , get , render
5
5
from ellar .core import ControllerBase , TestClientFactory
6
6
from ellar .core .templating import (
7
7
TemplateResponse ,
@@ -30,6 +30,15 @@ def another_index2(self, first_name: str, last_name: str):
30
30
)
31
31
32
32
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
+
33
42
tm = TestClientFactory .create_test_module (
34
43
controllers = (EllarController ,), base_directory = BASEDIR , template_folder = "templates"
35
44
)
@@ -52,3 +61,19 @@ def test_render_template():
52
61
content == '<!DOCTYPE html> <html lang="en"> '
53
62
'<head> <meta charset="UTF-8"> <title>Index Page</title> </head> <body> </body> </html>'
54
63
)
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