[Django] #20609: Documentation extension

9 views
Skip to first unread message

Django

unread,
Jun 15, 2013, 9:12:48 AM6/15/13
to django-...@googlegroups.com
#20609: Documentation extension
-------------------------------+--------------------
Reporter: michel@… | Owner: nobody
Type: Uncategorized | Status: new
Component: Documentation | Version: 1.5
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
I had a lot of problems finding out why I cannot use request.user in my
tests while using RequestFactory.

this line in the documentation
(https://docs.djangoproject.com/en/1.4/topics/testing/#the-request-
factory) seems to say it:

It does not support middleware. Session and authentication attributes must
be supplied by the test itself if required for the view to function
properly.

But it would be nice to have an example with a user added, like:

class TestCaseWithUser(TestCase):

def setUp(self):
# Every test needs access to the request factory.
self.factory = RequestFactory()
self.client = Client()
self.user_foo = User.objects.create_user('foo', 'f...@bar.com',
'bar')

def tearDown(self):
# Delete those objects that are saved in setup
self.user_foo.delete()

def test_request_user(self):
self.client.login( username='foo', password='bar')
request = self.factory.post('/my/url/', {"somedata": "data"})
# add a user so in the view to test request.user works
request.user = self.user_foo
nt.assert_equal(request.user,self.user_foo)

--
Ticket URL: <https://code.djangoproject.com/ticket/20609>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 17, 2013, 11:44:48 AM6/17/13
to django-...@googlegroups.com
#20609: Document how to use request.user with RequestFactory
--------------------------------------+------------------------------------
Reporter: michel@… | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.5
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timo):

* cc: timograham@… (added)
* needs_better_patch: => 0
* needs_tests: => 0
* easy: 0 => 1
* needs_docs: => 0
* type: Uncategorized => Cleanup/optimization
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/20609#comment:1>

Django

unread,
Jul 2, 2013, 4:21:03 AM7/2/13
to django-...@googlegroups.com
#20609: Document how to use request.user with RequestFactory
--------------------------------------+------------------------------------
Reporter: michel@… | Owner: susan
Type: Cleanup/optimization | Status: assigned
Component: Documentation | Version: 1.5

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by susan):

* status: new => assigned
* owner: nobody => susan


--
Ticket URL: <https://code.djangoproject.com/ticket/20609#comment:2>

Django

unread,
Jul 2, 2013, 4:24:28 AM7/2/13
to django-...@googlegroups.com
#20609: Document how to use request.user with RequestFactory
--------------------------------------+------------------------------------
Reporter: michel@… | Owner: susan
Type: Cleanup/optimization | Status: assigned
Component: Documentation | Version: 1.5

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by susan):

See https://github.com/django/django/pull/1319/files for PR. I edited the
given doc patch. Please code review. Thanks.

--
Ticket URL: <https://code.djangoproject.com/ticket/20609#comment:3>

Django

unread,
Jul 3, 2013, 11:07:06 AM7/3/13
to django-...@googlegroups.com
#20609: Document how to use request.user with RequestFactory
--------------------------------------+------------------------------------
Reporter: michel@… | Owner: susan
Type: Cleanup/optimization | Status: closed
Component: Documentation | Version: 1.5
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"067e0424ce8a0e15e2faac3f9f9fabe9b7667c72"]:
{{{
#!CommitTicketReference repository=""
revision="067e0424ce8a0e15e2faac3f9f9fabe9b7667c72"
Fixed #20609 -- Documented how to use request.user with RequestFactory

Thanks michel@ for the suggestion.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20609#comment:4>

Django

unread,
Jul 3, 2013, 11:12:01 AM7/3/13
to django-...@googlegroups.com
#20609: Document how to use request.user with RequestFactory
--------------------------------------+------------------------------------
Reporter: michel@… | Owner: susan
Type: Cleanup/optimization | Status: closed
Component: Documentation | Version: 1.5

Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"75041d5ea3821912abf8b9d1cd5477228a78cb23"]:
{{{
#!CommitTicketReference repository=""
revision="75041d5ea3821912abf8b9d1cd5477228a78cb23"
[1.6.x] Fixed #20609 -- Documented how to use request.user with
RequestFactory

Thanks michel@ for the suggestion.

Backport of 067e0424ce from master.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20609#comment:5>

Django

unread,
Jul 3, 2013, 11:12:58 AM7/3/13
to django-...@googlegroups.com
#20609: Document how to use request.user with RequestFactory
--------------------------------------+------------------------------------
Reporter: michel@… | Owner: susan
Type: Cleanup/optimization | Status: closed
Component: Documentation | Version: 1.5

Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"583f340d7dd52c6182530fd4ca798d01c4d93609"]:
{{{
#!CommitTicketReference repository=""
revision="583f340d7dd52c6182530fd4ca798d01c4d93609"
[1.5.x] Fixed #20609 -- Documented how to use request.user with
RequestFactory

Thanks michel@ for the suggestion.

Backport of 75041d5ea3 from stable/1.5.x.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20609#comment:6>

Django

unread,
Oct 5, 2014, 2:31:00 PM10/5/14
to django-...@googlegroups.com
#20609: Document how to use request.user with RequestFactory
--------------------------------------+------------------------------------
Reporter: michel@… | Owner: susan
Type: Cleanup/optimization | Status: closed
Component: Documentation | Version: 1.5

Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by nicbou):

* needs_better_patch: 0 => 1


Comment:

This is not sufficient. This still breaks when you need to test requests
where there is no authenticated user.

--
Ticket URL: <https://code.djangoproject.com/ticket/20609#comment:7>

Django

unread,
Oct 5, 2014, 2:31:09 PM10/5/14
to django-...@googlegroups.com
#20609: Document how to use request.user with RequestFactory
--------------------------------------+------------------------------------
Reporter: michel@… | Owner: susan
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.5
Severity: Normal | Resolution:

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by nicbou):

* status: closed => new
* resolution: fixed =>


--
Ticket URL: <https://code.djangoproject.com/ticket/20609#comment:8>

Django

unread,
Oct 20, 2014, 10:52:35 AM10/20/14
to django-...@googlegroups.com
#20609: Document how to use request.user with RequestFactory
--------------------------------------+------------------------------------
Reporter: michel@… | Owner: susan
Type: Cleanup/optimization | Status: closed
Component: Documentation | Version: 1.5
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"a39df37049c6b708924eed1521963929e0694b0c"]:
{{{
#!CommitTicketReference repository=""
revision="a39df37049c6b708924eed1521963929e0694b0c"
Fixed #20609 -- Added instructions for using AnonymousUser with
RequestFactory.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20609#comment:9>

Django

unread,
Oct 20, 2014, 10:52:55 AM10/20/14
to django-...@googlegroups.com
#20609: Document how to use request.user with RequestFactory
--------------------------------------+------------------------------------
Reporter: michel@… | Owner: susan
Type: Cleanup/optimization | Status: closed
Component: Documentation | Version: 1.5

Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"417923c69ee93f1737517156b13beaefc81f1e0e"]:
{{{
#!CommitTicketReference repository=""
revision="417923c69ee93f1737517156b13beaefc81f1e0e"
[1.7.x] Fixed #20609 -- Added instructions for using AnonymousUser with
RequestFactory.

Backport of a39df37049 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20609#comment:10>

Reply all
Reply to author
Forward
0 new messages