Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #21164 -- Added documentation for issue with test users.

The package renaming restores the older package names (which were also the
documented package names). This doesn't affect test discovery because the
module in question doesn't contain any tests.

Thanks to Carl for the design discussion.
  • Loading branch information...
commit ddb53856b62506128a6d19184dfa80da73c77db8 1 parent 8ff4303
Russell Keith-Magee authored October 08, 2013
0  django/contrib/auth/tests/test_custom_user.py → django/contrib/auth/tests/custom_user.py
File renamed without changes
2  django/contrib/auth/tests/test_auth_backends.py
@@ -5,7 +5,7 @@
5 5
 from django.contrib.auth.backends import ModelBackend
6 6
 from django.contrib.auth.models import User, Group, Permission, AnonymousUser
7 7
 from django.contrib.auth.tests.utils import skipIfCustomUser
8  
-from django.contrib.auth.tests.test_custom_user import ExtensionUser, CustomPermissionsUser, CustomUser
  8
+from django.contrib.auth.tests.custom_user import ExtensionUser, CustomPermissionsUser, CustomUser
9 9
 from django.contrib.contenttypes.models import ContentType
10 10
 from django.core.exceptions import ImproperlyConfigured, PermissionDenied
11 11
 from django.contrib.auth import authenticate, get_user
2  django/contrib/auth/tests/test_basic.py
@@ -6,7 +6,7 @@
6 6
 from django.contrib.auth import get_user_model
7 7
 from django.contrib.auth.management.commands import createsuperuser
8 8
 from django.contrib.auth.models import User, AnonymousUser
9  
-from django.contrib.auth.tests.test_custom_user import CustomUser
  9
+from django.contrib.auth.tests.custom_user import CustomUser
10 10
 from django.contrib.auth.tests.utils import skipIfCustomUser
11 11
 from django.core.exceptions import ImproperlyConfigured
12 12
 from django.core.management import call_command
2  django/contrib/auth/tests/test_handlers.py
@@ -2,7 +2,7 @@
2 2
 
3 3
 from django.contrib.auth.handlers.modwsgi import check_password, groups_for_user
4 4
 from django.contrib.auth.models import User, Group
5  
-from django.contrib.auth.tests.test_custom_user import CustomUser
  5
+from django.contrib.auth.tests.custom_user import CustomUser
6 6
 from django.contrib.auth.tests.utils import skipIfCustomUser
7 7
 from django.test import TransactionTestCase
8 8
 from django.test.utils import override_settings
2  django/contrib/auth/tests/test_management.py
@@ -5,7 +5,7 @@
5 5
 from django.contrib.auth.management import create_permissions
6 6
 from django.contrib.auth.management.commands import changepassword
7 7
 from django.contrib.auth.models import User
8  
-from django.contrib.auth.tests.test_custom_user import CustomUser
  8
+from django.contrib.auth.tests.custom_user import CustomUser
9 9
 from django.contrib.auth.tests.utils import skipIfCustomUser
10 10
 from django.contrib.contenttypes.models import ContentType
11 11
 from django.core.management import call_command
23  docs/releases/1.6.txt
@@ -442,6 +442,29 @@ but will not be removed from Django until version 1.8.
442 442
 
443 443
 .. _recommendations in the Python documentation: http://docs.python.org/2/library/doctest.html#unittest-api
444 444
 
  445
+Custom User models in tests
  446
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
  447
+
  448
+The introduction of the new test runner has also slightly changed the way that
  449
+test models are imported. As a result, any test that overrides ``AUTH_USER_MODEL``
  450
+to test behavior with one of Django's test user models (
  451
+:class:`~django.contrib.auth.tests.custom_user.CustomUser` and
  452
+:class:`~django.contrib.auth.tests.custom_user.ExtensionUser`) must now
  453
+explicitly import the User model in your test module::
  454
+
  455
+    from django.contrib.auth.tests.custom_user import CustomUser
  456
+
  457
+    @override_settings(AUTH_USER_MODEL='auth.CustomUser')
  458
+    class CustomUserFeatureTests(TestCase):
  459
+        def test_something(self):
  460
+            # Test code here ...
  461
+
  462
+This import forces the custom user model to be registered. Without this import,
  463
+the test will be unable to swap in the custom user model, and you will get an
  464
+error reporting::
  465
+
  466
+    ImproperlyConfigured: AUTH_USER_MODEL refers to model 'auth.CustomUser' that has not been installed
  467
+
445 468
 Time zone-aware ``day``, ``month``, and ``week_day`` lookups
446 469
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
447 470
 
14  docs/topics/auth/customizing.txt
@@ -855,12 +855,14 @@ that the application works with *any* user model, not just the default User
855 855
 model. To assist with this, Django provides two substitute user models that
856 856
 can be used in test suites:
857 857
 
858  
-* ``django.contrib.auth.tests.custom_user.CustomUser``, a custom user
859  
-  model that uses an ``email`` field as the username, and has a basic
  858
+.. class:: tests.custom_user.CustomUser
  859
+
  860
+  A custom user model that uses an ``email`` field as the username, and has a basic
860 861
   admin-compliant permissions setup
861 862
 
862  
-* ``django.contrib.auth.tests.custom_user.ExtensionUser``, a custom
863  
-  user model that extends ``django.contrib.auth.models.AbstractUser``,
  863
+.. class:: tests.custom_user.ExtensionUser
  864
+
  865
+  A custom user model that extends ``django.contrib.auth.models.AbstractUser``,
864 866
   adding a ``date_of_birth`` field.
865 867
 
866 868
 You can then use the ``@override_settings`` decorator to make that test run
@@ -869,6 +871,7 @@ would test three possible User models -- the default, plus the two User
869 871
 models provided by ``auth`` app::
870 872
 
871 873
     from django.contrib.auth.tests.utils import skipIfCustomUser
  874
+    from django.contrib.auth.tests.custom_user import CustomUser, ExtensionUser
872 875
     from django.test import TestCase, override_settings
873 876
 
874 877
 
@@ -888,6 +891,9 @@ models provided by ``auth`` app::
888 891
             "Run tests for a simple extension of the built-in User."
889 892
             self.assertSomething()
890 893
 
  894
+.. versionchanged:: 1.6
  895
+
  896
+    In Django 1.5, it wasn't necessary to explicitly import the test User models.
891 897
 
892 898
 A full example
893 899
 --------------

0 notes on commit ddb5385

Please sign in to comment.
Something went wrong with that request. Please try again.