diff --git a/tests/config/prod_client.json b/tests/config/prod_client.json new file mode 100644 index 0000000..06fc9f7 --- /dev/null +++ b/tests/config/prod_client.json @@ -0,0 +1,13 @@ +{ + + "$ref":"~/private_activedata_frontend6.json#esFrontLine", + "url_prefix": "/elasticsearch", + "debug": { + "trace": true, + "log": [ + { + "stream": "sys.stdout" + } + ] + } +} diff --git a/tests/prod_client.py b/tests/prod_client.py new file mode 100644 index 0000000..405b593 --- /dev/null +++ b/tests/prod_client.py @@ -0,0 +1,42 @@ +import json + +from elasticsearch import Elasticsearch + +from esFrontLine.connection import HawkConnection +from mo_kwargs import override +from mo_logs import startup, constants, Log + + +@override +def main(elasticsearch, users, url_prefix, kwargs): + Log.note('Will connect to esfrontline: {{url}}', url=elasticsearch) + + # Load users config + user = users[0] + Log.note('Will connect as {{user}}', user=user.hawk.id) + + # HawkConnection.url_prefix = url_prefix + es = Elasticsearch( + hosts=[elasticsearch], + connection_class=HawkConnection, + hawk_credentials=user.hawk, + url_prefix=url_prefix + ) + es.ping() + + index = user.resources[0] + Log.note("Query {{index}}", index=index) + Log.note('Count: {{result}}', result=es.count(index=index)) + response = es.search(index=user['resources'][0], body={'query': {}}) + Log.note('Query:\n{{result}}', result=response) + + +if __name__ == '__main__': + try: + settings = startup.read_settings() + constants.set(settings.constants) + Log.start(settings.debug) + + main(settings) + except Exception as e: + Log.error("problem", cause=e)