#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.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/055.8f5dbdbb489d6577dd956f2169e3113e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.