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
bf1bd0fb
Kaydet (Commit)
bf1bd0fb
authored
Kas 22, 2014
tarafından
Aymeric Augustin
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Moved tests for render shortcuts to their own app.
üst
b38637d5
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
112 additions
and
106 deletions
+112
-106
__init__.py
tests/shortcuts/__init__.py
+0
-0
render_dirs_test.html
tests/shortcuts/other_templates/render_dirs_test.html
+0
-0
render_test.html
tests/shortcuts/templates/shortcuts/render_test.html
+0
-0
tests.py
tests/shortcuts/tests.py
+13
-12
urls.py
tests/shortcuts/urls.py
+17
-0
views.py
tests/shortcuts/views.py
+81
-0
generic_urls.py
tests/view_tests/generic_urls.py
+0
-14
views.py
tests/view_tests/views.py
+1
-80
No files found.
tests/shortcuts/__init__.py
0 → 100644
Dosyayı görüntüle @
bf1bd0fb
tests/
view_tes
ts/other_templates/render_dirs_test.html
→
tests/
shortcu
ts/other_templates/render_dirs_test.html
Dosyayı görüntüle @
bf1bd0fb
File moved
tests/
view_tests/templates/debug
/render_test.html
→
tests/
shortcuts/templates/shortcuts
/render_test.html
Dosyayı görüntüle @
bf1bd0fb
File moved
tests/
view_tests/tests/test_shortcu
ts.py
→
tests/
shortcuts/tes
ts.py
Dosyayı görüntüle @
bf1bd0fb
...
...
@@ -4,67 +4,68 @@ from django.test import TestCase, override_settings
@override_settings
(
TEMPLATE_CONTEXT_PROCESSORS
=
(
'django.core.context_processors.static'
,),
STATIC_URL
=
'/path/to/static/media/'
,
ROOT_URLCONF
=
'
view_tests.generic_
urls'
,
ROOT_URLCONF
=
'
shortcuts.
urls'
,
)
class
ShortcutTests
(
TestCase
):
def
test_render_to_response
(
self
):
response
=
self
.
client
.
get
(
'/
shortcuts/
render_to_response/'
)
response
=
self
.
client
.
get
(
'/render_to_response/'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
content
,
b
'FOO.BAR..
\n
'
)
self
.
assertEqual
(
response
[
'Content-Type'
],
'text/html; charset=utf-8'
)
def
test_render_to_response_with_request_context
(
self
):
response
=
self
.
client
.
get
(
'/
shortcuts/
render_to_response/request_context/'
)
response
=
self
.
client
.
get
(
'/render_to_response/request_context/'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
content
,
b
'FOO.BAR../path/to/static/media/
\n
'
)
self
.
assertEqual
(
response
[
'Content-Type'
],
'text/html; charset=utf-8'
)
def
test_render_to_response_with_content_type
(
self
):
response
=
self
.
client
.
get
(
'/
shortcuts/
render_to_response/content_type/'
)
response
=
self
.
client
.
get
(
'/render_to_response/content_type/'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
content
,
b
'FOO.BAR..
\n
'
)
self
.
assertEqual
(
response
[
'Content-Type'
],
'application/x-rendertest'
)
def
test_render_to_response_with_dirs
(
self
):
response
=
self
.
client
.
get
(
'/
shortcuts/
render_to_response/dirs/'
)
response
=
self
.
client
.
get
(
'/render_to_response/dirs/'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
content
,
b
'spam eggs
\n
'
)
self
.
assertEqual
(
response
[
'Content-Type'
],
'text/html; charset=utf-8'
)
def
test_render
(
self
):
response
=
self
.
client
.
get
(
'/
shortcuts/
render/'
)
response
=
self
.
client
.
get
(
'/render/'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
content
,
b
'FOO.BAR../path/to/static/media/
\n
'
)
self
.
assertEqual
(
response
[
'Content-Type'
],
'text/html; charset=utf-8'
)
self
.
assertEqual
(
response
.
context
.
current_app
,
None
)
def
test_render_with_base_context
(
self
):
response
=
self
.
client
.
get
(
'/
shortcuts/
render/base_context/'
)
response
=
self
.
client
.
get
(
'/render/base_context/'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
content
,
b
'FOO.BAR..
\n
'
)
self
.
assertEqual
(
response
[
'Content-Type'
],
'text/html; charset=utf-8'
)
def
test_render_with_content_type
(
self
):
response
=
self
.
client
.
get
(
'/
shortcuts/
render/content_type/'
)
response
=
self
.
client
.
get
(
'/render/content_type/'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
content
,
b
'FOO.BAR../path/to/static/media/
\n
'
)
self
.
assertEqual
(
response
[
'Content-Type'
],
'application/x-rendertest'
)
def
test_render_with_status
(
self
):
response
=
self
.
client
.
get
(
'/
shortcuts/
render/status/'
)
response
=
self
.
client
.
get
(
'/render/status/'
)
self
.
assertEqual
(
response
.
status_code
,
403
)
self
.
assertEqual
(
response
.
content
,
b
'FOO.BAR../path/to/static/media/
\n
'
)
def
test_render_with_current_app
(
self
):
response
=
self
.
client
.
get
(
'/
shortcuts/
render/current_app/'
)
response
=
self
.
client
.
get
(
'/render/current_app/'
)
self
.
assertEqual
(
response
.
context
.
current_app
,
"foobar_app"
)
def
test_render_with_dirs
(
self
):
response
=
self
.
client
.
get
(
'/
shortcuts/
render/dirs/'
)
response
=
self
.
client
.
get
(
'/render/dirs/'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
content
,
b
'spam eggs
\n
'
)
self
.
assertEqual
(
response
[
'Content-Type'
],
'text/html; charset=utf-8'
)
def
test_render_with_current_app_conflict
(
self
):
self
.
assertRaises
(
ValueError
,
self
.
client
.
get
,
'/shortcuts/render/current_app_conflict/'
)
with
self
.
assertRaises
(
ValueError
):
self
.
client
.
get
(
'/render/current_app_conflict/'
)
tests/shortcuts/urls.py
0 → 100644
Dosyayı görüntüle @
bf1bd0fb
from
django.conf.urls
import
url
from
.
import
views
urlpatterns
=
[
url
(
r'^render_to_response/$'
,
views
.
render_to_response_view
),
url
(
r'^render_to_response/request_context/$'
,
views
.
render_to_response_view_with_request_context
),
url
(
r'^render_to_response/content_type/$'
,
views
.
render_to_response_view_with_content_type
),
url
(
r'^render_to_response/dirs/$'
,
views
.
render_to_response_view_with_dirs
),
url
(
r'^render/$'
,
views
.
render_view
),
url
(
r'^render/base_context/$'
,
views
.
render_view_with_base_context
),
url
(
r'^render/content_type/$'
,
views
.
render_view_with_content_type
),
url
(
r'^render/dirs/$'
,
views
.
render_with_dirs
),
url
(
r'^render/status/$'
,
views
.
render_view_with_status
),
url
(
r'^render/current_app/$'
,
views
.
render_view_with_current_app
),
url
(
r'^render/current_app_conflict/$'
,
views
.
render_view_with_current_app_conflict
),
]
tests/shortcuts/views.py
0 → 100644
Dosyayı görüntüle @
bf1bd0fb
import
os.path
from
django.shortcuts
import
render_to_response
,
render
from
django.template
import
Context
,
RequestContext
from
django.utils._os
import
upath
dirs
=
(
os
.
path
.
join
(
os
.
path
.
dirname
(
upath
(
__file__
)),
'other_templates'
),)
def
render_to_response_view
(
request
):
return
render_to_response
(
'shortcuts/render_test.html'
,
{
'foo'
:
'FOO'
,
'bar'
:
'BAR'
,
})
def
render_to_response_view_with_request_context
(
request
):
return
render_to_response
(
'shortcuts/render_test.html'
,
{
'foo'
:
'FOO'
,
'bar'
:
'BAR'
,
},
context_instance
=
RequestContext
(
request
))
def
render_to_response_view_with_content_type
(
request
):
return
render_to_response
(
'shortcuts/render_test.html'
,
{
'foo'
:
'FOO'
,
'bar'
:
'BAR'
,
},
content_type
=
'application/x-rendertest'
)
def
render_to_response_view_with_dirs
(
request
):
return
render_to_response
(
'render_dirs_test.html'
,
dirs
=
dirs
)
def
render_view
(
request
):
return
render
(
request
,
'shortcuts/render_test.html'
,
{
'foo'
:
'FOO'
,
'bar'
:
'BAR'
,
})
def
render_view_with_base_context
(
request
):
return
render
(
request
,
'shortcuts/render_test.html'
,
{
'foo'
:
'FOO'
,
'bar'
:
'BAR'
,
},
context_instance
=
Context
())
def
render_view_with_content_type
(
request
):
return
render
(
request
,
'shortcuts/render_test.html'
,
{
'foo'
:
'FOO'
,
'bar'
:
'BAR'
,
},
content_type
=
'application/x-rendertest'
)
def
render_with_dirs
(
request
):
return
render
(
request
,
'render_dirs_test.html'
,
dirs
=
dirs
)
def
render_view_with_status
(
request
):
return
render
(
request
,
'shortcuts/render_test.html'
,
{
'foo'
:
'FOO'
,
'bar'
:
'BAR'
,
},
status
=
403
)
def
render_view_with_current_app
(
request
):
return
render
(
request
,
'shortcuts/render_test.html'
,
{
'foo'
:
'FOO'
,
'bar'
:
'BAR'
,
},
current_app
=
"foobar_app"
)
def
render_view_with_current_app_conflict
(
request
):
# This should fail because we don't passing both a current_app and
# context_instance:
return
render
(
request
,
'shortcuts/render_test.html'
,
{
'foo'
:
'FOO'
,
'bar'
:
'BAR'
,
},
current_app
=
"foobar_app"
,
context_instance
=
RequestContext
(
request
))
tests/view_tests/generic_urls.py
Dosyayı görüntüle @
bf1bd0fb
...
...
@@ -44,20 +44,6 @@ urlpatterns += [
url
=
'/中文/target/'
,
permanent
=
True
)),
]
urlpatterns
+=
[
url
(
r'^shortcuts/render_to_response/$'
,
views
.
render_to_response_view
),
url
(
r'^shortcuts/render_to_response/request_context/$'
,
views
.
render_to_response_view_with_request_context
),
url
(
r'^shortcuts/render_to_response/content_type/$'
,
views
.
render_to_response_view_with_content_type
),
url
(
r'^shortcuts/render_to_response/dirs/$'
,
views
.
render_to_response_view_with_dirs
),
url
(
r'^shortcuts/render/$'
,
views
.
render_view
),
url
(
r'^shortcuts/render/base_context/$'
,
views
.
render_view_with_base_context
),
url
(
r'^shortcuts/render/content_type/$'
,
views
.
render_view_with_content_type
),
url
(
r'^shortcuts/render/status/$'
,
views
.
render_view_with_status
),
url
(
r'^shortcuts/render/current_app/$'
,
views
.
render_view_with_current_app
),
url
(
r'^shortcuts/render/dirs/$'
,
views
.
render_with_dirs
),
url
(
r'^shortcuts/render/current_app_conflict/$'
,
views
.
render_view_with_current_app_conflict
),
]
# json response
urlpatterns
+=
[
url
(
r'^json/response/$'
,
views
.
json_response_view
),
...
...
tests/view_tests/views.py
Dosyayı görüntüle @
bf1bd0fb
...
...
@@ -2,26 +2,22 @@ from __future__ import unicode_literals
import
datetime
import
decimal
import
os
import
sys
from
django.core.exceptions
import
PermissionDenied
,
SuspiciousOperation
from
django.core.urlresolvers
import
get_resolver
from
django.http
import
HttpResponse
,
HttpResponseRedirect
,
JsonResponse
,
Http404
from
django.shortcuts
import
render_to_response
,
render
from
django.template
import
Context
,
RequestContext
,
TemplateDoesNotExist
from
django.template
import
TemplateDoesNotExist
from
django.views.debug
import
technical_500_response
,
SafeExceptionReporterFilter
from
django.views.decorators.debug
import
(
sensitive_post_parameters
,
sensitive_variables
)
from
django.utils._os
import
upath
from
django.utils.log
import
getLogger
from
django.views.generic
import
View
from
.
import
BrokenException
,
except_args
dirs
=
(
os
.
path
.
join
(
os
.
path
.
dirname
(
upath
(
__file__
)),
'other_templates'
),)
def
index_page
(
request
):
"""Dummy index page"""
...
...
@@ -90,81 +86,6 @@ def template_exception(request, n):
def
jsi18n
(
request
):
return
render_to_response
(
'jsi18n.html'
)
# Some views to exercise the shortcuts
def
render_to_response_view
(
request
):
return
render_to_response
(
'debug/render_test.html'
,
{
'foo'
:
'FOO'
,
'bar'
:
'BAR'
,
})
def
render_to_response_view_with_request_context
(
request
):
return
render_to_response
(
'debug/render_test.html'
,
{
'foo'
:
'FOO'
,
'bar'
:
'BAR'
,
},
context_instance
=
RequestContext
(
request
))
def
render_to_response_view_with_content_type
(
request
):
return
render_to_response
(
'debug/render_test.html'
,
{
'foo'
:
'FOO'
,
'bar'
:
'BAR'
,
},
content_type
=
'application/x-rendertest'
)
def
render_to_response_view_with_dirs
(
request
):
return
render_to_response
(
'render_dirs_test.html'
,
dirs
=
dirs
)
def
render_view
(
request
):
return
render
(
request
,
'debug/render_test.html'
,
{
'foo'
:
'FOO'
,
'bar'
:
'BAR'
,
})
def
render_view_with_base_context
(
request
):
return
render
(
request
,
'debug/render_test.html'
,
{
'foo'
:
'FOO'
,
'bar'
:
'BAR'
,
},
context_instance
=
Context
())
def
render_view_with_content_type
(
request
):
return
render
(
request
,
'debug/render_test.html'
,
{
'foo'
:
'FOO'
,
'bar'
:
'BAR'
,
},
content_type
=
'application/x-rendertest'
)
def
render_view_with_status
(
request
):
return
render
(
request
,
'debug/render_test.html'
,
{
'foo'
:
'FOO'
,
'bar'
:
'BAR'
,
},
status
=
403
)
def
render_view_with_current_app
(
request
):
return
render
(
request
,
'debug/render_test.html'
,
{
'foo'
:
'FOO'
,
'bar'
:
'BAR'
,
},
current_app
=
"foobar_app"
)
def
render_view_with_current_app_conflict
(
request
):
# This should fail because we don't passing both a current_app and
# context_instance:
return
render
(
request
,
'debug/render_test.html'
,
{
'foo'
:
'FOO'
,
'bar'
:
'BAR'
,
},
current_app
=
"foobar_app"
,
context_instance
=
RequestContext
(
request
))
def
render_with_dirs
(
request
):
return
render
(
request
,
'render_dirs_test.html'
,
dirs
=
dirs
)
def
raises_template_does_not_exist
(
request
,
path
=
'i_dont_exist.html'
):
# We need to inspect the HTML generated by the fancy 500 debug view but
...
...
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