Commits

Mikhail Korobov committed cd0455e

python 3 support

Comments (0)

Files changed (7)

 - WebtestUserBackend is inserted after AuthenticationMiddleware, not to
   the end of middleware list (thanks bigkevmcd);
 - don't list python 2.5 as supported because WebOb dropped 2.5 support;
+- python 3 support;
 - test running using tox.
 
 1.4.4 (2012-02-08)

django_webtest/__init__.py

 from django.utils.functional import curry
 from django.utils.importlib import import_module
 from webtest import TestApp
+from webtest.compat import to_string
 
 from django_webtest.middleware import DjangoWsgiFix
 from django_webtest.response import DjangoWebtestResponse
         if user:
             environ = environ or {}
             if isinstance(user, User):
-                environ['WEBTEST_USER'] = str(user.username)
+                environ['WEBTEST_USER'] = to_string(user.username)
             else:
-                environ['WEBTEST_USER'] = user
+                environ['WEBTEST_USER'] = to_string(user)
         return environ
 
     def do_request(self, req, status, expect_errors):
+        req.environ.setdefault('REMOTE_ADDR', '127.0.0.1')
+
+        # is this a workaround for https://code.djangoproject.com/ticket/11111 ?
+        req.environ['REMOTE_ADDR'] = to_string(req.environ['REMOTE_ADDR'])
+        req.environ['PATH_INFO'] = to_string(req.environ['PATH_INFO'])
+
         # Curry a data dictionary into an instance of the template renderer
         # callback function.
-        req.environ.setdefault('REMOTE_ADDR', '127.0.0.1')
         data = {}
         on_template_render = curry(store_rendered_templates, data)
         template_rendered.connect(on_template_render)

django_webtest/response.py

 # -*- coding: utf-8 -*-
-import urlparse
+try:
+    import urlparse
+except ImportError: #python 3
+    from urllib import parse as urlparse
+
 from webtest import TestResponse
 from django.test import Client
 

django_webtest_tests/testapp_tests/tests.py

 # -*- coding: utf-8 -*-
+from __future__ import unicode_literals, absolute_import
 from webtest import AppError
+
 from django_webtest import WebTest
 from django.contrib.auth.models import User
 from django.core.urlresolvers import reverse
-from testapp_tests.views import PasswordForm
 
 class GetRequestTest(WebTest):
     def test_get_request(self):
 
     def test_assert_contains_unicode(self):
         response = self.app.get('/template/index.html')
-        self.assertContains(response, u'привет', 2)
+        self.assertContains(response, 'привет', 2)
 
     def test_assert_redirects(self):
         page = self.app.get(reverse('check_password'))

django_webtest_tests/urls.py

 # admin.autodiscover()
 
 def simple_method_test(request):
-    return HttpResponse(unicode(request.method))
+    return HttpResponse(str(request.method))
 
 def simple_template_render(request, template_name):
     return render_to_response(template_name, {
         'Intended Audience :: Developers',
         'License :: OSI Approved :: MIT License',
         'Programming Language :: Python',
+        'Programming Language :: Python :: 2',
         'Programming Language :: Python :: 2.6',
         'Programming Language :: Python :: 2.7',
+        'Programming Language :: Python :: 3',
+        'Programming Language :: Python :: 3.2',
         'Topic :: Software Development :: Libraries :: Python Modules',
         'Topic :: Software Development :: Testing',
     ],
 [tox]
-envlist = py26,py27,pypy
+envlist = py26,py27,pypy,py32
 
 [testenv]
 deps=
 
 commands=
     python django_webtest_tests/runtests.py
+
+[testenv:py32]
+deps=
+    WebTest
+    https://bitbucket.org/vinay.sajip/django/get/tip.zip#egg=django