From 3ef83eebe2400e066399c9fd9960afffa75eb4b5 Mon Sep 17 00:00:00 2001 From: khaledk2 Date: Tue, 21 Feb 2023 00:30:18 +0000 Subject: [PATCH] Fix unit test issues --- .../validation/psql_templates.py | 7 +++-- .../validation/results_validator.py | 17 +++++------ unit_tests/test_app.py | 29 +++++++++---------- 3 files changed, 25 insertions(+), 28 deletions(-) diff --git a/omero_search_engine/validation/psql_templates.py b/omero_search_engine/validation/psql_templates.py index 84b7f583..807076d1 100644 --- a/omero_search_engine/validation/psql_templates.py +++ b/omero_search_engine/validation/psql_templates.py @@ -44,7 +44,7 @@ def substitute(self, **kwargs): # get aviable values for an image key query_images_aviable_values_for_key = Template( """ -Select DISTINCT annotation_mapvalue.value from image +Select DISTINCT lower(annotation_mapvalue.value) from image inner join imageannotationlink on image.id =imageannotationlink.parent inner join annotation_mapvalue on annotation_mapvalue.annotation_id=imageannotationlink.child @@ -54,7 +54,8 @@ def substitute(self, **kwargs): # get any values for an image keys query_images_any_value = Template( """ -Select DISTINCT annotation_mapvalue.name, annotation_mapvalue.value from image +Select DISTINCT lower(annotation_mapvalue.name), +lower(annotation_mapvalue.value) from image inner join imageannotationlink on image.id =imageannotationlink.parent inner join annotation_mapvalue on annotation_mapvalue.annotation_id=imageannotationlink.child @@ -64,7 +65,7 @@ def substitute(self, **kwargs): # get any values for an image keys query_images_contians_not_contains = Template( """ -Select DISTINCT image.id, annotation_mapvalue.name, annotation_mapvalue.value from image +Select DISTINCT image.id from image inner join imageannotationlink on image.id =imageannotationlink.parent inner join annotation_mapvalue on annotation_mapvalue.annotation_id=imageannotationlink.child diff --git a/omero_search_engine/validation/results_validator.py b/omero_search_engine/validation/results_validator.py index 56d92c65..2eca8f50 100644 --- a/omero_search_engine/validation/results_validator.py +++ b/omero_search_engine/validation/results_validator.py @@ -160,7 +160,7 @@ def get_or_sql(self, clauses, name="query_image_or"): postgres_results = conn.execute_query(sql) results = [item["id"] for item in postgres_results] search_omero_app.logger.info( - "results for or received %s" % len(results) + "results for 'or' received %s" % len(results) ) # noqa return results @@ -177,9 +177,7 @@ def get_and_sql(self, clauses): conn = search_omero_app.config["database_connector"] postgres_results = conn.execute_query(sql) res = [item["id"] for item in postgres_results] - search_omero_app.logger.info( - "results for and received recived %s" % len(res) - ) + search_omero_app.logger.info("results for 'and' received %s" % len(res)) if co == 0: results = res else: @@ -743,7 +741,6 @@ def test_no_images(): headers = lines[0] headers = headers.split("\t") - print(len(headers)) for i in range(len(headers) - 1): print(i, headers[i]) names = {} @@ -935,11 +932,11 @@ def check_no_images_sql_containers_using_ids(): ) if seachengine_results != postgres_results: if res_name == "idr0021" and res_id == 872: - """ - issue with these two images: - #imag id= 9552 - #image id= 9539 - """ + # """ + # issue with these two images: + # as they belongo two differnet data sets + # image ids= 9539, 9552 + # """ continue dd = False if seachengine_results > 0: diff --git a/unit_tests/test_app.py b/unit_tests/test_app.py index 234b388f..403fc800 100644 --- a/unit_tests/test_app.py +++ b/unit_tests/test_app.py @@ -66,6 +66,8 @@ from omero_search_engine import search_omero_app, create_app create_app("testing") +# deep_check should be a configuration item +deep_check = True class BasicTestCase(unittest.TestCase): @@ -146,8 +148,6 @@ def test_add_submit_query_delete_es_index(self): es_index_2 = "key_values_resource_cach" create_es_index_2 = True all_all_indices = get_all_indexes_from_elasticsearch() - print(all_all_indices) - print(all_all_indices.keys()) if es_index_2 in all_all_indices.keys(): create_es_index_2 = False @@ -158,7 +158,6 @@ def test_add_submit_query_delete_es_index(self): create_index(es_index_2, key_values_resource_cache_template) ) res = search_resource_annotation(table, query) - print(res) assert len(res.get("results")) >= 0 self.assertTrue(delete_es_index(es_index)) if create_es_index_2: @@ -173,7 +172,7 @@ def test_single_query(self): for case in cases: name = case[0] value = case[1] - validator = Validator(True) + validator = Validator(deep_check) validator.set_simple_query(resource, name, value) validator.get_results_postgres("equals") validator.get_results_searchengine("equals") @@ -192,7 +191,7 @@ def test_single_query(self): def test_and_query(self): name = "query_image_and" for cases in query_image_and: - validator = Validator(True) + validator = Validator(deep_check) validator.set_complex_query(name, cases) validator.compare_results() self.assertEqual( @@ -204,7 +203,7 @@ def test_and_query(self): def test_or_query(self): name = "query_image_or" for cases in query_image_or: - validator = Validator(True) + validator = Validator(deep_check) validator.set_complex_query(name, cases) validator.compare_results() self.assertEqual( @@ -223,7 +222,7 @@ def test_multi_or_quries(self): def test_complex_query(self): name = "query_image_and_or" for cases in query_image_and_or: - validator = Validator(True) + validator = Validator(deep_check) validator.set_complex_query(name, cases) validator.compare_results() self.assertEqual( @@ -235,7 +234,7 @@ def test_complex_query(self): def test_in_query(self): for resource, cases in query_in.items(): for case in cases: - validator = Validator(True) + validator = Validator(deep_check) validator.set_in_query(case, resource) validator.compare_results() self.assertEqual( @@ -247,7 +246,7 @@ def test_in_query(self): def test_not_in_query(self): for resource, cases in query_in.items(): for case in cases: - validator = Validator(True) + validator = Validator(deep_check) validator.set_in_query(case, resource, type="not_in_clause") validator.compare_results() self.assertEqual( @@ -258,7 +257,7 @@ def test_not_in_query(self): def test_seach_for_any_value(self): for part in images_value_parts: - validator = Validator() + validator = Validator(deep_check) validator.set_simple_query("image", None, part, type="buckets") validator.compare_results() self.assertEqual( @@ -268,7 +267,7 @@ def test_seach_for_any_value(self): def test_available_values_for_key(self): for image_key in images_keys: - validator = Validator() + validator = Validator(deep_check) validator.set_simple_query("image", image_key, None, type="buckets") validator.compare_results() self.assertEqual( @@ -281,7 +280,7 @@ def test_contains_not_contains_quries(self): for case in cases: name = case[0] value = case[1] - validator = Validator(True) + validator = Validator(deep_check) validator.set_conatins_not_contains_query(resource, name, value) validator.get_results_postgres("contains") validator.get_results_searchengine("contains") @@ -303,7 +302,7 @@ def test_owner(self): name = case[0] value = case[1] owner_id = case[2] - validator = Validator(True) + validator = Validator(deep_check) validator.set_simple_query(resource, name, value) validator.set_owner_group(owner_id=owner_id) validator.compare_results() @@ -318,7 +317,7 @@ def test_group(self): name = case[0] value = case[1] group_id = case[2] - validator = Validator(True) + validator = Validator(deep_check) validator.set_simple_query(resource, name, value) validator.set_owner_group(group_id=group_id) validator.compare_results() @@ -334,7 +333,7 @@ def test_owner_group(self): value = case[1] owner_id = case[2] group_id = case[3] - validator = Validator(True) + validator = Validator(deep_check) validator.set_simple_query(resource, name, value) validator.set_owner_group(owner_id=owner_id, group_id=group_id) validator.compare_results()