Alex Rivera | Logout

How do I get django celery to write to the test database for my functional tests?

Asked 2012-10-19T06:38:10.563
8

I am working on a Django application. We're using celery to queue writes to our Mongo database. I'm trying to write a functional test (using Selenium) for a function that queues something in celery.

The problem is that celery writes to the main Mongo database instead of the test database. How can I set up my functional tests to work with an instance of celery that writes to the test database?

We're using 'django_nose.NoseTestSuiteRunner' as our TEST_RUNNER.

UPDATE:

I haven't been able to figure out how to use another instance of celery for the tests, but I have found a way to bypass celery for the functional tests.

In my settings.py:

FUNC_TEST_COMMAND=['functional']
func_test_command = filter(lambda element: element in FUNC_TEST_COMMAND, sys.argv)
if len(func_test_command) > 0:
  CELERY_ALWAYS_EAGER = True

This mimics the behaviour of an AsyncResult without sending anything through a message queue when running the functional test suite. (See http://celery.readthedocs.org/en/2.4/configuration.html#celery-always-eager for more info.)

This solution is probably not ideal for functional tests, because it cuts out one of the application layers.

Edit
Report

1 Answer

0

I'd suggest that you take a look at LiveServerTestCase if your using an automated test client for running functional tests.

Then make sure you have a separate settings module your running your tests with that properly configures Celery to use your project's database for transport.

answered 2012-10-20T13:06:04.210

Your Answer