diff options
| author | Tim Graham <timograham@gmail.com> | 2014-10-20 10:51:25 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2014-10-20 10:52:36 -0400 |
| commit | 417923c69ee93f1737517156b13beaefc81f1e0e (patch) | |
| tree | 5cecc229c060149571b52e7f041c2d3701107f41 /docs | |
| parent | a2ebbf891675d264a9fa6a9b2bcef976386b8da7 (diff) | |
[1.7.x] Fixed #20609 -- Added instructions for using AnonymousUser with RequestFactory.
Backport of a39df37049 from master
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/topics/testing/advanced.txt | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/docs/topics/testing/advanced.txt b/docs/topics/testing/advanced.txt index 0c7ca724fd..a60801ebca 100644 --- a/docs/topics/testing/advanced.txt +++ b/docs/topics/testing/advanced.txt @@ -37,7 +37,7 @@ Example The following is a simple unit test using the request factory:: - from django.contrib.auth.models import User + from django.contrib.auth.models import AnonymousUser, User from django.test import TestCase, RequestFactory class SimpleTest(TestCase): @@ -55,6 +55,10 @@ The following is a simple unit test using the request factory:: # logged-in user by setting request.user manually. request.user = self.user + # Or you can simulate an anonymous user by setting request.user to + # an AnonymousUser instance. + request.user = AnonymousUser() + # Test my_view() as if it were deployed at /customer/details response = my_view(request) self.assertEqual(response.status_code, 200) |
