algolia / algoliasearch-django

Seamless integration of Algolia into your Django project.
https://www.algolia.com
MIT License
173 stars 65 forks source link

Turning off Algolia for tests #242

Closed jdotjdot closed 6 years ago

jdotjdot commented 6 years ago

How do we turn off algoliasearch-django for tests? The way signals are registered, and the registration of models to the engine in apps.py has been breaking our test suite--we need a simple way to turn Algolia indexing on and off within tests with just a simple setting.

Is there any way to do this? The only way I can see is the with self.settings(...) modification in the docs, which isn't simple but also doesn't seem to work when we tried it. We either get items indexing, or we get error issues that a model is already registered when we try to just remove the INSTALLED_APPS entirely.

By using the with self.settings(...) method and turning 'AUTO_INDEXING' to False, we're actually getting a RegistrationError that the model isn't registered with the Algolia engine now. I want Algolia code not to be firing at all during this test, so I'm not sure why this is happening.

PLNech commented 6 years ago

Hi @jdotjdot, thanks for the feedback!

Indeed, this is something we didn't cover until now. I pushed an update to our demo app to showcase how you can turn off algoliasearch-django in your tests:

With this approach, you won't have algolia registered when running your tests. This should solve your issue, but if it persists please reopen this ticket and let me know what's happening!