Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Prepare settings and existing tests for db search backend

Jakub Draganek159d73eae1aa
diff --git a/saleor/settings.py b/saleor/settings.py
index fa48339f89..7f0388a4cd 100644
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -357,16 +357,20 @@ WEBPACK_LOADER = {
LOGOUT_ON_PASSWORD_CHANGE = False
+# SEARCH CONFIGURATION
+DB_SEARCH_ENABLED = True
+PREFER_DB_SEARCH = False # prefer db backend over elasticsearch
ELASTICSEARCH_URL = os.environ.get('ELASTICSEARCH_URL')
SEARCHBOX_URL = os.environ.get('SEARCHBOX_URL')
BONSAI_URL = os.environ.get('BONSAI_URL')
+
# We'll support couple of elasticsearch add-ons, but finally we'll use single
# variable
ES_URL = ELASTICSEARCH_URL or SEARCHBOX_URL or BONSAI_URL
-ENABLE_SEARCH = bool(ES_URL)
+ENABLE_SEARCH = bool(ES_URL) or DB_SEARCH_ENABLED
-if ENABLE_SEARCH:
+if ES_URL:
INSTALLED_APPS.append('django_elasticsearch_dsl')
ELASTICSEARCH_DSL = {
'default': {
diff --git a/tests/test_search.py b/tests/test_search.py
index 7345ff3546..49b48d4ffc 100644
--- a/tests/test_search.py
+++ b/tests/test_search.py
@@ -18,19 +18,26 @@ PRODUCTS_TO_UNPUBLISH = {56} # choose from PRODUCTS_INDEXED
PHRASE_WITH_RESULTS = 'Group'
PHRASE_WITHOUT_RESULTS = 'foo'
+ES_URL = 'http://search:9200' # make it real for communication recording
+
+
[email protected](scope='module', autouse=True)
+def elasticsearch_connection():
+ connections.create_connection('default', hosts=[ES_URL])
+
@pytest.fixture(scope='function', autouse=True)
-def es_autosync_disabled(settings):
- ''' Prevent ES index from being refreshed every time obj is saved '''
+def elasticsearch_enabled(settings):
+ settings.ELASTICSEARCH_URL = ES_URL
settings.ENABLE_SEARCH = True
- settings.ELASTICSEARCH_DSL_AUTO_REFRESH = False
- settings.ELASTICSEARCH_DSL_AUTOSYNC = False
+ settings.PREFER_DB_SEARCH = False
[email protected](scope='module', autouse=True)
-def enable_es():
- ES_URL = 'http://search:9200'
- connections.create_connection('default', hosts=[ES_URL])
[email protected](scope='function', autouse=True)
+def elasticsearch_autosync_disabled(settings):
+ ''' Prevent ES index from being refreshed every time obj is saved '''
+ settings.ELASTICSEARCH_DSL_AUTO_REFRESH = False
+ settings.ELASTICSEARCH_DSL_AUTOSYNC = False
@pytest.mark.vcr()