Fixed #25424 -- Use force_str for test client URLs.
urlparse() fails with an AttributeError ("'__proxy__' object has no attribute 'decode'") if reverse_lazy is used to look up the URL (this is exactly the same problem that caused ticket #18776). The solution is to use force_str() on the path before handing it to urlparse().
This commit is contained in:
parent
43f2eb7ef3
commit
1a09b3c398
|
@ -355,7 +355,7 @@ class RequestFactory(object):
|
||||||
content_type='application/octet-stream', secure=False,
|
content_type='application/octet-stream', secure=False,
|
||||||
**extra):
|
**extra):
|
||||||
"""Constructs an arbitrary HTTP request."""
|
"""Constructs an arbitrary HTTP request."""
|
||||||
parsed = urlparse(path)
|
parsed = urlparse(force_str(path))
|
||||||
data = force_bytes(data, settings.DEFAULT_CHARSET)
|
data = force_bytes(data, settings.DEFAULT_CHARSET)
|
||||||
r = {
|
r = {
|
||||||
'PATH_INFO': self._get_path(parsed),
|
'PATH_INFO': self._get_path(parsed),
|
||||||
|
|
|
@ -26,6 +26,7 @@ import datetime
|
||||||
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.core import mail
|
from django.core import mail
|
||||||
|
from django.core.urlresolvers import reverse_lazy
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.test import (
|
from django.test import (
|
||||||
Client, RequestFactory, SimpleTestCase, TestCase, override_settings,
|
Client, RequestFactory, SimpleTestCase, TestCase, override_settings,
|
||||||
|
@ -623,6 +624,14 @@ class ClientTest(TestCase):
|
||||||
self.assertEqual(mail.outbox[0].to[0], 'first@example.com')
|
self.assertEqual(mail.outbox[0].to[0], 'first@example.com')
|
||||||
self.assertEqual(mail.outbox[0].to[1], 'second@example.com')
|
self.assertEqual(mail.outbox[0].to[1], 'second@example.com')
|
||||||
|
|
||||||
|
def test_reverse_lazy_decodes(self):
|
||||||
|
"Ensure reverse_lazy works in the test client"
|
||||||
|
data = {'var': 'data'}
|
||||||
|
response = self.client.get(reverse_lazy('get_view'), data)
|
||||||
|
|
||||||
|
# Check some response details
|
||||||
|
self.assertContains(response, 'This is a test')
|
||||||
|
|
||||||
def test_mass_mail_sending(self):
|
def test_mass_mail_sending(self):
|
||||||
"Test that mass mail is redirected to a dummy outbox during test setup"
|
"Test that mass mail is redirected to a dummy outbox during test setup"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue