Add tests for the retrieval queries

This commit is contained in:
gvolfing 2023-11-28 13:34:21 +01:00
parent ac0c4193b0
commit b74aee186e
6 changed files with 207 additions and 0 deletions

View File

@ -48,6 +48,7 @@ add_subdirectory(temporal_types)
add_subdirectory(write_procedures)
add_subdirectory(configuration)
add_subdirectory(magic_functions)
add_subdirectory(metadata_queries)
add_subdirectory(module_file_manager)
add_subdirectory(monitoring_server)
add_subdirectory(lba_procedures)

View File

@ -0,0 +1,7 @@
function(copy_metadata_queries_e2e_python_files FILE_NAME)
copy_e2e_python_files(metadata_queries ${FILE_NAME})
endfunction()
copy_metadata_queries_e2e_python_files(common.py)
copy_metadata_queries_e2e_python_files(show_node_labels_info.py)
copy_metadata_queries_e2e_python_files(show_edge_types_info.py)

View File

@ -0,0 +1,34 @@
# Copyright 2023 Memgraph Ltd.
#
# Use of this software is governed by the Business Source License
# included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
# License, and you may not use this file except in compliance with the Business Source License.
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0, included in the file
# licenses/APL.txt.
import typing
import mgclient
import pytest
@pytest.fixture(scope="module")
def cursor(**kwargs) -> mgclient.Connection:
connection = mgclient.connect(host="localhost", port=7687, **kwargs)
connection.autocommit = True
return connection.cursor()
def execute_and_fetch_all(cursor: mgclient.Cursor, query: str, params: dict = dict()) -> typing.List[tuple]:
cursor.execute(query, params)
return cursor.fetchall()
def are_results_equal(result1, result2):
if len(result1) != len(result2):
return False
return sorted(result1) == sorted(result2)

View File

@ -0,0 +1,80 @@
# Copyright 2023 Memgraph Ltd.
#
# Use of this software is governed by the Business Source License
# included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
# License, and you may not use this file except in compliance with the Business Source License.
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0, included in the file
# licenses/APL.txt.
import sys
import pytest
from common import are_results_equal, cursor, execute_and_fetch_all
# Helper functions
def create_nodes(cursor):
execute_and_fetch_all(
cursor, "CREATE (charlie:Person:Actor {name: 'Charlie Sheen'}), (oliver:Person:Director {name: 'Oliver Stone'})"
)
def create_edges(cursor):
execute_and_fetch_all(
cursor,
"MATCH (charlie:Person {name: 'Charlie Sheen'}), (oliver:Person {name: 'Oliver Stone'}) CREATE (charlie)-[:ACTED_IN {role: 'Bud Fox'}]->(wallStreet:Movie {title: 'Wall Street'})<-[:DIRECTED]-(oliver)",
)
def edge_types_info(cursor):
return execute_and_fetch_all(cursor, "SHOW EDGE_TYPES INFO")
def default_expected_result(cursor):
return [("DIRECTED",), ("ACTED_IN",)]
# Tests
def test_return_empty(cursor):
create_nodes(cursor)
edge_types = edge_types_info(cursor)
expected = []
assert are_results_equal(expected, edge_types)
def test_return_edge_types_simple(cursor):
create_nodes(cursor)
create_edges(cursor)
edge_types = edge_types_info(cursor)
expected = default_expected_result(cursor)
assert are_results_equal(expected, edge_types)
def test_return_edge_types_repeating_identical_edges(cursor):
create_nodes(cursor)
for _ in range(100):
create_edges(cursor)
edge_types = edge_types_info(cursor)
expected = default_expected_result(cursor)
assert are_results_equal(expected, edge_types)
def test_return_edge_types_obtainable_after_edge_deletion(cursor):
create_nodes(cursor)
create_edges(cursor)
execute_and_fetch_all(cursor, "MATCH(n) DETACH DELETE n")
edge_types = edge_types_info(cursor)
expected = default_expected_result(cursor)
assert are_results_equal(expected, edge_types)
if __name__ == "__main__":
sys.exit(pytest.main([__file__, "-rA"]))

View File

@ -0,0 +1,67 @@
# Copyright 2023 Memgraph Ltd.
#
# Use of this software is governed by the Business Source License
# included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
# License, and you may not use this file except in compliance with the Business Source License.
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0, included in the file
# licenses/APL.txt.
import sys
import pytest
from common import are_results_equal, cursor, execute_and_fetch_all
# Helper functions
def create_nodes(cursor):
execute_and_fetch_all(
cursor, "CREATE (charlie:Person:Actor {name: 'Charlie Sheen'}), (oliver:Person:Director {name: 'Oliver Stone'})"
)
def node_labels_info(cursor):
return execute_and_fetch_all(cursor, "SHOW NODE_LABELS INFO")
def default_expected_result(cursor):
return [("Person",), ("Actor",), ("Director",)]
# Tests
def test_return_empty(cursor):
node_labels = node_labels_info(cursor)
expected = []
assert are_results_equal(expected, node_labels)
def test_return_node_labels_simple(cursor):
create_nodes(cursor)
node_labels = node_labels_info(cursor)
expected = default_expected_result(cursor)
assert are_results_equal(expected, node_labels)
def test_return_node_labels_repeating_identical_labels(cursor):
for _ in range(100):
create_nodes(cursor)
node_labels = node_labels_info(cursor)
expected = default_expected_result(cursor)
assert are_results_equal(expected, node_labels)
def test_return_node_labels_obtainable_after_vertex_deletion(cursor):
create_nodes(cursor)
execute_and_fetch_all(cursor, "MATCH(n) DELETE n")
node_labels = node_labels_info(cursor)
expected = default_expected_result(cursor)
assert are_results_equal(expected, node_labels)
if __name__ == "__main__":
sys.exit(pytest.main([__file__, "-rA"]))

View File

@ -0,0 +1,18 @@
metadata_queries: &metadata_queries
cluster:
main:
args: ["--bolt-port", "7687", "--log-level=TRACE", "--also-log-to-stderr", "--storage-enable-schema-metadata=TRUE"]
log_file: "metadata-queries.log"
setup_queries: []
validation_queries: []
workloads:
- name: "Show edge types info"
binary: "tests/e2e/pytest_runner.sh"
args: ["metadata_queries/show_edge_types_info.py"]
<<: *metadata_queries
- name: "Show node labels info"
binary: "tests/e2e/pytest_runner.sh"
args: ["metadata_queries/show_node_labels_info.py"]
<<: *metadata_queries