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
665e0aa6
Kaydet (Commit)
665e0aa6
authored
Ock 09, 2015
tarafından
Preston Timmons
Kaydeden (comit)
Tim Graham
Ock 09, 2015
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #24094 -- Enabled template tests to run individually.
üst
c8bac4b5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
218 additions
and
211 deletions
+218
-211
custom.py
tests/template_tests/templatetags/custom.py
+0
-160
inclusion.py
tests/template_tests/templatetags/inclusion.py
+167
-0
test_custom.py
tests/template_tests/test_custom.py
+51
-51
No files found.
tests/template_tests/templatetags/custom.py
Dosyayı görüntüle @
665e0aa6
...
@@ -2,7 +2,6 @@ import operator
...
@@ -2,7 +2,6 @@ import operator
from
django
import
template
from
django
import
template
from
django.template.defaultfilters
import
stringfilter
from
django.template.defaultfilters
import
stringfilter
from
django.template.loader
import
get_template
from
django.utils
import
six
from
django.utils
import
six
register
=
template
.
Library
()
register
=
template
.
Library
()
...
@@ -126,165 +125,6 @@ def minustwo_overridden_name(value):
...
@@ -126,165 +125,6 @@ def minustwo_overridden_name(value):
register
.
simple_tag
(
lambda
x
:
x
-
1
,
name
=
'minusone'
)
register
.
simple_tag
(
lambda
x
:
x
-
1
,
name
=
'minusone'
)
@register.inclusion_tag
(
'inclusion.html'
)
def
inclusion_no_params
():
"""Expected inclusion_no_params __doc__"""
return
{
"result"
:
"inclusion_no_params - Expected result"
}
inclusion_no_params
.
anything
=
"Expected inclusion_no_params __dict__"
@register.inclusion_tag
(
get_template
(
'inclusion.html'
))
def
inclusion_no_params_from_template
():
"""Expected inclusion_no_params_from_template __doc__"""
return
{
"result"
:
"inclusion_no_params_from_template - Expected result"
}
inclusion_no_params_from_template
.
anything
=
"Expected inclusion_no_params_from_template __dict__"
@register.inclusion_tag
(
'inclusion.html'
)
def
inclusion_one_param
(
arg
):
"""Expected inclusion_one_param __doc__"""
return
{
"result"
:
"inclusion_one_param - Expected result:
%
s"
%
arg
}
inclusion_one_param
.
anything
=
"Expected inclusion_one_param __dict__"
@register.inclusion_tag
(
get_template
(
'inclusion.html'
))
def
inclusion_one_param_from_template
(
arg
):
"""Expected inclusion_one_param_from_template __doc__"""
return
{
"result"
:
"inclusion_one_param_from_template - Expected result:
%
s"
%
arg
}
inclusion_one_param_from_template
.
anything
=
"Expected inclusion_one_param_from_template __dict__"
@register.inclusion_tag
(
'inclusion.html'
,
takes_context
=
False
)
def
inclusion_explicit_no_context
(
arg
):
"""Expected inclusion_explicit_no_context __doc__"""
return
{
"result"
:
"inclusion_explicit_no_context - Expected result:
%
s"
%
arg
}
inclusion_explicit_no_context
.
anything
=
"Expected inclusion_explicit_no_context __dict__"
@register.inclusion_tag
(
get_template
(
'inclusion.html'
),
takes_context
=
False
)
def
inclusion_explicit_no_context_from_template
(
arg
):
"""Expected inclusion_explicit_no_context_from_template __doc__"""
return
{
"result"
:
"inclusion_explicit_no_context_from_template - Expected result:
%
s"
%
arg
}
inclusion_explicit_no_context_from_template
.
anything
=
"Expected inclusion_explicit_no_context_from_template __dict__"
@register.inclusion_tag
(
'inclusion.html'
,
takes_context
=
True
)
def
inclusion_no_params_with_context
(
context
):
"""Expected inclusion_no_params_with_context __doc__"""
return
{
"result"
:
"inclusion_no_params_with_context - Expected result (context value:
%
s)"
%
context
[
'value'
]}
inclusion_no_params_with_context
.
anything
=
"Expected inclusion_no_params_with_context __dict__"
@register.inclusion_tag
(
get_template
(
'inclusion.html'
),
takes_context
=
True
)
def
inclusion_no_params_with_context_from_template
(
context
):
"""Expected inclusion_no_params_with_context_from_template __doc__"""
return
{
"result"
:
"inclusion_no_params_with_context_from_template - Expected result (context value:
%
s)"
%
context
[
'value'
]}
inclusion_no_params_with_context_from_template
.
anything
=
"Expected inclusion_no_params_with_context_from_template __dict__"
@register.inclusion_tag
(
'inclusion.html'
,
takes_context
=
True
)
def
inclusion_params_and_context
(
context
,
arg
):
"""Expected inclusion_params_and_context __doc__"""
return
{
"result"
:
"inclusion_params_and_context - Expected result (context value:
%
s):
%
s"
%
(
context
[
'value'
],
arg
)}
inclusion_params_and_context
.
anything
=
"Expected inclusion_params_and_context __dict__"
@register.inclusion_tag
(
get_template
(
'inclusion.html'
),
takes_context
=
True
)
def
inclusion_params_and_context_from_template
(
context
,
arg
):
"""Expected inclusion_params_and_context_from_template __doc__"""
return
{
"result"
:
"inclusion_params_and_context_from_template - Expected result (context value:
%
s):
%
s"
%
(
context
[
'value'
],
arg
)}
inclusion_params_and_context_from_template
.
anything
=
"Expected inclusion_params_and_context_from_template __dict__"
@register.inclusion_tag
(
'inclusion.html'
)
def
inclusion_two_params
(
one
,
two
):
"""Expected inclusion_two_params __doc__"""
return
{
"result"
:
"inclusion_two_params - Expected result:
%
s,
%
s"
%
(
one
,
two
)}
inclusion_two_params
.
anything
=
"Expected inclusion_two_params __dict__"
@register.inclusion_tag
(
get_template
(
'inclusion.html'
))
def
inclusion_two_params_from_template
(
one
,
two
):
"""Expected inclusion_two_params_from_template __doc__"""
return
{
"result"
:
"inclusion_two_params_from_template - Expected result:
%
s,
%
s"
%
(
one
,
two
)}
inclusion_two_params_from_template
.
anything
=
"Expected inclusion_two_params_from_template __dict__"
@register.inclusion_tag
(
'inclusion.html'
)
def
inclusion_one_default
(
one
,
two
=
'hi'
):
"""Expected inclusion_one_default __doc__"""
return
{
"result"
:
"inclusion_one_default - Expected result:
%
s,
%
s"
%
(
one
,
two
)}
inclusion_one_default
.
anything
=
"Expected inclusion_one_default __dict__"
@register.inclusion_tag
(
get_template
(
'inclusion.html'
))
def
inclusion_one_default_from_template
(
one
,
two
=
'hi'
):
"""Expected inclusion_one_default_from_template __doc__"""
return
{
"result"
:
"inclusion_one_default_from_template - Expected result:
%
s,
%
s"
%
(
one
,
two
)}
inclusion_one_default_from_template
.
anything
=
"Expected inclusion_one_default_from_template __dict__"
@register.inclusion_tag
(
'inclusion.html'
)
def
inclusion_unlimited_args
(
one
,
two
=
'hi'
,
*
args
):
"""Expected inclusion_unlimited_args __doc__"""
return
{
"result"
:
"inclusion_unlimited_args - Expected result:
%
s"
%
(
', '
.
join
(
six
.
text_type
(
arg
)
for
arg
in
[
one
,
two
]
+
list
(
args
)))}
inclusion_unlimited_args
.
anything
=
"Expected inclusion_unlimited_args __dict__"
@register.inclusion_tag
(
get_template
(
'inclusion.html'
))
def
inclusion_unlimited_args_from_template
(
one
,
two
=
'hi'
,
*
args
):
"""Expected inclusion_unlimited_args_from_template __doc__"""
return
{
"result"
:
"inclusion_unlimited_args_from_template - Expected result:
%
s"
%
(
', '
.
join
(
six
.
text_type
(
arg
)
for
arg
in
[
one
,
two
]
+
list
(
args
)))}
inclusion_unlimited_args_from_template
.
anything
=
"Expected inclusion_unlimited_args_from_template __dict__"
@register.inclusion_tag
(
'inclusion.html'
)
def
inclusion_only_unlimited_args
(
*
args
):
"""Expected inclusion_only_unlimited_args __doc__"""
return
{
"result"
:
"inclusion_only_unlimited_args - Expected result:
%
s"
%
(
', '
.
join
(
six
.
text_type
(
arg
)
for
arg
in
args
))}
inclusion_only_unlimited_args
.
anything
=
"Expected inclusion_only_unlimited_args __dict__"
@register.inclusion_tag
(
get_template
(
'inclusion.html'
))
def
inclusion_only_unlimited_args_from_template
(
*
args
):
"""Expected inclusion_only_unlimited_args_from_template __doc__"""
return
{
"result"
:
"inclusion_only_unlimited_args_from_template - Expected result:
%
s"
%
(
', '
.
join
(
six
.
text_type
(
arg
)
for
arg
in
args
))}
inclusion_only_unlimited_args_from_template
.
anything
=
"Expected inclusion_only_unlimited_args_from_template __dict__"
@register.inclusion_tag
(
'test_incl_tag_current_app.html'
,
takes_context
=
True
)
def
inclusion_tag_current_app
(
context
):
"""Expected inclusion_tag_current_app __doc__"""
return
{}
inclusion_tag_current_app
.
anything
=
"Expected inclusion_tag_current_app __dict__"
@register.inclusion_tag
(
'test_incl_tag_use_l10n.html'
,
takes_context
=
True
)
def
inclusion_tag_use_l10n
(
context
):
"""Expected inclusion_tag_use_l10n __doc__"""
return
{}
inclusion_tag_use_l10n
.
anything
=
"Expected inclusion_tag_use_l10n __dict__"
@register.inclusion_tag
(
'inclusion.html'
)
def
inclusion_unlimited_args_kwargs
(
one
,
two
=
'hi'
,
*
args
,
**
kwargs
):
"""Expected inclusion_unlimited_args_kwargs __doc__"""
# Sort the dictionary by key to guarantee the order for testing.
sorted_kwarg
=
sorted
(
six
.
iteritems
(
kwargs
),
key
=
operator
.
itemgetter
(
0
))
return
{
"result"
:
"inclusion_unlimited_args_kwargs - Expected result:
%
s /
%
s"
%
(
', '
.
join
(
six
.
text_type
(
arg
)
for
arg
in
[
one
,
two
]
+
list
(
args
)),
', '
.
join
(
'
%
s=
%
s'
%
(
k
,
v
)
for
(
k
,
v
)
in
sorted_kwarg
)
)}
inclusion_unlimited_args_kwargs
.
anything
=
"Expected inclusion_unlimited_args_kwargs __dict__"
@register.inclusion_tag
(
'inclusion.html'
,
takes_context
=
True
)
def
inclusion_tag_without_context_parameter
(
arg
):
"""Expected inclusion_tag_without_context_parameter __doc__"""
return
{}
inclusion_tag_without_context_parameter
.
anything
=
"Expected inclusion_tag_without_context_parameter __dict__"
@register.assignment_tag
@register.assignment_tag
def
assignment_no_params
():
def
assignment_no_params
():
"""Expected assignment_no_params __doc__"""
"""Expected assignment_no_params __doc__"""
...
...
tests/template_tests/templatetags/inclusion.py
0 → 100644
Dosyayı görüntüle @
665e0aa6
import
operator
from
django.template
import
Library
from
django.template.loader
import
get_template
from
django.utils
import
six
register
=
Library
()
@register.inclusion_tag
(
'inclusion.html'
)
def
inclusion_no_params
():
"""Expected inclusion_no_params __doc__"""
return
{
"result"
:
"inclusion_no_params - Expected result"
}
inclusion_no_params
.
anything
=
"Expected inclusion_no_params __dict__"
@register.inclusion_tag
(
get_template
(
'inclusion.html'
))
def
inclusion_no_params_from_template
():
"""Expected inclusion_no_params_from_template __doc__"""
return
{
"result"
:
"inclusion_no_params_from_template - Expected result"
}
inclusion_no_params_from_template
.
anything
=
"Expected inclusion_no_params_from_template __dict__"
@register.inclusion_tag
(
'inclusion.html'
)
def
inclusion_one_param
(
arg
):
"""Expected inclusion_one_param __doc__"""
return
{
"result"
:
"inclusion_one_param - Expected result:
%
s"
%
arg
}
inclusion_one_param
.
anything
=
"Expected inclusion_one_param __dict__"
@register.inclusion_tag
(
get_template
(
'inclusion.html'
))
def
inclusion_one_param_from_template
(
arg
):
"""Expected inclusion_one_param_from_template __doc__"""
return
{
"result"
:
"inclusion_one_param_from_template - Expected result:
%
s"
%
arg
}
inclusion_one_param_from_template
.
anything
=
"Expected inclusion_one_param_from_template __dict__"
@register.inclusion_tag
(
'inclusion.html'
,
takes_context
=
False
)
def
inclusion_explicit_no_context
(
arg
):
"""Expected inclusion_explicit_no_context __doc__"""
return
{
"result"
:
"inclusion_explicit_no_context - Expected result:
%
s"
%
arg
}
inclusion_explicit_no_context
.
anything
=
"Expected inclusion_explicit_no_context __dict__"
@register.inclusion_tag
(
get_template
(
'inclusion.html'
),
takes_context
=
False
)
def
inclusion_explicit_no_context_from_template
(
arg
):
"""Expected inclusion_explicit_no_context_from_template __doc__"""
return
{
"result"
:
"inclusion_explicit_no_context_from_template - Expected result:
%
s"
%
arg
}
inclusion_explicit_no_context_from_template
.
anything
=
"Expected inclusion_explicit_no_context_from_template __dict__"
@register.inclusion_tag
(
'inclusion.html'
,
takes_context
=
True
)
def
inclusion_no_params_with_context
(
context
):
"""Expected inclusion_no_params_with_context __doc__"""
return
{
"result"
:
"inclusion_no_params_with_context - Expected result (context value:
%
s)"
%
context
[
'value'
]}
inclusion_no_params_with_context
.
anything
=
"Expected inclusion_no_params_with_context __dict__"
@register.inclusion_tag
(
get_template
(
'inclusion.html'
),
takes_context
=
True
)
def
inclusion_no_params_with_context_from_template
(
context
):
"""Expected inclusion_no_params_with_context_from_template __doc__"""
return
{
"result"
:
"inclusion_no_params_with_context_from_template - Expected result (context value:
%
s)"
%
context
[
'value'
]}
inclusion_no_params_with_context_from_template
.
anything
=
"Expected inclusion_no_params_with_context_from_template __dict__"
@register.inclusion_tag
(
'inclusion.html'
,
takes_context
=
True
)
def
inclusion_params_and_context
(
context
,
arg
):
"""Expected inclusion_params_and_context __doc__"""
return
{
"result"
:
"inclusion_params_and_context - Expected result (context value:
%
s):
%
s"
%
(
context
[
'value'
],
arg
)}
inclusion_params_and_context
.
anything
=
"Expected inclusion_params_and_context __dict__"
@register.inclusion_tag
(
get_template
(
'inclusion.html'
),
takes_context
=
True
)
def
inclusion_params_and_context_from_template
(
context
,
arg
):
"""Expected inclusion_params_and_context_from_template __doc__"""
return
{
"result"
:
"inclusion_params_and_context_from_template - Expected result (context value:
%
s):
%
s"
%
(
context
[
'value'
],
arg
)}
inclusion_params_and_context_from_template
.
anything
=
"Expected inclusion_params_and_context_from_template __dict__"
@register.inclusion_tag
(
'inclusion.html'
)
def
inclusion_two_params
(
one
,
two
):
"""Expected inclusion_two_params __doc__"""
return
{
"result"
:
"inclusion_two_params - Expected result:
%
s,
%
s"
%
(
one
,
two
)}
inclusion_two_params
.
anything
=
"Expected inclusion_two_params __dict__"
@register.inclusion_tag
(
get_template
(
'inclusion.html'
))
def
inclusion_two_params_from_template
(
one
,
two
):
"""Expected inclusion_two_params_from_template __doc__"""
return
{
"result"
:
"inclusion_two_params_from_template - Expected result:
%
s,
%
s"
%
(
one
,
two
)}
inclusion_two_params_from_template
.
anything
=
"Expected inclusion_two_params_from_template __dict__"
@register.inclusion_tag
(
'inclusion.html'
)
def
inclusion_one_default
(
one
,
two
=
'hi'
):
"""Expected inclusion_one_default __doc__"""
return
{
"result"
:
"inclusion_one_default - Expected result:
%
s,
%
s"
%
(
one
,
two
)}
inclusion_one_default
.
anything
=
"Expected inclusion_one_default __dict__"
@register.inclusion_tag
(
get_template
(
'inclusion.html'
))
def
inclusion_one_default_from_template
(
one
,
two
=
'hi'
):
"""Expected inclusion_one_default_from_template __doc__"""
return
{
"result"
:
"inclusion_one_default_from_template - Expected result:
%
s,
%
s"
%
(
one
,
two
)}
inclusion_one_default_from_template
.
anything
=
"Expected inclusion_one_default_from_template __dict__"
@register.inclusion_tag
(
'inclusion.html'
)
def
inclusion_unlimited_args
(
one
,
two
=
'hi'
,
*
args
):
"""Expected inclusion_unlimited_args __doc__"""
return
{
"result"
:
"inclusion_unlimited_args - Expected result:
%
s"
%
(
', '
.
join
(
six
.
text_type
(
arg
)
for
arg
in
[
one
,
two
]
+
list
(
args
)))}
inclusion_unlimited_args
.
anything
=
"Expected inclusion_unlimited_args __dict__"
@register.inclusion_tag
(
get_template
(
'inclusion.html'
))
def
inclusion_unlimited_args_from_template
(
one
,
two
=
'hi'
,
*
args
):
"""Expected inclusion_unlimited_args_from_template __doc__"""
return
{
"result"
:
"inclusion_unlimited_args_from_template - Expected result:
%
s"
%
(
', '
.
join
(
six
.
text_type
(
arg
)
for
arg
in
[
one
,
two
]
+
list
(
args
)))}
inclusion_unlimited_args_from_template
.
anything
=
"Expected inclusion_unlimited_args_from_template __dict__"
@register.inclusion_tag
(
'inclusion.html'
)
def
inclusion_only_unlimited_args
(
*
args
):
"""Expected inclusion_only_unlimited_args __doc__"""
return
{
"result"
:
"inclusion_only_unlimited_args - Expected result:
%
s"
%
(
', '
.
join
(
six
.
text_type
(
arg
)
for
arg
in
args
))}
inclusion_only_unlimited_args
.
anything
=
"Expected inclusion_only_unlimited_args __dict__"
@register.inclusion_tag
(
get_template
(
'inclusion.html'
))
def
inclusion_only_unlimited_args_from_template
(
*
args
):
"""Expected inclusion_only_unlimited_args_from_template __doc__"""
return
{
"result"
:
"inclusion_only_unlimited_args_from_template - Expected result:
%
s"
%
(
', '
.
join
(
six
.
text_type
(
arg
)
for
arg
in
args
))}
inclusion_only_unlimited_args_from_template
.
anything
=
"Expected inclusion_only_unlimited_args_from_template __dict__"
@register.inclusion_tag
(
'test_incl_tag_current_app.html'
,
takes_context
=
True
)
def
inclusion_tag_current_app
(
context
):
"""Expected inclusion_tag_current_app __doc__"""
return
{}
inclusion_tag_current_app
.
anything
=
"Expected inclusion_tag_current_app __dict__"
@register.inclusion_tag
(
'test_incl_tag_use_l10n.html'
,
takes_context
=
True
)
def
inclusion_tag_use_l10n
(
context
):
"""Expected inclusion_tag_use_l10n __doc__"""
return
{}
inclusion_tag_use_l10n
.
anything
=
"Expected inclusion_tag_use_l10n __dict__"
@register.inclusion_tag
(
'inclusion.html'
)
def
inclusion_unlimited_args_kwargs
(
one
,
two
=
'hi'
,
*
args
,
**
kwargs
):
"""Expected inclusion_unlimited_args_kwargs __doc__"""
# Sort the dictionary by key to guarantee the order for testing.
sorted_kwarg
=
sorted
(
six
.
iteritems
(
kwargs
),
key
=
operator
.
itemgetter
(
0
))
return
{
"result"
:
"inclusion_unlimited_args_kwargs - Expected result:
%
s /
%
s"
%
(
', '
.
join
(
six
.
text_type
(
arg
)
for
arg
in
[
one
,
two
]
+
list
(
args
)),
', '
.
join
(
'
%
s=
%
s'
%
(
k
,
v
)
for
(
k
,
v
)
in
sorted_kwarg
)
)}
inclusion_unlimited_args_kwargs
.
anything
=
"Expected inclusion_unlimited_args_kwargs __dict__"
@register.inclusion_tag
(
'inclusion.html'
,
takes_context
=
True
)
def
inclusion_tag_without_context_parameter
(
arg
):
"""Expected inclusion_tag_without_context_parameter __doc__"""
return
{}
inclusion_tag_without_context_parameter
.
anything
=
"Expected inclusion_tag_without_context_parameter __dict__"
tests/template_tests/test_custom.py
Dosyayı görüntüle @
665e0aa6
...
@@ -7,7 +7,7 @@ from django.test import ignore_warnings
...
@@ -7,7 +7,7 @@ from django.test import ignore_warnings
from
django.utils
import
six
from
django.utils
import
six
from
django.utils.deprecation
import
RemovedInDjango20Warning
from
django.utils.deprecation
import
RemovedInDjango20Warning
from
.templatetags
import
custom
from
.templatetags
import
custom
,
inclusion
class
CustomFilterTests
(
TestCase
):
class
CustomFilterTests
(
TestCase
):
...
@@ -112,139 +112,139 @@ class CustomTagTests(TestCase):
...
@@ -112,139 +112,139 @@ class CustomTagTests(TestCase):
def
test_inclusion_tags
(
self
):
def
test_inclusion_tags
(
self
):
c
=
template
.
Context
({
'value'
:
42
})
c
=
template
.
Context
({
'value'
:
42
})
t
=
template
.
Template
(
'{
%
load
custom
%
}{
%
inclusion_no_params
%
}'
)
t
=
template
.
Template
(
'{
%
load
inclusion
%
}{
%
inclusion_no_params
%
}'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_no_params - Expected result
\n
'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_no_params - Expected result
\n
'
)
t
=
template
.
Template
(
'{
%
load
custom
%
}{
%
inclusion_one_param 37
%
}'
)
t
=
template
.
Template
(
'{
%
load
inclusion
%
}{
%
inclusion_one_param 37
%
}'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_one_param - Expected result: 37
\n
'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_one_param - Expected result: 37
\n
'
)
t
=
template
.
Template
(
'{
%
load
custom
%
}{
%
inclusion_explicit_no_context 37
%
}'
)
t
=
template
.
Template
(
'{
%
load
inclusion
%
}{
%
inclusion_explicit_no_context 37
%
}'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_explicit_no_context - Expected result: 37
\n
'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_explicit_no_context - Expected result: 37
\n
'
)
t
=
template
.
Template
(
'{
%
load
custom
%
}{
%
inclusion_no_params_with_context
%
}'
)
t
=
template
.
Template
(
'{
%
load
inclusion
%
}{
%
inclusion_no_params_with_context
%
}'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_no_params_with_context - Expected result (context value: 42)
\n
'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_no_params_with_context - Expected result (context value: 42)
\n
'
)
t
=
template
.
Template
(
'{
%
load
custom
%
}{
%
inclusion_params_and_context 37
%
}'
)
t
=
template
.
Template
(
'{
%
load
inclusion
%
}{
%
inclusion_params_and_context 37
%
}'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_params_and_context - Expected result (context value: 42): 37
\n
'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_params_and_context - Expected result (context value: 42): 37
\n
'
)
t
=
template
.
Template
(
'{
%
load
custom
%
}{
%
inclusion_two_params 37 42
%
}'
)
t
=
template
.
Template
(
'{
%
load
inclusion
%
}{
%
inclusion_two_params 37 42
%
}'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_two_params - Expected result: 37, 42
\n
'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_two_params - Expected result: 37, 42
\n
'
)
t
=
template
.
Template
(
'{
%
load
custom
%
}{
%
inclusion_one_default 37
%
}'
)
t
=
template
.
Template
(
'{
%
load
inclusion
%
}{
%
inclusion_one_default 37
%
}'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_one_default - Expected result: 37, hi
\n
'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_one_default - Expected result: 37, hi
\n
'
)
t
=
template
.
Template
(
'{
%
load
custom
%
}{
%
inclusion_one_default 37 two="hello"
%
}'
)
t
=
template
.
Template
(
'{
%
load
inclusion
%
}{
%
inclusion_one_default 37 two="hello"
%
}'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_one_default - Expected result: 37, hello
\n
'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_one_default - Expected result: 37, hello
\n
'
)
t
=
template
.
Template
(
'{
%
load
custom
%
}{
%
inclusion_one_default one=99 two="hello"
%
}'
)
t
=
template
.
Template
(
'{
%
load
inclusion
%
}{
%
inclusion_one_default one=99 two="hello"
%
}'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_one_default - Expected result: 99, hello
\n
'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_one_default - Expected result: 99, hello
\n
'
)
six
.
assertRaisesRegex
(
self
,
template
.
TemplateSyntaxError
,
six
.
assertRaisesRegex
(
self
,
template
.
TemplateSyntaxError
,
"'inclusion_one_default' received unexpected keyword argument 'three'"
,
"'inclusion_one_default' received unexpected keyword argument 'three'"
,
template
.
Template
,
'{
%
load
custom
%
}{
%
inclusion_one_default 99 two="hello" three="foo"
%
}'
)
template
.
Template
,
'{
%
load
inclusion
%
}{
%
inclusion_one_default 99 two="hello" three="foo"
%
}'
)
t
=
template
.
Template
(
'{
%
load
custom
%
}{
%
inclusion_one_default 37 42
%
}'
)
t
=
template
.
Template
(
'{
%
load
inclusion
%
}{
%
inclusion_one_default 37 42
%
}'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_one_default - Expected result: 37, 42
\n
'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_one_default - Expected result: 37, 42
\n
'
)
t
=
template
.
Template
(
'{
%
load
custom
%
}{
%
inclusion_unlimited_args 37
%
}'
)
t
=
template
.
Template
(
'{
%
load
inclusion
%
}{
%
inclusion_unlimited_args 37
%
}'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_unlimited_args - Expected result: 37, hi
\n
'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_unlimited_args - Expected result: 37, hi
\n
'
)
t
=
template
.
Template
(
'{
%
load
custom
%
}{
%
inclusion_unlimited_args 37 42 56 89
%
}'
)
t
=
template
.
Template
(
'{
%
load
inclusion
%
}{
%
inclusion_unlimited_args 37 42 56 89
%
}'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_unlimited_args - Expected result: 37, 42, 56, 89
\n
'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_unlimited_args - Expected result: 37, 42, 56, 89
\n
'
)
t
=
template
.
Template
(
'{
%
load
custom
%
}{
%
inclusion_only_unlimited_args
%
}'
)
t
=
template
.
Template
(
'{
%
load
inclusion
%
}{
%
inclusion_only_unlimited_args
%
}'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_only_unlimited_args - Expected result:
\n
'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_only_unlimited_args - Expected result:
\n
'
)
t
=
template
.
Template
(
'{
%
load
custom
%
}{
%
inclusion_only_unlimited_args 37 42 56 89
%
}'
)
t
=
template
.
Template
(
'{
%
load
inclusion
%
}{
%
inclusion_only_unlimited_args 37 42 56 89
%
}'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_only_unlimited_args - Expected result: 37, 42, 56, 89
\n
'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_only_unlimited_args - Expected result: 37, 42, 56, 89
\n
'
)
six
.
assertRaisesRegex
(
self
,
template
.
TemplateSyntaxError
,
six
.
assertRaisesRegex
(
self
,
template
.
TemplateSyntaxError
,
"'inclusion_two_params' received too many positional arguments"
,
"'inclusion_two_params' received too many positional arguments"
,
template
.
Template
,
'{
%
load
custom
%
}{
%
inclusion_two_params 37 42 56
%
}'
)
template
.
Template
,
'{
%
load
inclusion
%
}{
%
inclusion_two_params 37 42 56
%
}'
)
six
.
assertRaisesRegex
(
self
,
template
.
TemplateSyntaxError
,
six
.
assertRaisesRegex
(
self
,
template
.
TemplateSyntaxError
,
"'inclusion_one_default' received too many positional arguments"
,
"'inclusion_one_default' received too many positional arguments"
,
template
.
Template
,
'{
%
load
custom
%
}{
%
inclusion_one_default 37 42 56
%
}'
)
template
.
Template
,
'{
%
load
inclusion
%
}{
%
inclusion_one_default 37 42 56
%
}'
)
six
.
assertRaisesRegex
(
self
,
template
.
TemplateSyntaxError
,
six
.
assertRaisesRegex
(
self
,
template
.
TemplateSyntaxError
,
"'inclusion_one_default' did not receive value
\
(s
\
) for the argument
\
(s
\
): 'one'"
,
"'inclusion_one_default' did not receive value
\
(s
\
) for the argument
\
(s
\
): 'one'"
,
template
.
Template
,
'{
%
load
custom
%
}{
%
inclusion_one_default
%
}'
)
template
.
Template
,
'{
%
load
inclusion
%
}{
%
inclusion_one_default
%
}'
)
six
.
assertRaisesRegex
(
self
,
template
.
TemplateSyntaxError
,
six
.
assertRaisesRegex
(
self
,
template
.
TemplateSyntaxError
,
"'inclusion_unlimited_args' did not receive value
\
(s
\
) for the argument
\
(s
\
): 'one'"
,
"'inclusion_unlimited_args' did not receive value
\
(s
\
) for the argument
\
(s
\
): 'one'"
,
template
.
Template
,
'{
%
load
custom
%
}{
%
inclusion_unlimited_args
%
}'
)
template
.
Template
,
'{
%
load
inclusion
%
}{
%
inclusion_unlimited_args
%
}'
)
t
=
template
.
Template
(
'{
%
load
custom
%
}{
%
inclusion_unlimited_args_kwargs 37 40|add:2 56 eggs="scrambled" four=1|add:3
%
}'
)
t
=
template
.
Template
(
'{
%
load
inclusion
%
}{
%
inclusion_unlimited_args_kwargs 37 40|add:2 56 eggs="scrambled" four=1|add:3
%
}'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_unlimited_args_kwargs - Expected result: 37, 42, 56 / eggs=scrambled, four=4
\n
'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_unlimited_args_kwargs - Expected result: 37, 42, 56 / eggs=scrambled, four=4
\n
'
)
six
.
assertRaisesRegex
(
self
,
template
.
TemplateSyntaxError
,
six
.
assertRaisesRegex
(
self
,
template
.
TemplateSyntaxError
,
"'inclusion_unlimited_args_kwargs' received some positional argument
\
(s
\
) after some keyword argument
\
(s
\
)"
,
"'inclusion_unlimited_args_kwargs' received some positional argument
\
(s
\
) after some keyword argument
\
(s
\
)"
,
template
.
Template
,
'{
%
load
custom
%
}{
%
inclusion_unlimited_args_kwargs 37 40|add:2 eggs="scrambled" 56 four=1|add:3
%
}'
)
template
.
Template
,
'{
%
load
inclusion
%
}{
%
inclusion_unlimited_args_kwargs 37 40|add:2 eggs="scrambled" 56 four=1|add:3
%
}'
)
six
.
assertRaisesRegex
(
self
,
template
.
TemplateSyntaxError
,
six
.
assertRaisesRegex
(
self
,
template
.
TemplateSyntaxError
,
"'inclusion_unlimited_args_kwargs' received multiple values for keyword argument 'eggs'"
,
"'inclusion_unlimited_args_kwargs' received multiple values for keyword argument 'eggs'"
,
template
.
Template
,
'{
%
load
custom
%
}{
%
inclusion_unlimited_args_kwargs 37 eggs="scrambled" eggs="scrambled"
%
}'
)
template
.
Template
,
'{
%
load
inclusion
%
}{
%
inclusion_unlimited_args_kwargs 37 eggs="scrambled" eggs="scrambled"
%
}'
)
def
test_include_tag_missing_context
(
self
):
def
test_include_tag_missing_context
(
self
):
# The 'context' parameter must be present when takes_context is True
# The 'context' parameter must be present when takes_context is True
six
.
assertRaisesRegex
(
self
,
template
.
TemplateSyntaxError
,
six
.
assertRaisesRegex
(
self
,
template
.
TemplateSyntaxError
,
"'inclusion_tag_without_context_parameter' is decorated with takes_context=True so it must have a first argument of 'context'"
,
"'inclusion_tag_without_context_parameter' is decorated with takes_context=True so it must have a first argument of 'context'"
,
template
.
Template
,
'{
%
load
custom
%
}{
%
inclusion_tag_without_context_parameter 123
%
}'
)
template
.
Template
,
'{
%
load
inclusion
%
}{
%
inclusion_tag_without_context_parameter 123
%
}'
)
def
test_inclusion_tags_from_template
(
self
):
def
test_inclusion_tags_from_template
(
self
):
c
=
template
.
Context
({
'value'
:
42
})
c
=
template
.
Context
({
'value'
:
42
})
t
=
template
.
Template
(
'{
%
load
custom
%
}{
%
inclusion_no_params_from_template
%
}'
)
t
=
template
.
Template
(
'{
%
load
inclusion
%
}{
%
inclusion_no_params_from_template
%
}'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_no_params_from_template - Expected result
\n
'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_no_params_from_template - Expected result
\n
'
)
t
=
template
.
Template
(
'{
%
load
custom
%
}{
%
inclusion_one_param_from_template 37
%
}'
)
t
=
template
.
Template
(
'{
%
load
inclusion
%
}{
%
inclusion_one_param_from_template 37
%
}'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_one_param_from_template - Expected result: 37
\n
'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_one_param_from_template - Expected result: 37
\n
'
)
t
=
template
.
Template
(
'{
%
load
custom
%
}{
%
inclusion_explicit_no_context_from_template 37
%
}'
)
t
=
template
.
Template
(
'{
%
load
inclusion
%
}{
%
inclusion_explicit_no_context_from_template 37
%
}'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_explicit_no_context_from_template - Expected result: 37
\n
'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_explicit_no_context_from_template - Expected result: 37
\n
'
)
t
=
template
.
Template
(
'{
%
load
custom
%
}{
%
inclusion_no_params_with_context_from_template
%
}'
)
t
=
template
.
Template
(
'{
%
load
inclusion
%
}{
%
inclusion_no_params_with_context_from_template
%
}'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_no_params_with_context_from_template - Expected result (context value: 42)
\n
'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_no_params_with_context_from_template - Expected result (context value: 42)
\n
'
)
t
=
template
.
Template
(
'{
%
load
custom
%
}{
%
inclusion_params_and_context_from_template 37
%
}'
)
t
=
template
.
Template
(
'{
%
load
inclusion
%
}{
%
inclusion_params_and_context_from_template 37
%
}'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_params_and_context_from_template - Expected result (context value: 42): 37
\n
'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_params_and_context_from_template - Expected result (context value: 42): 37
\n
'
)
t
=
template
.
Template
(
'{
%
load
custom
%
}{
%
inclusion_two_params_from_template 37 42
%
}'
)
t
=
template
.
Template
(
'{
%
load
inclusion
%
}{
%
inclusion_two_params_from_template 37 42
%
}'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_two_params_from_template - Expected result: 37, 42
\n
'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_two_params_from_template - Expected result: 37, 42
\n
'
)
t
=
template
.
Template
(
'{
%
load
custom
%
}{
%
inclusion_one_default_from_template 37
%
}'
)
t
=
template
.
Template
(
'{
%
load
inclusion
%
}{
%
inclusion_one_default_from_template 37
%
}'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_one_default_from_template - Expected result: 37, hi
\n
'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_one_default_from_template - Expected result: 37, hi
\n
'
)
t
=
template
.
Template
(
'{
%
load
custom
%
}{
%
inclusion_one_default_from_template 37 42
%
}'
)
t
=
template
.
Template
(
'{
%
load
inclusion
%
}{
%
inclusion_one_default_from_template 37 42
%
}'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_one_default_from_template - Expected result: 37, 42
\n
'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_one_default_from_template - Expected result: 37, 42
\n
'
)
t
=
template
.
Template
(
'{
%
load
custom
%
}{
%
inclusion_unlimited_args_from_template 37
%
}'
)
t
=
template
.
Template
(
'{
%
load
inclusion
%
}{
%
inclusion_unlimited_args_from_template 37
%
}'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_unlimited_args_from_template - Expected result: 37, hi
\n
'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_unlimited_args_from_template - Expected result: 37, hi
\n
'
)
t
=
template
.
Template
(
'{
%
load
custom
%
}{
%
inclusion_unlimited_args_from_template 37 42 56 89
%
}'
)
t
=
template
.
Template
(
'{
%
load
inclusion
%
}{
%
inclusion_unlimited_args_from_template 37 42 56 89
%
}'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_unlimited_args_from_template - Expected result: 37, 42, 56, 89
\n
'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_unlimited_args_from_template - Expected result: 37, 42, 56, 89
\n
'
)
t
=
template
.
Template
(
'{
%
load
custom
%
}{
%
inclusion_only_unlimited_args_from_template
%
}'
)
t
=
template
.
Template
(
'{
%
load
inclusion
%
}{
%
inclusion_only_unlimited_args_from_template
%
}'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_only_unlimited_args_from_template - Expected result:
\n
'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_only_unlimited_args_from_template - Expected result:
\n
'
)
t
=
template
.
Template
(
'{
%
load
custom
%
}{
%
inclusion_only_unlimited_args_from_template 37 42 56 89
%
}'
)
t
=
template
.
Template
(
'{
%
load
inclusion
%
}{
%
inclusion_only_unlimited_args_from_template 37 42 56 89
%
}'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_only_unlimited_args_from_template - Expected result: 37, 42, 56, 89
\n
'
)
self
.
assertEqual
(
t
.
render
(
c
),
'inclusion_only_unlimited_args_from_template - Expected result: 37, 42, 56, 89
\n
'
)
def
test_inclusion_tag_registration
(
self
):
def
test_inclusion_tag_registration
(
self
):
# Test that the decorators preserve the decorated function's docstring, name and attributes.
# Test that the decorators preserve the decorated function's docstring, name and attributes.
self
.
verify_tag
(
custom
.
inclusion_no_params
,
'inclusion_no_params'
)
self
.
verify_tag
(
inclusion
.
inclusion_no_params
,
'inclusion_no_params'
)
self
.
verify_tag
(
custom
.
inclusion_one_param
,
'inclusion_one_param'
)
self
.
verify_tag
(
inclusion
.
inclusion_one_param
,
'inclusion_one_param'
)
self
.
verify_tag
(
custom
.
inclusion_explicit_no_context
,
'inclusion_explicit_no_context'
)
self
.
verify_tag
(
inclusion
.
inclusion_explicit_no_context
,
'inclusion_explicit_no_context'
)
self
.
verify_tag
(
custom
.
inclusion_no_params_with_context
,
'inclusion_no_params_with_context'
)
self
.
verify_tag
(
inclusion
.
inclusion_no_params_with_context
,
'inclusion_no_params_with_context'
)
self
.
verify_tag
(
custom
.
inclusion_params_and_context
,
'inclusion_params_and_context'
)
self
.
verify_tag
(
inclusion
.
inclusion_params_and_context
,
'inclusion_params_and_context'
)
self
.
verify_tag
(
custom
.
inclusion_two_params
,
'inclusion_two_params'
)
self
.
verify_tag
(
inclusion
.
inclusion_two_params
,
'inclusion_two_params'
)
self
.
verify_tag
(
custom
.
inclusion_one_default
,
'inclusion_one_default'
)
self
.
verify_tag
(
inclusion
.
inclusion_one_default
,
'inclusion_one_default'
)
self
.
verify_tag
(
custom
.
inclusion_unlimited_args
,
'inclusion_unlimited_args'
)
self
.
verify_tag
(
inclusion
.
inclusion_unlimited_args
,
'inclusion_unlimited_args'
)
self
.
verify_tag
(
custom
.
inclusion_only_unlimited_args
,
'inclusion_only_unlimited_args'
)
self
.
verify_tag
(
inclusion
.
inclusion_only_unlimited_args
,
'inclusion_only_unlimited_args'
)
self
.
verify_tag
(
custom
.
inclusion_tag_without_context_parameter
,
'inclusion_tag_without_context_parameter'
)
self
.
verify_tag
(
inclusion
.
inclusion_tag_without_context_parameter
,
'inclusion_tag_without_context_parameter'
)
self
.
verify_tag
(
custom
.
inclusion_tag_use_l10n
,
'inclusion_tag_use_l10n'
)
self
.
verify_tag
(
inclusion
.
inclusion_tag_use_l10n
,
'inclusion_tag_use_l10n'
)
self
.
verify_tag
(
custom
.
inclusion_tag_current_app
,
'inclusion_tag_current_app'
)
self
.
verify_tag
(
inclusion
.
inclusion_tag_current_app
,
'inclusion_tag_current_app'
)
self
.
verify_tag
(
custom
.
inclusion_unlimited_args_kwargs
,
'inclusion_unlimited_args_kwargs'
)
self
.
verify_tag
(
inclusion
.
inclusion_unlimited_args_kwargs
,
'inclusion_unlimited_args_kwargs'
)
@ignore_warnings
(
category
=
RemovedInDjango20Warning
)
@ignore_warnings
(
category
=
RemovedInDjango20Warning
)
def
test_15070_current_app
(
self
):
def
test_15070_current_app
(
self
):
...
@@ -253,7 +253,7 @@ class CustomTagTests(TestCase):
...
@@ -253,7 +253,7 @@ class CustomTagTests(TestCase):
Context of the included/rendered template as well.
Context of the included/rendered template as well.
"""
"""
c
=
template
.
Context
({})
c
=
template
.
Context
({})
t
=
template
.
Template
(
'{
%
load
custom
%
}{
%
inclusion_tag_current_app
%
}'
)
t
=
template
.
Template
(
'{
%
load
inclusion
%
}{
%
inclusion_tag_current_app
%
}'
)
self
.
assertEqual
(
t
.
render
(
c
)
.
strip
(),
'None'
)
self
.
assertEqual
(
t
.
render
(
c
)
.
strip
(),
'None'
)
# That part produces the deprecation warning
# That part produces the deprecation warning
...
@@ -266,7 +266,7 @@ class CustomTagTests(TestCase):
...
@@ -266,7 +266,7 @@ class CustomTagTests(TestCase):
Context of the included/rendered template as well.
Context of the included/rendered template as well.
"""
"""
c
=
template
.
Context
({})
c
=
template
.
Context
({})
t
=
template
.
Template
(
'{
%
load
custom
%
}{
%
inclusion_tag_use_l10n
%
}'
)
t
=
template
.
Template
(
'{
%
load
inclusion
%
}{
%
inclusion_tag_use_l10n
%
}'
)
self
.
assertEqual
(
t
.
render
(
c
)
.
strip
(),
'None'
)
self
.
assertEqual
(
t
.
render
(
c
)
.
strip
(),
'None'
)
c
.
use_l10n
=
True
c
.
use_l10n
=
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