diff --git a/setup.py b/setup.py index ac0332ac58..5941cc1905 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,8 @@ # and https://github.com/psf/requests/pull/5651) "urllib3<1.26", "eve==1.1.2", - "eve-elastic>=7.3.2,<7.4.0", + "eve-elastic>=7.4.0,<7.5.0", + "elasticsearch<7.14", # we are using oss version on test server "flask>=1.1,<1.2", "flask-mail>=0.9,<0.10", "flask-script>=2.0.5,<3.0", diff --git a/superdesk/commands/rebuild_elastic_index.py b/superdesk/commands/rebuild_elastic_index.py index 9f21203677..03b46a0b81 100644 --- a/superdesk/commands/rebuild_elastic_index.py +++ b/superdesk/commands/rebuild_elastic_index.py @@ -10,11 +10,8 @@ import superdesk -import elasticsearch -from flask import current_app -from eve_elastic import get_es, get_indices, reindex -from superdesk.utils import get_random_string +from flask import current_app as app class RebuildElasticIndex(superdesk.Command): @@ -33,18 +30,19 @@ class RebuildElasticIndex(superdesk.Command): """ option_list = [ - superdesk.Option('--resource', '-r', dest='resource_name') + superdesk.Option('--resource', '-r', dest='resource_name'), + superdesk.Option('--requests-per-second', dest='requests_per_second'), ] - def run(self, resource_name=None): + def run(self, resource_name=None, requests_per_second=1000): # if no index name is passed then use the configured one - resources = list(current_app.data.elastic._get_elastic_resources().keys()) + resources = list(app.data.elastic._get_elastic_resources().keys()) if resource_name and resource_name in resources: resources = [resource_name] elif resource_name: raise ValueError("Resource {} is not configured".format(resource_name)) for resource in resources: - current_app.data.elastic.reindex(resource) + app.data.elastic.reindex(resource, requests_per_second=requests_per_second) print('Index {} rebuilt successfully.'.format(resource)) diff --git a/superdesk/tests/__init__.py b/superdesk/tests/__init__.py index dbd1d2d93f..6e83d8c889 100644 --- a/superdesk/tests/__init__.py +++ b/superdesk/tests/__init__.py @@ -362,8 +362,9 @@ def setup(context=None, config=None, app_factory=get_app, reset=False): if context: context.app = app context.client = app.test_client() - if not hasattr(context, "BEHAVE"): - app.test_request_context().push() + if not hasattr(context, "BEHAVE") and not hasattr(context, "test_context"): + context.test_context = app.test_request_context() + context.test_context.push() with app.app_context(): clean_dbs(app, force=bool(config))