diff --git a/VERSION b/VERSION index 227cea2..359a5b9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.0.0 +2.0.0 \ No newline at end of file diff --git a/src/ensembl/production/datacheck/app/main.py b/src/ensembl/production/datacheck/app/main.py index b250136..c935f31 100644 --- a/src/ensembl/production/datacheck/app/main.py +++ b/src/ensembl/production/datacheck/app/main.py @@ -66,7 +66,6 @@ es_user = app.config['ES_USER'] es_password = app.config['ES_PASSWORD'] es_ssl = app.config['ES_SSL'] - app_es_data_source = app.config['APP_ES_DATA_SOURCE'] if app.env == 'development': @@ -343,7 +342,6 @@ def job_details(): jsonfile = request.args.get('jsonfile', None) if jsonfile is None: raise Exception('jsonfile needed ') - if app_es_data_source: ensembl_division = f"Ensembl{DatacheckConfig.DATACHECK_TYPE.capitalize()}" res = get_datacheck_results(division=ensembl_division, @@ -361,7 +359,7 @@ def job_details(): file_data = open(jsonfile, 'r').read() return jsonify(json.loads(file_data)) except Exception as e: - return jsonify({'error': f"Failed to retrive the details : {str(e)}"}), 404 + return jsonify({'error': f"Failed to retrieve the details : {str(e)}"}), 404 @app.route('/jobs/', methods=['GET']) diff --git a/src/ensembl/production/datacheck/config.py b/src/ensembl/production/datacheck/config.py index 15b9d64..bb473b8 100644 --- a/src/ensembl/production/datacheck/config.py +++ b/src/ensembl/production/datacheck/config.py @@ -35,7 +35,8 @@ def get_app_version(): try: - version = pkg_resources.require("datacheck")[0].version + from importlib.metadata import version + version = version("datacheck") except Exception as e: with open(Path(__file__).parents[4] / 'VERSION') as f: version = f.read() @@ -126,11 +127,11 @@ class DatacheckConfig(EnsemblConfig): APP_ES_DATA_SOURCE = os.environ.get('APP_ES_DATA_SOURCE', EnsemblConfig.file_config.get('app_es_data_source', True)) ES_HOST = os.environ.get('ES_HOST', EnsemblConfig.file_config.get('es_host', 'localhost')) - ES_USER = os.getenv("ES_USER", EnsemblConfig.file_config.get("es_user", "elastic")), - ES_PASSWORD = os.getenv("ES_PASSWORD", EnsemblConfig.file_config.get("es_password", "password")), + ES_USER = "" # os.getenv("ES_USER", EnsemblConfig.file_config.get("es_user", "")), + ES_PASSWORD = "" # os.getenv("ES_PASSWORD", EnsemblConfig.file_config.get("es_password", "")), ES_PORT = os.environ.get('ES_PORT', EnsemblConfig.file_config.get('es_port', '9200')) ES_SSL = os.environ.get('ES_SSL', EnsemblConfig.file_config.get('es_ssl', "f")).lower() in ['true', '1'] - ES_INDEX = os.environ.get('ES_INDEX', EnsemblConfig.file_config.get('es_index', f"datacheck_results_{EnsemblConfig.ENS_VERSION}")) + ES_INDEX = os.environ.get('ES_INDEX', EnsemblConfig.file_config.get('es_index', "datacheck_results")) GET_SERVER_NAMES = os.environ.get('GET_SERVER_NAMES', EnsemblConfig.file_config.get('get_server_names', 0)) diff --git a/src/tests/conftest.py b/src/tests/conftest.py index d7ee044..fc233d5 100644 --- a/src/tests/conftest.py +++ b/src/tests/conftest.py @@ -101,24 +101,25 @@ def wait_for(url: str, retries: int = 2, backoff: float = 0.2): @pytest.fixture(scope="session") def elastic_search(): wait_for(f"http://localhost:9200/") - es = Elasticsearch([{"host": "localhost", "port": 9200}]) - print(es.info()) - if not es.ping(): - raise( - f"Cannot connect to Elasticsearch server. Host: localhost, Port: 9200" - ) - def search(body: dict) -> None: - es.indices.flush() - es.indices.refresh() - return es.search(index="datacheck_results", body=body) - try: - #set mock es data - es.index(index="datacheck_results", body=dc_success_result_es_doc, doc_type="report") - es.index(index="datacheck_results", body=dc_failed_result_es_doc, doc_type="report") - yield search - finally: - if es.indices.exists("datacheck_results"): - es.indices.delete("datacheck_results") + with ElasticsearchConnectionManager("localhost", "9200", "", "", False) as es_client: + es = es_client.client + print("EsInfo", es.info()) + def search(body: dict) -> None: + es.indices.flush() + es.indices.refresh() + return es.search(index="datacheck_results", body=body) + + try: + #set mock es data + es.index(index="datacheck_results", body=dc_success_result_es_doc, doc_type="report") + es.index(index="datacheck_results", body=dc_failed_result_es_doc, doc_type="report") + print("Index created") + yield search + except: + raise RuntimeWarning("Unable to create indexes!") + finally: + if es.indices.exists("datacheck_results"): + es.indices.delete("datacheck_results") @pytest.fixture() def es_query(): diff --git a/src/tests/test_config_loader.py b/src/tests/test_config_loader.py index b5a2f2c..dc2b011 100644 --- a/src/tests/test_config_loader.py +++ b/src/tests/test_config_loader.py @@ -36,12 +36,17 @@ def test_config_load_fallback(self): class TestAPPVersion(unittest.TestCase): def test_config_app_version(self): - + try: + from importlib.metadata import version + version = version("datacheck") + version_pkg = True + except Exception as e: + version = "unknown" + version_pkg = False with open(Path(__file__).parent.parent.parent / 'VERSION') as f: version_file = f.read().strip('\n') - - version = pkg_resources.require("datacheck")[0].version version_config = DatacheckConfig.APP_VERSION - self.assertEqual(version, version_config) - self.assertEqual(version, version_file) + if version_pkg : + self.assertEqual(version, version_config) + self.assertEqual(version, version_file) self.assertEqual(version_file, version_config ) diff --git a/src/tests/test_dc_results_from_es.py b/src/tests/test_dc_results_from_es.py index 67b8b60..4a501cd 100644 --- a/src/tests/test_dc_results_from_es.py +++ b/src/tests/test_dc_results_from_es.py @@ -8,13 +8,12 @@ def test_without_jsonfile_param(appclient): response = appclient.get('/jobs/details') data = json.loads(response.data) assert response.status_code == 404 - assert data['error'] == 'Failed to retrive the details : jsonfile needed ' + assert data['error'] == 'Failed to retrieve the details : jsonfile needed ' def test_get_dc_results_success(appclient, elastic_search, es_query): elastic_search(es_query) response = appclient.get('/jobs/details?jsonfile=/homes/user/test_es_output/user_sL2nmrNTRkjE/results_by_species.json') data = json.loads(response.data) - print(response.data) assert response.status_code == 200 assert data == {} @@ -22,7 +21,6 @@ def test_get_dc_results_failed(appclient, elastic_search, es_query): elastic_search(es_query) response = appclient.get('/jobs/details?jsonfile=/homes/user/test_es_output/user_sL3mnrNTRrr1/results_by_species.json') data = json.loads(response.data) - print(response.data) assert response.status_code == 200 assert len(data.keys()) == 2