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
3096f4b0
Kaydet (Commit)
3096f4b0
authored
Ara 29, 2015
tarafından
Simon Charette
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Imported required models directly in auth management tests.
üst
7bb373e3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
24 deletions
+24
-24
test_management.py
tests/auth_tests/test_management.py
+24
-24
No files found.
tests/auth_tests/test_management.py
Dosyayı görüntüle @
3096f4b0
...
...
@@ -5,13 +5,13 @@ import sys
from
datetime
import
date
from
django.apps
import
apps
from
django.contrib.auth
import
management
,
models
from
django.contrib.auth
import
management
from
django.contrib.auth.checks
import
check_user_model
from
django.contrib.auth.management
import
create_permissions
from
django.contrib.auth.management.commands
import
(
changepassword
,
createsuperuser
,
)
from
django.contrib.auth.models
import
Group
,
User
from
django.contrib.auth.models
import
Group
,
Permission
,
User
from
django.contrib.auth.tests.custom_user
import
CustomUser
from
django.contrib.contenttypes.models
import
ContentType
from
django.core
import
checks
,
exceptions
...
...
@@ -97,7 +97,7 @@ class GetDefaultUsernameTestCase(TestCase):
self
.
assertEqual
(
management
.
get_default_username
(),
'joe'
)
def
test_existing
(
self
):
models
.
User
.
objects
.
create
(
username
=
'joe'
)
User
.
objects
.
create
(
username
=
'joe'
)
management
.
get_system_username
=
lambda
:
'joe'
self
.
assertEqual
(
management
.
get_default_username
(),
''
)
self
.
assertEqual
(
...
...
@@ -115,7 +115,7 @@ class GetDefaultUsernameTestCase(TestCase):
class
ChangepasswordManagementCommandTestCase
(
TestCase
):
def
setUp
(
self
):
self
.
user
=
models
.
User
.
objects
.
create_user
(
username
=
'joe'
,
password
=
'qwerty'
)
self
.
user
=
User
.
objects
.
create_user
(
username
=
'joe'
,
password
=
'qwerty'
)
self
.
stdout
=
six
.
StringIO
()
self
.
stderr
=
six
.
StringIO
()
...
...
@@ -136,7 +136,7 @@ class ChangepasswordManagementCommandTestCase(TestCase):
command_output
,
"Changing password for user 'joe'
\n
Password changed successfully for user 'joe'"
)
self
.
assertTrue
(
models
.
User
.
objects
.
get
(
username
=
"joe"
)
.
check_password
(
"not qwerty"
))
self
.
assertTrue
(
User
.
objects
.
get
(
username
=
"joe"
)
.
check_password
(
"not qwerty"
))
def
test_that_max_tries_exits_1
(
self
):
"""
...
...
@@ -168,7 +168,7 @@ class ChangepasswordManagementCommandTestCase(TestCase):
non-ASCII characters from the User object representation.
"""
# 'Julia' with accented 'u':
models
.
User
.
objects
.
create_user
(
username
=
'J
\xfa
lia'
,
password
=
'qwerty'
)
User
.
objects
.
create_user
(
username
=
'J
\xfa
lia'
,
password
=
'qwerty'
)
command
=
changepassword
.
Command
()
command
.
_get_pass
=
lambda
*
args
:
'not qwerty'
...
...
@@ -639,14 +639,14 @@ class CustomUserModelValidationTestCase(SimpleTestCase):
class
PermissionTestCase
(
TestCase
):
def
setUp
(
self
):
self
.
_original_permissions
=
models
.
Permission
.
_meta
.
permissions
[:]
self
.
_original_default_permissions
=
models
.
Permission
.
_meta
.
default_permissions
self
.
_original_verbose_name
=
models
.
Permission
.
_meta
.
verbose_name
self
.
_original_permissions
=
Permission
.
_meta
.
permissions
[:]
self
.
_original_default_permissions
=
Permission
.
_meta
.
default_permissions
self
.
_original_verbose_name
=
Permission
.
_meta
.
verbose_name
def
tearDown
(
self
):
models
.
Permission
.
_meta
.
permissions
=
self
.
_original_permissions
models
.
Permission
.
_meta
.
default_permissions
=
self
.
_original_default_permissions
models
.
Permission
.
_meta
.
verbose_name
=
self
.
_original_verbose_name
Permission
.
_meta
.
permissions
=
self
.
_original_permissions
Permission
.
_meta
.
default_permissions
=
self
.
_original_default_permissions
Permission
.
_meta
.
verbose_name
=
self
.
_original_verbose_name
ContentType
.
objects
.
clear_cache
()
def
test_duplicated_permissions
(
self
):
...
...
@@ -657,7 +657,7 @@ class PermissionTestCase(TestCase):
auth_app_config
=
apps
.
get_app_config
(
'auth'
)
# check duplicated default permission
models
.
Permission
.
_meta
.
permissions
=
[
Permission
.
_meta
.
permissions
=
[
(
'change_permission'
,
'Can edit permission (duplicate)'
)]
six
.
assertRaisesRegex
(
self
,
CommandError
,
"The permission codename 'change_permission' clashes with a "
...
...
@@ -665,7 +665,7 @@ class PermissionTestCase(TestCase):
create_permissions
,
auth_app_config
,
verbosity
=
0
)
# check duplicated custom permissions
models
.
Permission
.
_meta
.
permissions
=
[
Permission
.
_meta
.
permissions
=
[
(
'my_custom_permission'
,
'Some permission'
),
(
'other_one'
,
'Some other permission'
),
(
'my_custom_permission'
,
'Some permission with duplicate permission code'
),
...
...
@@ -676,7 +676,7 @@ class PermissionTestCase(TestCase):
create_permissions
,
auth_app_config
,
verbosity
=
0
)
# should not raise anything
models
.
Permission
.
_meta
.
permissions
=
[
Permission
.
_meta
.
permissions
=
[
(
'my_custom_permission'
,
'Some permission'
),
(
'other_one'
,
'Some other permission'
),
]
...
...
@@ -686,22 +686,22 @@ class PermissionTestCase(TestCase):
auth_app_config
=
apps
.
get_app_config
(
'auth'
)
permission_content_type
=
ContentType
.
objects
.
get_by_natural_key
(
'auth'
,
'permission'
)
models
.
Permission
.
_meta
.
permissions
=
[
Permission
.
_meta
.
permissions
=
[
(
'my_custom_permission'
,
'Some permission'
),
]
create_permissions
(
auth_app_config
,
verbosity
=
0
)
# add/change/delete permission by default + custom permission
self
.
assertEqual
(
models
.
Permission
.
objects
.
filter
(
self
.
assertEqual
(
Permission
.
objects
.
filter
(
content_type
=
permission_content_type
,
)
.
count
(),
4
)
models
.
Permission
.
objects
.
filter
(
content_type
=
permission_content_type
)
.
delete
()
models
.
Permission
.
_meta
.
default_permissions
=
[]
Permission
.
objects
.
filter
(
content_type
=
permission_content_type
)
.
delete
()
Permission
.
_meta
.
default_permissions
=
[]
create_permissions
(
auth_app_config
,
verbosity
=
0
)
# custom permission only since default permissions is empty
self
.
assertEqual
(
models
.
Permission
.
objects
.
filter
(
self
.
assertEqual
(
Permission
.
objects
.
filter
(
content_type
=
permission_content_type
,
)
.
count
(),
1
)
...
...
@@ -709,8 +709,8 @@ class PermissionTestCase(TestCase):
auth_app_config
=
apps
.
get_app_config
(
'auth'
)
permission_content_type
=
ContentType
.
objects
.
get_by_natural_key
(
'auth'
,
'permission'
)
models
.
Permission
.
objects
.
filter
(
content_type
=
permission_content_type
)
.
delete
()
models
.
Permission
.
_meta
.
verbose_name
=
"some ridiculously long verbose name that is out of control"
*
5
Permission
.
objects
.
filter
(
content_type
=
permission_content_type
)
.
delete
()
Permission
.
_meta
.
verbose_name
=
"some ridiculously long verbose name that is out of control"
*
5
six
.
assertRaisesRegex
(
self
,
exceptions
.
ValidationError
,
"The verbose_name of auth.permission is longer than 244 characters"
,
...
...
@@ -721,7 +721,7 @@ class PermissionTestCase(TestCase):
ContentType
.
objects
.
get_by_natural_key
(
'auth'
,
'permission'
)
custom_perm_name
=
'a'
*
256
models
.
Permission
.
_meta
.
permissions
=
[
Permission
.
_meta
.
permissions
=
[
(
'my_custom_permission'
,
custom_perm_name
),
]
try
:
...
...
@@ -732,4 +732,4 @@ class PermissionTestCase(TestCase):
with
self
.
assertRaisesMessage
(
exceptions
.
ValidationError
,
msg
):
create_permissions
(
auth_app_config
,
verbosity
=
0
)
finally
:
models
.
Permission
.
_meta
.
permissions
=
[]
Permission
.
_meta
.
permissions
=
[]
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