I am using *django_webtest* to test my views and *django_nose_selenium* to test the ajax on my site ( I could not get webtest.sel working + static files were not served since debug=False when running unit tests).
I am running the full test suite using
./manage.py test project --with-selenium --with-cherrypyliveserver
and keep getting erratic behavior between django_webtest and the selenium tests.
It seems like when I have an odd number of django webtest, the suite passes - when it's an even number, I get SAVEPOINT can only be used in transaction blocks exceptions ( see stack below). I discovered that by adding a simple test case ( assertTrue(2 == 1+1).
Could this be related to the cherrypy server settings? Any thoughts on what might be going on? What combination of tools do you use to test your views + ajax?
======================================================================
ERROR: test_update_project_files (proj.apps.project.tests.UpdateProjectTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/kepioo/Documents/code/virtualenvs/myproject/proj/../proj/apps/project/tests/integration_tests.py", line 88, in test_update_project_files
response = self.app.get("/project/manage/sample-project-name/", user="username")
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/django_webtest/__init__.py", line 71, in get
url, params, headers, extra_environ, status, expect_errors)
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/webtest/app.py", line 756, in get
expect_errors=expect_errors)
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/django_webtest/__init__.py", line 42, in do_request
response = super(DjangoTestApp, self).do_request(req, status, expect_errors)
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/webtest/app.py", line 1000, in do_request
res = req.get_response(app, catch_exc_info=True)
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/webob/request.py", line 1145, in get_response
application, catch_exc_info=True)
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/webob/request.py", line 1118, in call_application
app_iter = application(self.environ, start_response)
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/webtest/lint.py", line 173, in lint_app
iterator = application(environ, start_response_wrapper)
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/django_webtest/middleware.py", line 77, in __call__
return self.app(environ, start_response)
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/django/contrib/staticfiles/handlers.py", line 68, in __call__
return self.application(environ, start_response)
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/django/core/handlers/wsgi.py", line 272, in __call__
response = self.get_response(request)
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/django/core/handlers/base.py", line 169, in get_response
response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/django/core/handlers/base.py", line 89, in get_response
response = middleware_method(request)
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/django_webtest/middleware.py", line 49, in process_request
auth.login(request, user)
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/django/contrib/auth/__init__.py", line 80, in login
request.session.cycle_key()
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/django/contrib/sessions/backends/base.py", line 271, in cycle_key
self.create()
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/django/contrib/sessions/backends/db.py", line 40, in create
self.save(must_create=True)
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/django/contrib/sessions/backends/db.py", line 61, in save
sid = transaction.savepoint(using=using)
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/django/db/transaction.py", line 162, in savepoint
return connection.savepoint()
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/django/db/backends/__init__.py", line 223, in savepoint
self._savepoint(sid)
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/django/db/backends/__init__.py", line 70, in _savepoint
self.cursor().execute(self.ops.savepoint_create_sql(sid))
File "/Users/kepioo/Documents/code/virtualenvs/myproject/lib/python2.6/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 44, in execute
return self.cursor.execute(query, args)
DatabaseError: SAVEPOINT can only be used in transaction blocks
-------------------- >> begin captured stdout << ---------------------
query exception SAVEPOINT s140735086238912_x1
--------------------- >> end captured stdout << ----------------------
-------------------- >> begin captured logging << --------------------
tracking.middleware: DEBUG: Created a new visitor: {'session_key': '8a0c9599b9fcf95d75fc01ad3ed4411e', 'ip_address': '127.0.0.1'}
--------------------- >> end captured logging << ---------------------
----------------------------------------------------------------------
Ran 3 tests in 28.389s
FAILED (errors=1)
Destroying test database for alias 'default' ('test_mydb')...
I'm using webtest.sel without problem. Just add some stuff to serve your static files if you're in a test
Let say an env var:
Then in your urls.py: