Commits

Mikhail Korobov committed 7677464 Merge

Merge pull request #7 from carljm/django16

Add compatibility with Django 1.6.

Comments (0)

Files changed (4)

django_webtest/__init__.py

 from django.utils.functional import curry
 from django.utils.importlib import import_module
 from django.core import signals
-from django.db import close_connection
+try:
+    from django.db import close_old_connections
+except ImportError:
+    from django.db import close_connection
+    close_old_connections = None
 try:
     from django.core.servers.basehttp import AdminMediaHandler as StaticFilesHandler
 except ImportError:
 
         # Django closes the database connection after every request;
         # this breaks the use of transactions in your tests.
-        signals.request_finished.disconnect(close_connection)
+        if close_old_connections is not None: # Django 1.6+
+            signals.request_started.disconnect(close_old_connections)
+            signals.request_finished.disconnect(close_old_connections)
+        else: # Django < 1.6
+            signals.request_finished.disconnect(close_connection)
 
         try:
             req.environ.setdefault('REMOTE_ADDR', '127.0.0.1')
             response.__class__ = self.response_class
             return response
         finally:
-            signals.request_finished.connect(close_connection)
+            if close_old_connections: # Django 1.6+
+                signals.request_started.connect(close_old_connections)
+                signals.request_finished.connect(close_old_connections)
+            else: # Django < 1.6
+                signals.request_finished.connect(close_connection)
 
 
     def get(self, url, params=None, headers=None, extra_environ=None,

django_webtest/response.py

         return self.body
 
     @property
+    def url(self):
+        return self['location']
+
+    @property
     def client(self):
         client = Client()
         client.cookies = SimpleCookie()

django_webtest_tests/runtests.py

 #!/usr/bin/env python
+import os
 import sys
-from django.core.management import execute_manager
-try:
-    import settings # Assumed to be in the same directory.
-except ImportError:
-    sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
-    sys.exit(1)
-
-sys.argv.insert(1, 'test')
-
-if len(sys.argv) == 2:
-    sys.argv.append('testapp_tests')
 
 if __name__ == "__main__":
-    execute_manager(settings)
+    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
+
+    from django.core.management import execute_from_command_line
+
+    sys.argv.insert(1, 'test')
+
+    if len(sys.argv) == 2:
+        sys.argv.append('testapp_tests')
+
+    execute_from_command_line(sys.argv)
 envlist =
     py26,py27,pypy,
     dj12-py26,
-    dj12,dj13,dj14,dj15,
+    dj12,dj13,dj14,dj15,dj16,
     dj15-py32,dj15-py33,dj15-py33-postgres,
     py26-wt1x, py32-wt2x
 
 deps=
     django >= 1.5.1, <1.6
 
+[django16]
+deps=
+    https://github.com/django/django/tarball/master
+
 [testenv:dj12-py26]
 basepython = python2.6
 deps=
     WebTest
     {[django15]deps}
 
+[testenv:dj16]
+deps=
+    WebTest
+    {[django16]deps}
+
 [testenv:dj15-py32]
 deps=
     {[testenv:dj15]deps}