Disable django-haystack During Testing

I use django-haystack and elasticsearch for the search engine in our apps. But I don’t want my model that registered to haystack do indexing during the testing. I avoid haystack indexing by adding these following lines of code below in my settings.py.

import sys

TESTING = 'test' in sys.argv
if TESTING:
    HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.BaseSignalProcessor'
    HAYSTACK_CONNECTIONS['default'] = {
        'ENGINE': 'haystack.backends.simple_backend.SimpleEngine',
    }

Reference: https://stackoverflow.com/q/33108569/1936697

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s