Skip to content

Commit fbd16d8

Browse files
committed
Test that non-string view arguments are supported.
Close #43.
1 parent bd34555 commit fbd16d8

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

tests/models.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# coding: utf-8
2+
3+
from __future__ import unicode_literals
4+
5+
from django.utils import six
6+
7+
8+
class NonAsciiRepr(object):
9+
def __repr__(self):
10+
return 'nôt åscíì' if six.PY3 else 'nôt åscíì'.encode('utf-8')

tests/tests.py

+4
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ def test_object_with_non_ascii_repr_in_context(self):
196196
response = self.client.get('/non_ascii_context/')
197197
self.assertContains(response, 'nôt åscíì')
198198

199+
def test_object_with_non_ascii_repr_in_request_vars(self):
200+
response = self.client.get('/non_ascii_request/')
201+
self.assertContains(response, 'nôt åscíì')
202+
199203
def test_xml_validation(self):
200204
response = self.client.get('/regular/XML/')
201205
ET.fromstring(response.content) # shouldn't raise ParseError

tests/urls.py

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
from django.conf.urls import patterns, url
1111
from django.contrib import admin
1212

13+
from .models import NonAsciiRepr
14+
15+
1316
admin.autodiscover()
1417

1518
urlpatterns = patterns('tests.views',
@@ -19,5 +22,6 @@
1922
url(r'^resolving3/(.+)/$', 'resolving_view', { 'arg2' : 'default' }),
2023
url(r'^regular/(?P<title>.*)/$', 'regular_view'),
2124
url(r'^non_ascii_context/$', 'non_ascii_context'),
25+
url(r'^non_ascii_request/$', 'regular_view', {'title': NonAsciiRepr()}),
2226
url(r'^execute_sql/$', 'execute_sql'),
2327
)

tests/views.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,15 @@
77
from django.shortcuts import render
88
from django.utils import six
99

10+
from .models import NonAsciiRepr
11+
1012

1113
def execute_sql(request):
1214
list(User.objects.all())
1315
return HttpResponse()
1416

1517

1618
def non_ascii_context(request):
17-
class NonAsciiRepr(object):
18-
def __repr__(self):
19-
return 'nôt åscíì' if six.PY3 else 'nôt åscíì'.encode('utf-8')
2019
return render(request, 'basic.html', {'title': NonAsciiRepr()})
2120

2221

0 commit comments

Comments
 (0)