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
5ab327a3
Kaydet (Commit)
5ab327a3
authored
Şub 11, 2015
tarafından
Tim Graham
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Moved non-documented auth test models to the new test location.
üst
2d7aca3d
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
175 additions
and
144 deletions
+175
-144
custom_user.py
django/contrib/auth/tests/custom_user.py
+25
-133
__init__.py
tests/auth_tests/models/__init__.py
+13
-0
custom_permissions.py
tests/auth_tests/models/custom_permissions.py
+43
-0
invalid_models.py
tests/auth_tests/models/invalid_models.py
+36
-0
is_active.py
tests/auth_tests/models/is_active.py
+18
-0
with_foreign_key.py
tests/auth_tests/models/with_foreign_key.py
+31
-0
test_auth_backends.py
tests/auth_tests/test_auth_backends.py
+3
-3
test_management.py
tests/auth_tests/test_management.py
+6
-4
test_models.py
tests/auth_tests/test_models.py
+0
-2
test_views.py
tests/auth_tests/test_views.py
+0
-2
No files found.
django/contrib/auth/tests/custom_user.py
Dosyayı görüntüle @
5ab327a3
...
...
@@ -8,7 +8,6 @@ from django.db import models
# The custom User uses email as the unique identifier, and requires
# that every user provide a date of birth. This lets us test
# changes in username datatype, and non-text required fields.
class
CustomUserManager
(
BaseUserManager
):
def
create_user
(
self
,
email
,
date_of_birth
,
password
=
None
):
"""
...
...
@@ -33,18 +32,6 @@ class CustomUserManager(BaseUserManager):
return
u
class
CustomUserWithFKManager
(
BaseUserManager
):
def
create_superuser
(
self
,
username
,
email
,
group
,
password
):
user
=
self
.
model
(
username_id
=
username
,
email_id
=
email
,
group_id
=
group
)
user
.
set_password
(
password
)
user
.
save
(
using
=
self
.
_db
)
return
user
class
Email
(
models
.
Model
):
email
=
models
.
EmailField
(
verbose_name
=
'email address'
,
max_length
=
255
,
unique
=
True
)
class
CustomUser
(
AbstractBaseUser
):
email
=
models
.
EmailField
(
verbose_name
=
'email address'
,
max_length
=
255
,
unique
=
True
)
is_active
=
models
.
BooleanField
(
default
=
True
)
...
...
@@ -90,132 +77,37 @@ class CustomUser(AbstractBaseUser):
return
self
.
is_admin
class
CustomUserWithFK
(
AbstractBaseUser
):
username
=
models
.
ForeignKey
(
Email
,
related_name
=
'primary'
)
email
=
models
.
ForeignKey
(
Email
,
to_field
=
'email'
,
related_name
=
'secondary'
)
group
=
models
.
ForeignKey
(
Group
)
custom_objects
=
CustomUserWithFKManager
()
USERNAME_FIELD
=
'username'
REQUIRED_FIELDS
=
[
'email'
,
'group'
]
class
Meta
:
app_label
=
'auth'
# At this point, temporarily remove the groups and user_permissions M2M
# fields from the AbstractUser class, so they don't clash with the related_name
# that sets.
class
RemoveGroupsAndPermissions
(
object
):
"""
A context manager to temporarily remove the groups and user_permissions M2M
fields from the AbstractUser class, so they don't clash with the
related_name sets.
"""
def
__enter__
(
self
):
self
.
_old_au_local_m2m
=
AbstractUser
.
_meta
.
local_many_to_many
self
.
_old_pm_local_m2m
=
PermissionsMixin
.
_meta
.
local_many_to_many
groups
=
models
.
ManyToManyField
(
Group
,
blank
=
True
)
groups
.
contribute_to_class
(
PermissionsMixin
,
"groups"
)
user_permissions
=
models
.
ManyToManyField
(
Permission
,
blank
=
True
)
user_permissions
.
contribute_to_class
(
PermissionsMixin
,
"user_permissions"
)
PermissionsMixin
.
_meta
.
local_many_to_many
=
[
groups
,
user_permissions
]
AbstractUser
.
_meta
.
local_many_to_many
=
[
groups
,
user_permissions
]
old_au_local_m2m
=
AbstractUser
.
_meta
.
local_many_to_many
old_pm_local_m2m
=
PermissionsMixin
.
_meta
.
local_many_to_many
groups
=
models
.
ManyToManyField
(
Group
,
blank
=
True
)
groups
.
contribute_to_class
(
PermissionsMixin
,
"groups"
)
user_permissions
=
models
.
ManyToManyField
(
Permission
,
blank
=
True
)
user_permissions
.
contribute_to_class
(
PermissionsMixin
,
"user_permissions"
)
PermissionsMixin
.
_meta
.
local_many_to_many
=
[
groups
,
user_permissions
]
AbstractUser
.
_meta
.
local_many_to_many
=
[
groups
,
user_permissions
]
def
__exit__
(
self
,
exc_type
,
exc_value
,
traceback
):
AbstractUser
.
_meta
.
local_many_to_many
=
self
.
_old_au_local_m2m
PermissionsMixin
.
_meta
.
local_many_to_many
=
self
.
_old_pm_local_m2m
# The extension user is a simple extension of the built-in user class,
# adding a required date_of_birth field. This allows us to check for
# any hard references to the name "User" in forms/handlers etc.
with
RemoveGroupsAndPermissions
():
class
ExtensionUser
(
AbstractUser
):
date_of_birth
=
models
.
DateField
()
class
ExtensionUser
(
AbstractUser
):
date_of_birth
=
models
.
DateField
()
custom_objects
=
UserManager
()
REQUIRED_FIELDS
=
AbstractUser
.
REQUIRED_FIELDS
+
[
'date_of_birth'
]
class
Meta
:
app_label
=
'auth'
# The CustomPermissionsUser users email as the identifier, but uses the normal
# Django permissions model. This allows us to check that the PermissionsMixin
# includes everything that is needed to interact with the ModelBackend.
class
CustomPermissionsUserManager
(
CustomUserManager
):
def
create_superuser
(
self
,
email
,
password
,
date_of_birth
):
u
=
self
.
create_user
(
email
,
password
=
password
,
date_of_birth
=
date_of_birth
)
u
.
is_superuser
=
True
u
.
save
(
using
=
self
.
_db
)
return
u
class
CustomPermissionsUser
(
AbstractBaseUser
,
PermissionsMixin
):
email
=
models
.
EmailField
(
verbose_name
=
'email address'
,
max_length
=
255
,
unique
=
True
)
date_of_birth
=
models
.
DateField
()
custom_objects
=
CustomPermissionsUserManager
()
USERNAME_FIELD
=
'email'
REQUIRED_FIELDS
=
[
'date_of_birth'
]
class
Meta
:
app_label
=
'auth'
def
get_full_name
(
self
):
return
self
.
email
def
get_short_name
(
self
):
return
self
.
email
def
__unicode__
(
self
):
return
self
.
email
class
IsActiveTestUser1
(
AbstractBaseUser
):
"""
This test user class and derivatives test the default is_active behavior
"""
username
=
models
.
CharField
(
max_length
=
30
,
unique
=
True
)
custom_objects
=
BaseUserManager
()
USERNAME_FIELD
=
'username'
class
Meta
:
app_label
=
'auth'
custom_objects
=
UserManager
()
# the is_active attr is provided by AbstractBaseUser
class
CustomUserNonUniqueUsername
(
AbstractBaseUser
):
"A user with a non-unique username"
username
=
models
.
CharField
(
max_length
=
30
)
USERNAME_FIELD
=
'username'
class
Meta
:
app_label
=
'auth'
class
CustomUserNonListRequiredFields
(
AbstractBaseUser
):
"A user with a non-list REQUIRED_FIELDS"
username
=
models
.
CharField
(
max_length
=
30
,
unique
=
True
)
date_of_birth
=
models
.
DateField
()
USERNAME_FIELD
=
'username'
REQUIRED_FIELDS
=
'date_of_birth'
class
Meta
:
app_label
=
'auth'
class
CustomUserBadRequiredFields
(
AbstractBaseUser
):
"A user with a USERNAME_FIELD that appears in REQUIRED_FIELDS (invalid)"
username
=
models
.
CharField
(
max_length
=
30
,
unique
=
True
)
date_of_birth
=
models
.
DateField
()
USERNAME_FIELD
=
'username'
REQUIRED_FIELDS
=
[
'username'
,
'date_of_birth'
]
class
Meta
:
app_label
=
'auth'
REQUIRED_FIELDS
=
AbstractUser
.
REQUIRED_FIELDS
+
[
'date_of_birth'
]
# Undo swap hack
AbstractUser
.
_meta
.
local_many_to_many
=
old_au_local_m2m
PermissionsMixin
.
_meta
.
local_many_to_many
=
old_pm_local_m2m
class
Meta
:
app_label
=
'auth'
tests/auth_tests/models/__init__.py
0 → 100644
Dosyayı görüntüle @
5ab327a3
from
.custom_permissions
import
CustomPermissionsUser
from
.is_active
import
IsActiveTestUser1
from
.invalid_models
import
(
CustomUserNonUniqueUsername
,
CustomUserNonListRequiredFields
,
CustomUserBadRequiredFields
,
)
from
.with_foreign_key
import
CustomUserWithFK
,
Email
__all__
=
(
'CustomPermissionsUser'
,
'CustomUserNonUniqueUsername'
,
'CustomUserNonListRequiredFields'
,
'CustomUserBadRequiredFields'
,
'CustomUserWithFK'
,
'Email'
,
'IsActiveTestUser1'
,
)
tests/auth_tests/models/custom_permissions.py
0 → 100644
Dosyayı görüntüle @
5ab327a3
"""
The CustomPermissionsUser users email as the identifier, but uses the normal
Django permissions model. This allows us to check that the PermissionsMixin
includes everything that is needed to interact with the ModelBackend.
"""
from
django.contrib.auth.models
import
AbstractBaseUser
,
PermissionsMixin
from
django.contrib.auth.tests.custom_user
import
(
CustomUserManager
,
RemoveGroupsAndPermissions
,
)
from
django.db
import
models
from
django.utils.encoding
import
python_2_unicode_compatible
class
CustomPermissionsUserManager
(
CustomUserManager
):
def
create_superuser
(
self
,
email
,
password
,
date_of_birth
):
u
=
self
.
create_user
(
email
,
password
=
password
,
date_of_birth
=
date_of_birth
)
u
.
is_superuser
=
True
u
.
save
(
using
=
self
.
_db
)
return
u
with
RemoveGroupsAndPermissions
():
@python_2_unicode_compatible
class
CustomPermissionsUser
(
AbstractBaseUser
,
PermissionsMixin
):
email
=
models
.
EmailField
(
verbose_name
=
'email address'
,
max_length
=
255
,
unique
=
True
)
date_of_birth
=
models
.
DateField
()
custom_objects
=
CustomPermissionsUserManager
()
USERNAME_FIELD
=
'email'
REQUIRED_FIELDS
=
[
'date_of_birth'
]
class
Meta
:
app_label
=
'auth'
def
get_full_name
(
self
):
return
self
.
email
def
get_short_name
(
self
):
return
self
.
email
def
__str__
(
self
):
return
self
.
email
tests/auth_tests/models/invalid_models.py
0 → 100644
Dosyayı görüntüle @
5ab327a3
from
django.contrib.auth.models
import
AbstractBaseUser
from
django.db
import
models
class
CustomUserNonUniqueUsername
(
AbstractBaseUser
):
"A user with a non-unique username"
username
=
models
.
CharField
(
max_length
=
30
)
USERNAME_FIELD
=
'username'
class
Meta
:
app_label
=
'auth'
class
CustomUserNonListRequiredFields
(
AbstractBaseUser
):
"A user with a non-list REQUIRED_FIELDS"
username
=
models
.
CharField
(
max_length
=
30
,
unique
=
True
)
date_of_birth
=
models
.
DateField
()
USERNAME_FIELD
=
'username'
REQUIRED_FIELDS
=
'date_of_birth'
class
Meta
:
app_label
=
'auth'
class
CustomUserBadRequiredFields
(
AbstractBaseUser
):
"A user with a USERNAME_FIELD that appears in REQUIRED_FIELDS (invalid)"
username
=
models
.
CharField
(
max_length
=
30
,
unique
=
True
)
date_of_birth
=
models
.
DateField
()
USERNAME_FIELD
=
'username'
REQUIRED_FIELDS
=
[
'username'
,
'date_of_birth'
]
class
Meta
:
app_label
=
'auth'
tests/auth_tests/models/is_active.py
0 → 100644
Dosyayı görüntüle @
5ab327a3
from
django.contrib.auth.models
import
AbstractBaseUser
,
BaseUserManager
from
django.db
import
models
class
IsActiveTestUser1
(
AbstractBaseUser
):
"""
This test user class and derivatives test the default is_active behavior
"""
username
=
models
.
CharField
(
max_length
=
30
,
unique
=
True
)
custom_objects
=
BaseUserManager
()
USERNAME_FIELD
=
'username'
class
Meta
:
app_label
=
'auth'
# the is_active attr is provided by AbstractBaseUser
tests/auth_tests/models/with_foreign_key.py
0 → 100644
Dosyayı görüntüle @
5ab327a3
from
django.contrib.auth.models
import
AbstractBaseUser
,
BaseUserManager
,
Group
from
django.db
import
models
class
Email
(
models
.
Model
):
email
=
models
.
EmailField
(
verbose_name
=
'email address'
,
max_length
=
255
,
unique
=
True
)
class
Meta
:
app_label
=
'auth'
class
CustomUserWithFKManager
(
BaseUserManager
):
def
create_superuser
(
self
,
username
,
email
,
group
,
password
):
user
=
self
.
model
(
username_id
=
username
,
email_id
=
email
,
group_id
=
group
)
user
.
set_password
(
password
)
user
.
save
(
using
=
self
.
_db
)
return
user
class
CustomUserWithFK
(
AbstractBaseUser
):
username
=
models
.
ForeignKey
(
Email
,
related_name
=
'primary'
)
email
=
models
.
ForeignKey
(
Email
,
to_field
=
'email'
,
related_name
=
'secondary'
)
group
=
models
.
ForeignKey
(
Group
)
custom_objects
=
CustomUserWithFKManager
()
USERNAME_FIELD
=
'username'
REQUIRED_FIELDS
=
[
'email'
,
'group'
]
class
Meta
:
app_label
=
'auth'
tests/auth_tests/test_auth_backends.py
Dosyayı görüntüle @
5ab327a3
...
...
@@ -6,14 +6,14 @@ from django.contrib.auth import BACKEND_SESSION_KEY, authenticate, get_user
from
django.contrib.auth.backends
import
ModelBackend
from
django.contrib.auth.hashers
import
MD5PasswordHasher
from
django.contrib.auth.models
import
AnonymousUser
,
Group
,
Permission
,
User
from
django.contrib.auth.tests.custom_user
import
(
CustomPermissionsUser
,
CustomUser
,
ExtensionUser
,
)
from
django.contrib.auth.tests.custom_user
import
CustomUser
,
ExtensionUser
from
django.contrib.contenttypes.models
import
ContentType
from
django.core.exceptions
import
ImproperlyConfigured
,
PermissionDenied
from
django.http
import
HttpRequest
from
django.test
import
TestCase
,
modify_settings
,
override_settings
from
.models
import
CustomPermissionsUser
class
CountingMD5PasswordHasher
(
MD5PasswordHasher
):
"""Hasher that counts how many times it computes a hash."""
...
...
tests/auth_tests/test_management.py
Dosyayı görüntüle @
5ab327a3
...
...
@@ -12,10 +12,7 @@ from django.contrib.auth.management.commands import (
changepassword
,
createsuperuser
,
)
from
django.contrib.auth.models
import
Group
,
User
from
django.contrib.auth.tests.custom_user
import
(
CustomUser
,
CustomUserBadRequiredFields
,
CustomUserNonListRequiredFields
,
CustomUserNonUniqueUsername
,
CustomUserWithFK
,
Email
,
)
from
django.contrib.auth.tests.custom_user
import
CustomUser
from
django.contrib.contenttypes.models
import
ContentType
from
django.core
import
checks
,
exceptions
from
django.core.management
import
call_command
...
...
@@ -25,6 +22,11 @@ from django.utils import six
from
django.utils.encoding
import
force_str
from
django.utils.translation
import
ugettext_lazy
as
_
from
.models
import
(
CustomUserBadRequiredFields
,
CustomUserNonListRequiredFields
,
CustomUserNonUniqueUsername
,
CustomUserWithFK
,
Email
,
)
def
mock_inputs
(
inputs
):
"""
...
...
tests/auth_tests/test_models.py
Dosyayı görüntüle @
5ab327a3
...
...
@@ -2,8 +2,6 @@ from django.contrib.auth import get_user_model
from
django.contrib.auth.models
import
(
AbstractUser
,
Group
,
Permission
,
User
,
UserManager
,
)
# Needed so model is installed when tests are run independently:
from
django.contrib.auth.tests.custom_user
import
IsActiveTestUser1
# NOQA
from
django.contrib.contenttypes.models
import
ContentType
from
django.core
import
mail
from
django.db.models.signals
import
post_save
...
...
tests/auth_tests/test_views.py
Dosyayı görüntüle @
5ab327a3
...
...
@@ -13,8 +13,6 @@ from django.contrib.auth.forms import (
AuthenticationForm
,
PasswordChangeForm
,
SetPasswordForm
,
)
from
django.contrib.auth.models
import
User
# Needed so model is installed when tests are run independently:
from
django.contrib.auth.tests.custom_user
import
CustomUser
# NOQA
from
django.contrib.auth.views
import
login
as
login_view
,
redirect_to_login
from
django.contrib.sessions.middleware
import
SessionMiddleware
from
django.contrib.sites.requests
import
RequestSite
...
...
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