[Django] #23922: Quoting problem in RequestFactory

21 views
Skip to first unread message

Django

unread,
Nov 26, 2014, 3:35:10 PM11/26/14
to django-...@googlegroups.com
#23922: Quoting problem in RequestFactory
-----------------------------------+--------------------
Reporter: berkerpeksag | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------
I was trying to convert middleware tests to use `RequestFactory`. I've
converted all tests easily except
`CommonMiddlewareTest.test_append_slash_quoted`:

{{{#!python
@override_settings(APPEND_SLASH=True)
def test_append_slash_quoted(self):
"""
Tests that URLs which require quoting are redirected to their
slash
version ok.
"""
request = self._get_request('needsquoting#')
r = CommonMiddleware().process_request(request)
self.assertEqual(r.status_code, 301)
self.assertEqual(
r.url,
'http://testserver/needsquoting%23/')
}}}

https://github.com/django/django/blob/master/tests/middleware/tests.py#L94

The `urlparse` call in the `RequestFactory.generic` method swallows `#` in
the URL. The test is passing with a plain `HttpRequest` object.

Here is a try to fix this problem:
https://github.com/berkerpeksag/django/compare/use-requestfactory

An alternative fix would be to wrap `path` with `quote(path, safe=b"...")`
or with `django.utils.encoding.escape_uri_path` in
`RequestFactory.generic`:

https://github.com/django/django/blob/master/django/test/client.py#L351

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

Django

unread,
Nov 27, 2014, 9:06:07 AM11/27/14
to django-...@googlegroups.com
#23922: Quoting problem in RequestFactory
-----------------------------------+------------------------------------

Reporter: berkerpeksag | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted


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

Django

unread,
Nov 29, 2014, 1:49:04 AM11/29/14
to django-...@googlegroups.com
#23922: Quoting problem in RequestFactory
-------------------------------------+-------------------------------------
Reporter: berkerpeksag | Owner:
Type: Bug | berkerpeksag
Component: Testing framework | Status: assigned
Severity: Normal | Version: master
Keywords: | Resolution:
Has patch: 1 | Triage Stage: Accepted
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by berkerpeksag):

* owner: nobody => berkerpeksag
* status: new => assigned
* has_patch: 0 => 1


Comment:

https://github.com/django/django/pull/3645

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

Django

unread,
Dec 8, 2014, 8:02:29 AM12/8/14
to django-...@googlegroups.com
#23922: Quoting problem in RequestFactory
-------------------------------------+-------------------------------------
Reporter: berkerpeksag | Owner:
Type: Bug | berkerpeksag
Component: Testing framework | Status: assigned
Severity: Normal | Version: master
Keywords: | Resolution:
Has patch: 1 | Triage Stage: Accepted
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 1
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: 0 => 1


Comment:

Question about the implementation left on the PR.

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

Django

unread,
Dec 25, 2014, 8:51:45 AM12/25/14
to django-...@googlegroups.com
#23922: Quoting problem in RequestFactory
-------------------------------------+-------------------------------------
Reporter: berkerpeksag | Owner:
| berkerpeksag
Type: Bug | Status: assigned

Component: Testing framework | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by timgraham):

On further investigation, I think we can simply use the urlencoded version
of # when updating that test to use `RequestFactory` like this:
`rf.get('/needsquoting%23')`. The test passes and works as a regression
test as originally intended if I remove `urlquote` from
`urlquote(new_url[1])` in `CommonMiddleware`.

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

Django

unread,
Dec 27, 2014, 5:42:58 PM12/27/14
to django-...@googlegroups.com
#23922: Quoting problem in RequestFactory
-------------------------------------+-------------------------------------
Reporter: berkerpeksag | Owner:
| berkerpeksag
Type: Bug | Status: closed

Component: Testing framework | Version: master
Severity: Normal | Resolution: invalid

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

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

* status: assigned => closed
* needs_better_patch: 1 => 0
* resolution: => invalid


Comment:

Thanks. I agree with your analysis. I'll convert my branch to a pull
request and will close [https://github.com/django/django/pull/3645 PR
#3645].

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

Reply all
Reply to author
Forward
0 new messages