Skip to content

Commit

Permalink
Merge pull request #157 from singnet/imp/refactor-query-validator
Browse files Browse the repository at this point in the history
Refactor validate_query()
  • Loading branch information
marcocapozzoli authored Oct 18, 2024
2 parents c3efc39 + fac1ba8 commit 6c9895c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
39 changes: 37 additions & 2 deletions das-query-engine/tests/integration/handle/test_query_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
BaseTestHandlerAction,
expression,
inheritance,
similarity,
human,
mammal,
symbol,
)
Expand Down Expand Up @@ -33,12 +35,45 @@ def valid_event(self, action_type):
},
}
}

@pytest.fixture
def query_list(self, action_type):
return {
"body": {
"action": action_type,
"input": {
"query": [
{
"atom_type": "link",
"type": expression,
"targets": [
{"atom_type": "node", "type": symbol, "name": inheritance},
{"atom_type": "variable", "name": "$v1"},
{"atom_type": "node", "type": symbol, "name": mammal},
],
},
{
"atom_type": "link",
"type": expression,
"targets": [
{"atom_type": "node", "type": symbol, "name": similarity},
{"atom_type": "variable", "name": "$v1"},
{"atom_type": "node", "type": symbol, "name": human},
],
}
]
},
}
}

@pytest.mark.parametrize("query_input", ["valid_event", "query_list"])
def test_query_action(
self,
valid_event,
request,
query_input,
):
body, status_code = self.make_request(valid_event)
query_data = request.getfixturevalue(query_input)
body, status_code = self.make_request(query_data)
expected_status_code = 200

assert (
Expand Down
3 changes: 3 additions & 0 deletions das-query-engine/validators/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class QueryValidator(PayloadValidator):

@staticmethod
def validate_query(query, *args, **kwargs) -> bool:
if isinstance(query, list):
return all([QueryValidator.validate_query(q) for q in query])

if not isinstance(query, dict):
return False

Expand Down

0 comments on commit 6c9895c

Please sign in to comment.