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
76ae1e9a
Kaydet (Commit)
76ae1e9a
authored
Mar 25, 2018
tarafından
Hasan Ramezani
Kaydeden (comit)
Tim Graham
Mar 26, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Increased test coverage for {% get_admin_log %} and {% static %}.
üst
3990d740
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
15 deletions
+41
-15
tests.py
tests/admin_changelist/tests.py
+28
-15
test_static.py
tests/template_tests/syntax_tests/test_static.py
+13
-0
No files found.
tests/admin_changelist/tests.py
Dosyayı görüntüle @
76ae1e9a
...
...
@@ -12,7 +12,7 @@ from django.db.models import F
from
django.db.models.fields
import
Field
,
IntegerField
from
django.db.models.functions
import
Upper
from
django.db.models.lookups
import
Contains
,
Exact
from
django.template
import
Context
,
Template
from
django.template
import
Context
,
Template
,
TemplateSyntaxError
from
django.test
import
TestCase
,
override_settings
from
django.test.client
import
RequestFactory
from
django.urls
import
reverse
...
...
@@ -893,31 +893,24 @@ class ChangeListTests(TestCase):
self
.
assertNotIn
(
'Add '
,
response
.
rendered_content
)
class
AdminLogNodeTestCase
(
TestCase
):
class
GetAdminLogTests
(
TestCase
):
def
test_
get_admin_log_templatetag_custom_user
(
self
):
def
test_
custom_user_pk_not_named_id
(
self
):
"""
Regression test for ticket #20088: admin log depends on User model
having id field as primary key.
The old implementation raised an AttributeError when trying to use
the id field.
{
%
get_admin_log
%
} works if the user model's primary key isn't named
'id'.
"""
context
=
Context
({
'user'
:
CustomIdUser
()})
template_string
=
'{
%
load log
%
}{
%
get_admin_log 10 as admin_log for_user user
%
}'
template
=
Template
(
template_string
)
template
=
Template
(
'{
%
load log
%
}{
%
get_admin_log 10 as admin_log for_user user
%
}'
)
# This template tag just logs.
self
.
assertEqual
(
template
.
render
(
context
),
''
)
def
test_get_admin_log_templatetag_no_user
(
self
):
"""
The {
%
get_admin_log
%
} tag should work without specifying a user.
"""
def
test_no_user
(
self
):
"""{
%
get_admin_log
%
} works without specifying a user."""
user
=
User
(
username
=
'jondoe'
,
password
=
'secret'
,
email
=
'super@example.com'
)
user
.
save
()
ct
=
ContentType
.
objects
.
get_for_model
(
User
)
LogEntry
.
objects
.
log_action
(
user
.
pk
,
ct
.
pk
,
user
.
pk
,
repr
(
user
),
1
)
t
=
Template
(
'{
%
load log
%
}'
'{
%
get_admin_log 100 as admin_log
%
}'
...
...
@@ -927,6 +920,26 @@ class AdminLogNodeTestCase(TestCase):
)
self
.
assertEqual
(
t
.
render
(
Context
({})),
'Added "<User: jondoe>".'
)
def
test_missing_args
(
self
):
msg
=
"'get_admin_log' statements require two arguments"
with
self
.
assertRaisesMessage
(
TemplateSyntaxError
,
msg
):
Template
(
'{
%
load log
%
}{
%
get_admin_log 10 as
%
}'
)
def
test_non_integer_limit
(
self
):
msg
=
"First argument to 'get_admin_log' must be an integer"
with
self
.
assertRaisesMessage
(
TemplateSyntaxError
,
msg
):
Template
(
'{
%
load log
%
}{
%
get_admin_log "10" as admin_log for_user user
%
}'
)
def
test_without_as
(
self
):
msg
=
"Second argument to 'get_admin_log' must be 'as'"
with
self
.
assertRaisesMessage
(
TemplateSyntaxError
,
msg
):
Template
(
'{
%
load log
%
}{
%
get_admin_log 10 ad admin_log for_user user
%
}'
)
def
test_without_for_user
(
self
):
msg
=
"Fourth argument to 'get_admin_log' must be 'for_user'"
with
self
.
assertRaisesMessage
(
TemplateSyntaxError
,
msg
):
Template
(
'{
%
load log
%
}{
%
get_admin_log 10 as admin_log foruser user
%
}'
)
@override_settings
(
ROOT_URLCONF
=
'admin_changelist.urls'
)
class
SeleniumTests
(
AdminSeleniumTestCase
):
...
...
tests/template_tests/syntax_tests/test_static.py
Dosyayı görüntüle @
76ae1e9a
from
urllib.parse
import
urljoin
from
django.conf
import
settings
from
django.template
import
TemplateSyntaxError
from
django.test
import
SimpleTestCase
,
override_settings
from
..utils
import
setup
...
...
@@ -32,6 +33,12 @@ class StaticTagTests(SimpleTestCase):
output
=
self
.
engine
.
render_to_string
(
'static-prefixtag04'
)
self
.
assertEqual
(
output
,
settings
.
MEDIA_URL
)
@setup
({
't'
:
'{
%
load static
%
}{
%
get_media_prefix ad media_prefix
%
}{{ media_prefix }}'
})
def
test_static_prefixtag_without_as
(
self
):
msg
=
"First argument in 'get_media_prefix' must be 'as'"
with
self
.
assertRaisesMessage
(
TemplateSyntaxError
,
msg
):
self
.
engine
.
render_to_string
(
't'
)
@setup
({
'static-statictag01'
:
'{
%
load static
%
}{
%
static "admin/base.css"
%
}'
})
def
test_static_statictag01
(
self
):
output
=
self
.
engine
.
render_to_string
(
'static-statictag01'
)
...
...
@@ -56,3 +63,9 @@ class StaticTagTests(SimpleTestCase):
def
test_static_quotes_urls
(
self
):
output
=
self
.
engine
.
render_to_string
(
'static-statictag05'
)
self
.
assertEqual
(
output
,
urljoin
(
settings
.
STATIC_URL
,
'/static/special
%3
Fchars
%26
quoted.html'
))
@setup
({
't'
:
'{
%
load static
%
}{
%
static
%
}'
})
def
test_static_statictag_without_path
(
self
):
msg
=
"'static' takes at least one argument (path to file)"
with
self
.
assertRaisesMessage
(
TemplateSyntaxError
,
msg
):
self
.
engine
.
render_to_string
(
't'
)
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