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
6eb3ce11
Kaydet (Commit)
6eb3ce11
authored
Şub 04, 2016
tarafından
Simon Charette
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #26089 -- Removed custom user test models from public API.
Thanks to Tim Graham for the review.
üst
19318507
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
47 additions
and
38 deletions
+47
-38
1.10.txt
docs/releases/1.10.txt
+7
-0
__init__.py
tests/auth_tests/models/__init__.py
+4
-2
custom_permissions.py
tests/auth_tests/models/custom_permissions.py
+2
-3
custom_user.py
tests/auth_tests/models/custom_user.py
+0
-6
uuid_pk.py
tests/auth_tests/models/uuid_pk.py
+2
-1
test_auth_backends.py
tests/auth_tests/test_auth_backends.py
+3
-4
test_basic.py
tests/auth_tests/test_basic.py
+3
-2
test_decorators.py
tests/auth_tests/test_decorators.py
+5
-5
test_handlers.py
tests/auth_tests/test_handlers.py
+4
-2
test_management.py
tests/auth_tests/test_management.py
+5
-4
test_mixins.py
tests/auth_tests/test_mixins.py
+10
-6
test_views.py
tests/auth_tests/test_views.py
+2
-3
No files found.
docs/releases/1.10.txt
Dosyayı görüntüle @
6eb3ce11
...
...
@@ -448,6 +448,13 @@ output::
}
}
``auth.CustomUser`` and ``auth.ExtensionUser`` test models were removed.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Since the introduction of migrations for the contrib apps in Django 1.8, the
tables of these custom user test models were not created anymore making them
unusable in a testing context.
Miscellaneous
~~~~~~~~~~~~~
...
...
tests/auth_tests/models/__init__.py
Dosyayı görüntüle @
6eb3ce11
from
.custom_permissions
import
CustomPermissionsUser
from
.custom_user
import
CustomUser
,
ExtensionUser
from
.invalid_models
import
CustomUserNonUniqueUsername
from
.is_active
import
IsActiveTestUser1
from
.uuid_pk
import
UUIDUser
from
.with_foreign_key
import
CustomUserWithFK
,
Email
__all__
=
(
'CustomPermissionsUser'
,
'CustomUserWithFK'
,
'Email'
,
'IsActiveTestUser1'
,
'UUIDUser'
,
'CustomUserNonUniqueUsername'
,
'CustomUser'
,
'CustomPermissionsUser'
,
'CustomUserWithFK'
,
'Email'
,
'ExtensionUser'
,
'IsActiveTestUser1'
,
'UUIDUser'
,
'CustomUserNonUniqueUsername'
,
)
tests/auth_tests/models/custom_permissions.py
Dosyayı görüntüle @
6eb3ce11
...
...
@@ -4,12 +4,11 @@ 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
from
.custom_user
import
CustomUserManager
,
RemoveGroupsAndPermissions
class
CustomPermissionsUserManager
(
CustomUserManager
):
def
create_superuser
(
self
,
email
,
password
,
date_of_birth
):
...
...
django/contrib/auth/test
s/custom_user.py
→
tests/auth_tests/model
s/custom_user.py
Dosyayı görüntüle @
6eb3ce11
...
...
@@ -43,9 +43,6 @@ class CustomUser(AbstractBaseUser):
USERNAME_FIELD
=
'email'
REQUIRED_FIELDS
=
[
'date_of_birth'
]
class
Meta
:
app_label
=
'auth'
def
get_full_name
(
self
):
return
self
.
email
...
...
@@ -108,6 +105,3 @@ with RemoveGroupsAndPermissions():
custom_objects
=
UserManager
()
REQUIRED_FIELDS
=
AbstractUser
.
REQUIRED_FIELDS
+
[
'date_of_birth'
]
class
Meta
:
app_label
=
'auth'
tests/auth_tests/models/uuid_pk.py
Dosyayı görüntüle @
6eb3ce11
import
uuid
from
django.contrib.auth.models
import
AbstractUser
from
django.contrib.auth.tests.custom_user
import
RemoveGroupsAndPermissions
from
django.db
import
models
from
.custom_user
import
RemoveGroupsAndPermissions
with
RemoveGroupsAndPermissions
():
class
UUIDUser
(
AbstractUser
):
"""A user with a UUID as primary key"""
...
...
tests/auth_tests/test_auth_backends.py
Dosyayı görüntüle @
6eb3ce11
...
...
@@ -8,7 +8,6 @@ from django.contrib.auth import (
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
CustomUser
,
ExtensionUser
from
django.contrib.contenttypes.models
import
ContentType
from
django.core.exceptions
import
ImproperlyConfigured
,
PermissionDenied
from
django.http
import
HttpRequest
...
...
@@ -16,7 +15,7 @@ from django.test import (
SimpleTestCase
,
TestCase
,
modify_settings
,
override_settings
,
)
from
.models
import
CustomPermissionsUser
,
UUIDUser
from
.models
import
CustomPermissionsUser
,
CustomUser
,
ExtensionUser
,
UUIDUser
class
CountingMD5PasswordHasher
(
MD5PasswordHasher
):
...
...
@@ -215,7 +214,7 @@ class ModelBackendTest(BaseModelBackendTest, TestCase):
)
@override_settings
(
AUTH_USER_MODEL
=
'auth.ExtensionUser'
)
@override_settings
(
AUTH_USER_MODEL
=
'auth
_tests
.ExtensionUser'
)
class
ExtensionUserModelBackendTest
(
BaseModelBackendTest
,
TestCase
):
"""
Tests for the ModelBackend using the custom ExtensionUser model.
...
...
@@ -275,7 +274,7 @@ class CustomPermissionsUserModelBackendTest(BaseModelBackendTest, TestCase):
)
@override_settings
(
AUTH_USER_MODEL
=
'auth.CustomUser'
)
@override_settings
(
AUTH_USER_MODEL
=
'auth
_tests
.CustomUser'
)
class
CustomUserModelBackendAuthenticateTest
(
TestCase
):
"""
Tests that the model backend can accept a credentials kwarg labeled with
...
...
tests/auth_tests/test_basic.py
Dosyayı görüntüle @
6eb3ce11
...
...
@@ -3,13 +3,14 @@ from __future__ import unicode_literals
from
django.apps
import
apps
from
django.contrib.auth
import
get_user_model
from
django.contrib.auth.models
import
AnonymousUser
,
User
from
django.contrib.auth.tests.custom_user
import
CustomUser
from
django.core.exceptions
import
ImproperlyConfigured
from
django.dispatch
import
receiver
from
django.test
import
TestCase
,
override_settings
from
django.test.signals
import
setting_changed
from
django.utils
import
translation
from
.models
import
CustomUser
@receiver
(
setting_changed
)
def
user_model_swapped
(
**
kwargs
):
...
...
@@ -87,7 +88,7 @@ class BasicTestCase(TestCase):
"The current user model can be retrieved"
self
.
assertEqual
(
get_user_model
(),
User
)
@override_settings
(
AUTH_USER_MODEL
=
'auth.CustomUser'
)
@override_settings
(
AUTH_USER_MODEL
=
'auth
_tests
.CustomUser'
)
def
test_swappable_user
(
self
):
"The current user model can be swapped out for another"
self
.
assertEqual
(
get_user_model
(),
CustomUser
)
...
...
tests/auth_tests/test_decorators.py
Dosyayı görüntüle @
6eb3ce11
...
...
@@ -68,7 +68,7 @@ class PermissionsRequiredDecoratorTest(TestCase):
def
test_many_permissions_pass
(
self
):
@permission_required
([
'auth
.add_customuser'
,
'auth
.change_customuser'
])
@permission_required
([
'auth
_tests.add_customuser'
,
'auth_tests
.change_customuser'
])
def
a_view
(
request
):
return
HttpResponse
()
request
=
self
.
factory
.
get
(
'/rand'
)
...
...
@@ -78,7 +78,7 @@ class PermissionsRequiredDecoratorTest(TestCase):
def
test_many_permissions_in_set_pass
(
self
):
@permission_required
({
'auth
.add_customuser'
,
'auth
.change_customuser'
})
@permission_required
({
'auth
_tests.add_customuser'
,
'auth_tests
.change_customuser'
})
def
a_view
(
request
):
return
HttpResponse
()
request
=
self
.
factory
.
get
(
'/rand'
)
...
...
@@ -88,7 +88,7 @@ class PermissionsRequiredDecoratorTest(TestCase):
def
test_single_permission_pass
(
self
):
@permission_required
(
'auth.add_customuser'
)
@permission_required
(
'auth
_tests
.add_customuser'
)
def
a_view
(
request
):
return
HttpResponse
()
request
=
self
.
factory
.
get
(
'/rand'
)
...
...
@@ -98,7 +98,7 @@ class PermissionsRequiredDecoratorTest(TestCase):
def
test_permissioned_denied_redirect
(
self
):
@permission_required
([
'auth
.add_customuser'
,
'auth
.change_customuser'
,
'non-existent-permission'
])
@permission_required
([
'auth
_tests.add_customuser'
,
'auth_tests
.change_customuser'
,
'non-existent-permission'
])
def
a_view
(
request
):
return
HttpResponse
()
request
=
self
.
factory
.
get
(
'/rand'
)
...
...
@@ -109,7 +109,7 @@ class PermissionsRequiredDecoratorTest(TestCase):
def
test_permissioned_denied_exception_raised
(
self
):
@permission_required
([
'auth
.add_customuser'
,
'auth
.change_customuser'
,
'non-existent-permission'
'auth
_tests.add_customuser'
,
'auth_tests
.change_customuser'
,
'non-existent-permission'
],
raise_exception
=
True
)
def
a_view
(
request
):
return
HttpResponse
()
...
...
tests/auth_tests/test_handlers.py
Dosyayı görüntüle @
6eb3ce11
...
...
@@ -4,9 +4,10 @@ from django.contrib.auth.handlers.modwsgi import (
check_password
,
groups_for_user
,
)
from
django.contrib.auth.models
import
Group
,
User
from
django.contrib.auth.tests.custom_user
import
CustomUser
from
django.test
import
TransactionTestCase
,
override_settings
from
.models
import
CustomUser
# This must be a TransactionTestCase because the WSGI auth handler performs
# its own transaction management.
...
...
@@ -18,6 +19,7 @@ class ModWsgiHandlerTestCase(TransactionTestCase):
available_apps
=
[
'django.contrib.auth'
,
'django.contrib.contenttypes'
,
'auth_tests'
,
]
def
test_check_password
(
self
):
...
...
@@ -40,7 +42,7 @@ class ModWsgiHandlerTestCase(TransactionTestCase):
# Valid user with incorrect password
self
.
assertFalse
(
check_password
({},
'test'
,
'incorrect'
))
@override_settings
(
AUTH_USER_MODEL
=
'auth.CustomUser'
)
@override_settings
(
AUTH_USER_MODEL
=
'auth
_tests
.CustomUser'
)
def
test_check_password_custom_user
(
self
):
"""
Verify that check_password returns the correct values as per
...
...
tests/auth_tests/test_management.py
Dosyayı görüntüle @
6eb3ce11
...
...
@@ -14,7 +14,6 @@ from django.contrib.auth.management.commands import (
from
django.contrib.auth.models
import
(
AbstractBaseUser
,
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
from
django.core.management
import
call_command
...
...
@@ -28,7 +27,9 @@ from django.utils import six
from
django.utils.encoding
import
force_str
from
django.utils.translation
import
ugettext_lazy
as
_
from
.models
import
CustomUserNonUniqueUsername
,
CustomUserWithFK
,
Email
from
.models
import
(
CustomUser
,
CustomUserNonUniqueUsername
,
CustomUserWithFK
,
Email
,
)
def
mock_inputs
(
inputs
):
...
...
@@ -287,7 +288,7 @@ class CreatesuperuserManagementCommandTestCase(TestCase):
self
.
assertEqual
(
u
.
email
,
'joe@somewhere.org'
)
self
.
assertFalse
(
u
.
has_usable_password
())
@override_settings
(
AUTH_USER_MODEL
=
'auth.CustomUser'
)
@override_settings
(
AUTH_USER_MODEL
=
'auth
_tests
.CustomUser'
)
def
test_swappable_user
(
self
):
"A superuser can be created when a custom User model is in use"
# We can use the management command to create a superuser
...
...
@@ -309,7 +310,7 @@ class CreatesuperuserManagementCommandTestCase(TestCase):
# created password should be unusable
self
.
assertFalse
(
u
.
has_usable_password
())
@override_settings
(
AUTH_USER_MODEL
=
'auth.CustomUser'
)
@override_settings
(
AUTH_USER_MODEL
=
'auth
_tests
.CustomUser'
)
def
test_swappable_user_missing_required_field
(
self
):
"A Custom superuser won't be created when a required field isn't provided"
# We can use the management command to create a superuser
...
...
tests/auth_tests/test_mixins.py
Dosyayı görüntüle @
6eb3ce11
...
...
@@ -35,12 +35,12 @@ class AlwaysFalseView(AlwaysFalseMixin, EmptyResponseView):
class
StackedMixinsView1
(
LoginRequiredMixin
,
PermissionRequiredMixin
,
EmptyResponseView
):
permission_required
=
[
'auth
.add_customuser'
,
'auth
.change_customuser'
]
permission_required
=
[
'auth
_tests.add_customuser'
,
'auth_tests
.change_customuser'
]
raise_exception
=
True
class
StackedMixinsView2
(
PermissionRequiredMixin
,
LoginRequiredMixin
,
EmptyResponseView
):
permission_required
=
[
'auth
.add_customuser'
,
'auth
.change_customuser'
]
permission_required
=
[
'auth
_tests.add_customuser'
,
'auth_tests
.change_customuser'
]
raise_exception
=
True
...
...
@@ -217,7 +217,7 @@ class PermissionsRequiredMixinTests(TestCase):
def
test_many_permissions_pass
(
self
):
class
AView
(
PermissionRequiredMixin
,
EmptyResponseView
):
permission_required
=
[
'auth
.add_customuser'
,
'auth
.change_customuser'
]
permission_required
=
[
'auth
_tests.add_customuser'
,
'auth_tests
.change_customuser'
]
request
=
self
.
factory
.
get
(
'/rand'
)
request
.
user
=
self
.
user
...
...
@@ -226,7 +226,7 @@ class PermissionsRequiredMixinTests(TestCase):
def
test_single_permission_pass
(
self
):
class
AView
(
PermissionRequiredMixin
,
EmptyResponseView
):
permission_required
=
'auth.add_customuser'
permission_required
=
'auth
_tests
.add_customuser'
request
=
self
.
factory
.
get
(
'/rand'
)
request
.
user
=
self
.
user
...
...
@@ -235,7 +235,9 @@ class PermissionsRequiredMixinTests(TestCase):
def
test_permissioned_denied_redirect
(
self
):
class
AView
(
PermissionRequiredMixin
,
EmptyResponseView
):
permission_required
=
[
'auth.add_customuser'
,
'auth.change_customuser'
,
'non-existent-permission'
]
permission_required
=
[
'auth_tests.add_customuser'
,
'auth_tests.change_customuser'
,
'non-existent-permission'
,
]
request
=
self
.
factory
.
get
(
'/rand'
)
request
.
user
=
self
.
user
...
...
@@ -244,7 +246,9 @@ class PermissionsRequiredMixinTests(TestCase):
def
test_permissioned_denied_exception_raised
(
self
):
class
AView
(
PermissionRequiredMixin
,
EmptyResponseView
):
permission_required
=
[
'auth.add_customuser'
,
'auth.change_customuser'
,
'non-existent-permission'
]
permission_required
=
[
'auth_tests.add_customuser'
,
'auth_tests.change_customuser'
,
'non-existent-permission'
,
]
raise_exception
=
True
request
=
self
.
factory
.
get
(
'/rand'
)
...
...
tests/auth_tests/test_views.py
Dosyayı görüntüle @
6eb3ce11
...
...
@@ -15,7 +15,6 @@ from django.contrib.auth.forms import (
AuthenticationForm
,
PasswordChangeForm
,
SetPasswordForm
,
)
from
django.contrib.auth.models
import
User
from
django.contrib.auth.tests.custom_user
import
CustomUser
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
...
...
@@ -31,7 +30,7 @@ from django.utils.http import urlquote
from
django.utils.six.moves.urllib.parse
import
ParseResult
,
urlparse
from
django.utils.translation
import
LANGUAGE_SESSION_KEY
from
.models
import
UUIDUser
from
.models
import
CustomUser
,
UUIDUser
from
.settings
import
AUTH_TEMPLATES
...
...
@@ -367,7 +366,7 @@ class PasswordResetTest(AuthViewsTestCase):
self
.
assertContains
(
response
,
"Hello, ."
)
@override_settings
(
AUTH_USER_MODEL
=
'auth.CustomUser'
)
@override_settings
(
AUTH_USER_MODEL
=
'auth
_tests
.CustomUser'
)
class
CustomUserPasswordResetTest
(
AuthViewsTestCase
):
user_email
=
'staffmember@example.com'
...
...
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