Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
332154e7
Kaydet (Commit)
332154e7
authored
Ara 14, 2014
tarafından
Aymeric Augustin
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Added basic tests for template backends.
üst
1eca0e95
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
113 additions
and
0 deletions
+113
-0
base.txt
tests/requirements/base.txt
+1
-0
__init__.py
tests/template_backends/__init__.py
+0
-0
hello.html
.../template_backends/forbidden/template_backends/hello.html
+1
-0
csrf.html
tests/template_backends/jinja2/template_backends/csrf.html
+1
-0
hello.html
tests/template_backends/jinja2/template_backends/hello.html
+1
-0
csrf.html
...ate_backends/template_strings/template_backends/csrf.html
+1
-0
hello.html
...te_backends/template_strings/template_backends/hello.html
+1
-0
csrf.html
...s/template_backends/templates/template_backends/csrf.html
+1
-0
hello.html
.../template_backends/templates/template_backends/hello.html
+1
-0
test_django.py
tests/template_backends/test_django.py
+9
-0
test_dummy.py
tests/template_backends/test_dummy.py
+70
-0
test_jinja2.py
tests/template_backends/test_jinja2.py
+26
-0
No files found.
tests/requirements/base.txt
Dosyayı görüntüle @
332154e7
bcrypt
docutils
jinja2
# move to py2.txt when dropping Python 3.2
mock
numpy
...
...
tests/template_backends/__init__.py
0 → 100644
Dosyayı görüntüle @
332154e7
tests/template_backends/forbidden/template_backends/hello.html
0 → 100644
Dosyayı görüntüle @
332154e7
Hu ho.
tests/template_backends/jinja2/template_backends/csrf.html
0 → 100644
Dosyayı görüntüle @
332154e7
{{ csrf_input }}
tests/template_backends/jinja2/template_backends/hello.html
0 → 100644
Dosyayı görüntüle @
332154e7
Hello {{ name }}!
tests/template_backends/template_strings/template_backends/csrf.html
0 → 100644
Dosyayı görüntüle @
332154e7
$csrf_input
tests/template_backends/template_strings/template_backends/hello.html
0 → 100644
Dosyayı görüntüle @
332154e7
Hello $name!
tests/template_backends/templates/template_backends/csrf.html
0 → 100644
Dosyayı görüntüle @
332154e7
{% csrf_token %}
tests/template_backends/templates/template_backends/hello.html
0 → 100644
Dosyayı görüntüle @
332154e7
Hello {{ name }}!
tests/template_backends/test_django.py
0 → 100644
Dosyayı görüntüle @
332154e7
from
django.template.backends.django
import
DjangoTemplates
from
.test_dummy
import
TemplateStringsTests
class
DjangoTemplatesTests
(
TemplateStringsTests
):
engine_class
=
DjangoTemplates
backend_name
=
'django'
tests/template_backends/test_dummy.py
0 → 100644
Dosyayı görüntüle @
332154e7
# coding: utf-8
from
__future__
import
unicode_literals
from
django.http
import
HttpRequest
from
django.middleware.csrf
import
CsrfViewMiddleware
,
get_token
from
django.template
import
TemplateDoesNotExist
from
django.template.backends.dummy
import
TemplateStrings
from
django.test
import
SimpleTestCase
class
TemplateStringsTests
(
SimpleTestCase
):
engine_class
=
TemplateStrings
backend_name
=
'dummy'
options
=
{}
@classmethod
def
setUpClass
(
cls
):
params
=
{
'DIRS'
:
[],
'APP_DIRS'
:
True
,
'NAME'
:
cls
.
backend_name
,
'OPTIONS'
:
cls
.
options
,
}
cls
.
engine
=
cls
.
engine_class
(
params
)
def
test_from_string
(
self
):
template
=
self
.
engine
.
from_string
(
"Hello!
\n
"
)
content
=
template
.
render
()
self
.
assertEqual
(
content
,
"Hello!
\n
"
)
def
test_get_template
(
self
):
template
=
self
.
engine
.
get_template
(
'template_backends/hello.html'
)
content
=
template
.
render
({
'name'
:
'world'
})
self
.
assertEqual
(
content
,
"Hello world!
\n
"
)
def
test_get_template_non_existing
(
self
):
with
self
.
assertRaises
(
TemplateDoesNotExist
):
self
.
engine
.
get_template
(
'template_backends/non_existing.html'
)
def
test_html_escaping
(
self
):
template
=
self
.
engine
.
get_template
(
'template_backends/hello.html'
)
context
=
{
'name'
:
'<script>alert("XSS!");</script>'
}
content
=
template
.
render
(
context
)
self
.
assertIn
(
'<script>'
,
content
)
self
.
assertNotIn
(
'<script>'
,
content
)
def
test_csrf_token
(
self
):
request
=
HttpRequest
()
CsrfViewMiddleware
()
.
process_view
(
request
,
lambda
r
:
None
,
(),
{})
template
=
self
.
engine
.
get_template
(
'template_backends/csrf.html'
)
content
=
template
.
render
(
request
=
request
)
expected
=
(
'<input type="hidden" name="csrfmiddlewaretoken" '
'value="{}" />'
.
format
(
get_token
(
request
)))
self
.
assertHTMLEqual
(
content
,
expected
)
def
test_no_directory_traversal
(
self
):
with
self
.
assertRaises
(
TemplateDoesNotExist
):
self
.
engine
.
get_template
(
'../forbidden/template_backends/hello.html'
)
def
test_non_ascii_characters
(
self
):
template
=
self
.
engine
.
get_template
(
'template_backends/hello.html'
)
content
=
template
.
render
({
'name'
:
'Jérôme'
})
self
.
assertEqual
(
content
,
"Hello Jérôme!
\n
"
)
tests/template_backends/test_jinja2.py
0 → 100644
Dosyayı görüntüle @
332154e7
import
sys
from
unittest
import
skipIf
# Jinja2 doesn't run on Python 3.2 because it uses u-prefixed unicode strings.
if
sys
.
version_info
[:
2
]
==
(
2
,
7
)
or
sys
.
version_info
[:
2
]
>=
(
3
,
3
):
try
:
import
jinja2
except
ImportError
:
jinja2
=
None
Jinja2
=
None
else
:
from
django.template.backends.jinja2
import
Jinja2
else
:
jinja2
=
None
Jinja2
=
None
from
.test_dummy
import
TemplateStringsTests
@skipIf
(
jinja2
is
None
,
"this test requires jinja2"
)
class
Jinja2Tests
(
TemplateStringsTests
):
engine_class
=
Jinja2
backend_name
=
'jinja2'
options
=
{
'keep_trailing_newline'
:
True
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment