Skip to content

Commit

Permalink
refactor: change SearchAPIQuery attribute name for better readability
Browse files Browse the repository at this point in the history
  • Loading branch information
MRichards99 committed Dec 20, 2021
1 parent 33e92e7 commit 5f2c2be
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 18 deletions.
16 changes: 7 additions & 9 deletions datagateway_api/src/search_api/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ def apply_filter(self, query):
# code written in `PythonICATWhereFilter.apply_filter()`
self.field = ".".join(icat_field_names)

# TODO - `query.query.query` might be confusing, might rename `query` in
# function signature
return super().apply_filter(query.query.query)
return super().apply_filter(query.icat_query.query)

def get_icat_mapping(self, panosc_entity_name, field_name):
"""
Expand Down Expand Up @@ -113,12 +111,12 @@ def __str__(self):
# Replicating the condition in Python ICAT format so it can be searched on
# the query and return as string representation
conds_dict = self.create_filter()
a, jpql_func = query.query.query._split_db_functs(self.field)
conds_dict[self.field] = query.query.query._cond_value(
a, jpql_func = query.icat_query.query._split_db_functs(self.field)
conds_dict[self.field] = query.icat_query.query._cond_value(
conds_dict[self.field], jpql_func,
)

str_conds = query.query.query.search_conditions(self.field, conds_dict)
str_conds = query.icat_query.query.search_conditions(self.field, conds_dict)

try:
return str_conds[0]
Expand All @@ -139,20 +137,20 @@ def __init__(self, skip_value):
super().__init__(skip_value, filter_use="search_api")

def apply_filter(self, query):
return super().apply_filter(query.query.query)
return super().apply_filter(query.icat_query.query)


class SearchAPILimitFilter(PythonICATLimitFilter):
def __init__(self, limit_value):
super().__init__(limit_value)

def apply_filter(self, query):
return super().apply_filter(query.query.query)
return super().apply_filter(query.icat_query.query)


class SearchAPIIncludeFilter(PythonICATIncludeFilter):
def __init__(self, included_filters):
super().__init__(included_filters)

def apply_filter(self, query):
return super().apply_filter(query.query.query)
return super().apply_filter(query.icat_query.query)
2 changes: 1 addition & 1 deletion datagateway_api/src/search_api/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def get_search(endpoint_name, entity_name, filters=list()):
filter_handler.add_query_to_where_filters(query)
filter_handler.apply_filters(query)

log.debug("Python ICAT Query: %s", query.query.query)
log.debug("Python ICAT Query: %s", query.icat_query.query)
# TODO - `getApiVersion()` used as a placeholder for testing client handling
# Replace with endpoint functionality when implementing the endpoints
return SessionHandler.client.getApiVersion()
Expand Down
2 changes: 1 addition & 1 deletion datagateway_api/src/search_api/nested_where_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self, lhs, rhs, joining_operator, search_api_query=None):
NestedWhereFilters.set_search_api_query(self, search_api_query)

def apply_filter(self, query):
query.query.query.setConditionsByString(str(self))
query.icat_query.query.setConditionsByString(str(self))

@staticmethod
def set_search_api_query(query_filter, search_api_query):
Expand Down
2 changes: 1 addition & 1 deletion datagateway_api/src/search_api/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ def __init__(self, panosc_entity_name):
"base_icat_entity"
]

self.query = ICATQuery(SessionHandler.client, self.icat_entity_name)
self.icat_query = ICATQuery(SessionHandler.client, self.icat_entity_name)
2 changes: 1 addition & 1 deletion test/search_api/filters/test_search_api_limit_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_valid_limit_value(self, limit_value):
test_query = SearchAPIQuery("Document")
test_filter.apply_filter(test_query)

assert test_query.query.query.limit == (0, limit_value)
assert test_query.icat_query.query.limit == (0, limit_value)

@pytest.mark.parametrize(
"limit_value",
Expand Down
2 changes: 1 addition & 1 deletion test/search_api/filters/test_search_api_skip_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_valid_skip_value(self, icat_query, skip_value):
test_query = SearchAPIQuery("Document")
test_filter.apply_filter(test_query)

assert test_query.query.query.limit == (
assert test_query.icat_query.query.limit == (
skip_value,
get_icat_properties(
Config.config.search_api.icat_url,
Expand Down
8 changes: 4 additions & 4 deletions test/search_api/filters/test_search_api_where_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ def test_valid_apply_where_filter(self, filter_input, entity_name, expected_quer

filter_handler.apply_filters(test_query)

print(f"JPQL Query: {str(test_query.query.query)}")
print(f"JPQL Query: {str(test_query.icat_query.query)}")

assert expected_query == str(test_query.query.query)
assert expected_query == str(test_query.icat_query.query)

@pytest.mark.parametrize(
"filter_input, entity_name, expected_query",
Expand Down Expand Up @@ -194,6 +194,6 @@ def test_valid_apply_nested_filters(

filter_handler.apply_filters(test_query)

print(f"JPQL Query: {str(test_query.query.query)}")
print(f"JPQL Query: {str(test_query.icat_query.query)}")

assert str(test_query.query.query) == expected_query
assert str(test_query.icat_query.query) == expected_query

0 comments on commit 5f2c2be

Please sign in to comment.