From 7459329d93026e02aa6888ffaf4fea916ba9deef Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Mon, 9 Nov 2015 12:13:07 +0000 Subject: [PATCH] Added --elasticsearch argument to runtests.py --- docs/contributing/developing.rst | 15 +++++++++------ runtests.py | 4 ++++ wagtail/tests/settings.py | 13 ++----------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/docs/contributing/developing.rst b/docs/contributing/developing.rst index 3ac0a68349..01e5447961 100644 --- a/docs/contributing/developing.rst +++ b/docs/contributing/developing.rst @@ -92,16 +92,19 @@ the tests against it. To test Elasticsearch, you need to have the ``elasticsearch`` package installed. -Once installed, Wagtail will attempt to connect to a local instance of -Elasticsearch (``http://localhost:9200``) and use the index ``test_wagtail``. +Once installed, you can test Wagtail with Elasticsearch by passing the +``--elasticsearch`` argument to ``runtests.py``:: + + python runtests.py --elasticsearch + + +Wagtail will attempt to connect to a local instance of Elasticsearch +(``http://localhost:9200``) and use the index ``test_wagtail``. If your Elasticsearch instance is located somewhere else, you can set the ``ELASTICSEARCH_URL`` environment variable to point to its location:: - ELASTICSEARCH_URL=http://my-elasticsearch-instance:9200 python runtests.py - -If you no longer want Wagtail to test against Elasticsearch, uninstall the -``elasticsearch`` package. + ELASTICSEARCH_URL=http://my-elasticsearch-instance:9200 python runtests.py --elasticsearch Compiling static assets ~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/runtests.py b/runtests.py index 1a674c29a1..2e9a9de231 100755 --- a/runtests.py +++ b/runtests.py @@ -22,6 +22,10 @@ def runtests(): os.environ['DATABASE_ENGINE'] = 'django.db.backends.postgresql_psycopg2' args.remove('--postgres') + if '--elasticsearch' in args: + os.environ.setdefault('ELASTICSEARCH_URL', 'http://localhost:9200') + args.remove('--elasticsearch') + argv = sys.argv[:1] + ['test'] + args try: execute_from_command_line(argv) diff --git a/wagtail/tests/settings.py b/wagtail/tests/settings.py index 9af3be45eb..cf4f36055d 100644 --- a/wagtail/tests/settings.py +++ b/wagtail/tests/settings.py @@ -157,23 +157,14 @@ WAGTAILSEARCH_BACKENDS = { AUTH_USER_MODEL = 'customuser.CustomUser' -try: - # Only add Elasticsearch backend if the elasticsearch-py library is installed - import elasticsearch # noqa - - # Import succeeded, add an Elasticsearch backend +if 'ELASTICSEARCH_URL' in os.environ: WAGTAILSEARCH_BACKENDS['elasticsearch'] = { 'BACKEND': 'wagtail.wagtailsearch.backends.elasticsearch', + 'URLS': [os.environ['ELASTICSEARCH_URL']], 'TIMEOUT': 10, 'max_retries': 1, 'AUTO_UPDATE': False, } - if 'ELASTICSEARCH_URL' in os.environ: - WAGTAILSEARCH_BACKENDS['elasticsearch']['URLS'] = [os.environ['ELASTICSEARCH_URL']] - -except ImportError: - pass - WAGTAIL_SITE_NAME = "Test Site"