Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor validate_query() #157

Merged
merged 4 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Success are good an all for testing, but testing the invalid paths are very important as well.
If so, you would've caught the return True inside the for.

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