Skip to content

Commit

Permalink
Fix unit test issues
Browse files Browse the repository at this point in the history
  • Loading branch information
khaledk2 committed Feb 21, 2023
1 parent 6146d5a commit 3ef83ee
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 28 deletions.
7 changes: 4 additions & 3 deletions omero_search_engine/validation/psql_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
17 changes: 7 additions & 10 deletions omero_search_engine/validation/results_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand Down Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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:
Expand Down
29 changes: 14 additions & 15 deletions unit_tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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

Expand All @@ -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:
Expand All @@ -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")
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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")
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit 3ef83ee

Please sign in to comment.