Ticket #19075: 19075-2.diff

File 19075-2.diff, 3.1 KB (added by claudep, 2 years ago)

Ivan's patch + test

  • django/core/servers/basehttp.py

    diff --git a/django/core/servers/basehttp.py b/django/core/servers/basehttp.py
    index 19b287a..e95b96c 100644
    a b class WSGIRequestHandler(simple_server.WSGIRequestHandler, object): 
    144144        env['SERVER_PROTOCOL'] = self.request_version
    145145        env['REQUEST_METHOD'] = self.command
    146146        if '?' in self.path:
    147             path,query = self.path.split('?',1)
     147            path,query = self.path.split(str('?'),1)
    148148        else:
    149149            path,query = self.path,''
    150150
    151151        env['PATH_INFO'] = unquote(path)
    152152        env['QUERY_STRING'] = query
    153153        env['REMOTE_ADDR'] = self.client_address[0]
    154         env['CONTENT_TYPE'] = self.headers.get('content-type', 'text/plain')
     154        env['CONTENT_TYPE'] = self.headers.get('content-type', str('text/plain'))
    155155
    156156        length = self.headers.get('content-length')
    157157        if length:
  • tests/regressiontests/servers/tests.py

    diff --git a/tests/regressiontests/servers/tests.py b/tests/regressiontests/servers/tests.py
    index c90c785..f54e34c 100644
    a b  
     1# -*- encoding: utf-8 -*-
    12"""
    23Tests for django.core.servers.
    34"""
     5from __future__ import unicode_literals
     6
    47import os
    58try:
    69    from urllib.request import urlopen, HTTPError
    from django.core.exceptions import ImproperlyConfigured 
    1114from django.test import LiveServerTestCase
    1215from django.core.servers.basehttp import WSGIServerException
    1316from django.test.utils import override_settings
     17from django.utils.http import urlencode
    1418
    1519from .models import Person
    1620
    class LiveServerViews(LiveServerBase): 
    134138        f = self.urlopen('/media/example_media_file.txt')
    135139        self.assertEqual(f.read().rstrip(b'\r\n'), b'example media file')
    136140
     141    def test_environ(self):
     142        f = self.urlopen('/environ_view/?%s' % urlencode({'q': 'тест'}))
     143        self.assertIn(b"QUERY_STRING: 'q=%D1%82%D0%B5%D1%81%D1%82'", f.read())
     144
    137145
    138146class LiveServerDatabase(LiveServerBase):
    139147
  • tests/regressiontests/servers/urls.py

    diff --git a/tests/regressiontests/servers/urls.py b/tests/regressiontests/servers/urls.py
    index c8ca1ac..a857c45 100644
    a b urlpatterns = patterns('', 
    99    url(r'^example_view/$', views.example_view),
    1010    url(r'^model_view/$', views.model_view),
    1111    url(r'^create_model_instance/$', views.create_model_instance),
    12 )
    13  No newline at end of file
     12    url(r'^environ_view/$', views.environ_view),
     13)
  • tests/regressiontests/servers/views.py

    diff --git a/tests/regressiontests/servers/views.py b/tests/regressiontests/servers/views.py
    index 94a4f2d..00baf4b 100644
    a b def model_view(request): 
    1414def create_model_instance(request):
    1515    person = Person(name='emily')
    1616    person.save()
    17     return HttpResponse('')
    18  No newline at end of file
     17    return HttpResponse('')
     18
     19
     20def environ_view(request):
     21    return HttpResponse("\n".join(["%s: %r" % (k, v) for k, v in request.environ.items()]))
Back to Top