From 90da7aa5028d64437f3fcaf903075cbda293b575 Mon Sep 17 00:00:00 2001 From: Muriithi Frederick Muriuki Date: Fri, 13 Apr 2018 15:39:47 +0300 Subject: Fix logging in tests * Use the LOG_LEVEL provided by the application settings to enable easy control of logging when running tests. It helps avoid a lot of verbosity when running tests. --- test/requests/parametrized_test.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test/requests/parametrized_test.py') diff --git a/test/requests/parametrized_test.py b/test/requests/parametrized_test.py index abf98fce..c585e910 100644 --- a/test/requests/parametrized_test.py +++ b/test/requests/parametrized_test.py @@ -1,5 +1,6 @@ import logging import unittest +from wqflask import app from elasticsearch import Elasticsearch, TransportError class ParametrizedTest(unittest.TestCase): @@ -14,6 +15,7 @@ class ParametrizedTest(unittest.TestCase): self.es_cleanup = [] es_logger = logging.getLogger("elasticsearch") + es_logger.setLevel(app.config.get("LOG_LEVEL")) es_logger.addHandler( logging.FileHandler("/tmp/es_TestRegistrationInfo.log")) es_trace_logger = logging.getLogger("elasticsearch.trace") -- cgit v1.2.3 From e3e98b0533460837c4ea2eac67c4281eb0ba0012 Mon Sep 17 00:00:00 2001 From: Muriithi Frederick Muriuki Date: Sun, 15 Apr 2018 11:48:06 +0300 Subject: Use existing code. Delay after delete. * Use existing code to get the elasticsearch connection. This should prevent tests from failing in case the way connections to elasticsearch are made change. * Delay a while after deleting to allow elasticsearch to re-index the data, thus preventing subtle bugs in the test. --- test/requests/parametrized_test.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'test/requests/parametrized_test.py') diff --git a/test/requests/parametrized_test.py b/test/requests/parametrized_test.py index c585e910..50003850 100644 --- a/test/requests/parametrized_test.py +++ b/test/requests/parametrized_test.py @@ -1,6 +1,7 @@ import logging import unittest from wqflask import app +from utility.elasticsearch_tools import get_elasticsearch_connection, get_user_by_unique_column from elasticsearch import Elasticsearch, TransportError class ParametrizedTest(unittest.TestCase): @@ -11,7 +12,7 @@ class ParametrizedTest(unittest.TestCase): self.es_url = es_url def setUp(self): - self.es = Elasticsearch([self.es_url]) + self.es = get_elasticsearch_connection() self.es_cleanup = [] es_logger = logging.getLogger("elasticsearch") @@ -23,7 +24,9 @@ class ParametrizedTest(unittest.TestCase): logging.FileHandler("/tmp/es_TestRegistrationTrace.log")) def tearDown(self): + from time import sleep self.es.delete_by_query( index="users" , doc_type="local" , body={"query":{"match":{"email_address":"test@user.com"}}}) + sleep(1) -- cgit v1.2.3