Fill out tests

This commit is contained in:
Ante Pušić 2024-01-22 13:45:59 +01:00
parent c7be58e1dc
commit 04410d242b
2 changed files with 36 additions and 32 deletions

View File

@ -26,12 +26,12 @@ def connect(**kwargs) -> mgclient.Connection:
connection = mgclient.connect(host="localhost", port=7687, **kwargs)
connection.autocommit = True
cursor = connection.cursor()
execute_and_fetch_all(cursor, "USE DATABASE memgraph")
execute_and_fetch_all(cursor, """USE DATABASE memgraph""")
try:
execute_and_fetch_all(cursor, "DROP DATABASE clean")
execute_and_fetch_all(cursor, """DROP DATABASE clean""")
except:
pass
execute_and_fetch_all(cursor, "MATCH (n) DETACH DELETE n")
execute_and_fetch_all(cursor, """MATCH (n) DETACH DELETE n""")
yield connection
@ -50,16 +50,17 @@ def memgraph_with_text_indexed_data(**kwargs) -> Memgraph:
memgraph = Memgraph()
memgraph.execute(
"CREATE (:Document {title: 'Rules2024', version: 1, date: date('2023-11-14'), contents: 'Lorem ipsum dolor sit amet'});"
"""CREATE (:Document {title: "Rules2024", version: 1, fulltext: "random fulltext", date: date("2023-11-14")});"""
)
memgraph.execute(
"CREATE (:Document:Revision {title: 'Rules2024', version: 2, date: date('2023-12-15'), contents: 'consectetur adipiscing elit'});"
"""CREATE (:Document:Revision {title: "Rules2024", version: 2, fulltext: "random words", date: date("2023-12-15")});"""
)
memgraph.execute("CREATE TEXT INDEX complianceDocuments ON :Document;")
memgraph.execute("""CREATE (:Revision {title: "OperationSchema", version: 3, date: date("2023-10-01")});""")
memgraph.execute("""CREATE TEXT INDEX complianceDocuments ON :Document;""")
yield memgraph
memgraph.execute("DROP TEXT INDEX complianceDocuments;")
memgraph.execute("""DROP TEXT INDEX complianceDocuments;""")
memgraph.drop_database()
memgraph.drop_indexes()
@ -69,15 +70,15 @@ def memgraph_with_mixed_data(**kwargs) -> Memgraph:
memgraph = Memgraph()
memgraph.execute(
"CREATE (:Document:Revision {title: 'Rules2024', version: 1, date: date('2023-11-14'), contents: 'Lorem ipsum dolor sit amet'});"
"""CREATE (:Document:Revision {title: "Rules2024", version: 1, date: date("2023-11-14"), contents: "Lorem ipsum dolor sit amet"});"""
)
memgraph.execute(
"CREATE (:Revision {title: 'Rules2024', version: 2, date: date('2023-12-15'), contents: 'consectetur adipiscing elit'});"
"""CREATE (:Revision {title: "Rules2024", version: 2, date: date("2023-12-15"), contents: "consectetur adipiscing elit"});"""
)
memgraph.execute("CREATE TEXT INDEX complianceDocuments ON :Document;")
memgraph.execute("""CREATE TEXT INDEX complianceDocuments ON :Document;""")
yield memgraph
memgraph.execute("DROP TEXT INDEX complianceDocuments;")
memgraph.execute("""DROP TEXT INDEX complianceDocuments;""")
memgraph.drop_database()
memgraph.drop_indexes()

View File

@ -15,23 +15,23 @@ import pytest
from common import memgraph, memgraph_with_mixed_data, memgraph_with_text_indexed_data
from gqlalchemy.exceptions import GQLAlchemyDatabaseError
GET_RULES_2024_DOCUMENT = """CALL text_search.search('complianceDocuments', 'data.title:Rules2024') YIELD node
GET_RULES_2024_DOCUMENT = """CALL text_search.search("complianceDocuments", "data.title:Rules2024") YIELD node
RETURN node.title AS title, node.version AS version
ORDER BY version ASC, title ASC;"""
def test_create_index(memgraph):
memgraph.execute("CREATE TEXT INDEX exampleIndex ON :Document;")
memgraph.execute("""CREATE TEXT INDEX exampleIndex ON :Document;""")
index_info = memgraph.execute_and_fetch("SHOW INDEX INFO")
index_info = memgraph.execute_and_fetch("""SHOW INDEX INFO""")
assert list(index_info) == [{"index type": "text", "label": "exampleIndex", "property": None, "count": None}]
def test_drop_index(memgraph):
memgraph.execute("DROP TEXT INDEX exampleIndex;")
memgraph.execute("""DROP TEXT INDEX exampleIndex;""")
index_info = memgraph.execute_and_fetch("SHOW INDEX INFO")
index_info = memgraph.execute_and_fetch("""SHOW INDEX INFO""")
assert list(index_info) == []
@ -42,18 +42,18 @@ def test_text_search_given_property(memgraph_with_text_indexed_data):
assert len(result) == 2 and result == [{"title": "Rules2024", "version": 1}, {"title": "Rules2024", "version": 2}]
# def test_text_search_query_boolean(memgraph_with_text_indexed_data):
# BOOLEAN_QUERY = """CALL text_search.search('complianceDocuments', '(data.title:Rules2023 OR data.title:Rules2024) AND data.contents:consectetur') YIELD node
# RETURN node.title AS title, node.version AS version
# ORDER BY version ASC, title ASC;"""
def test_text_search_query_boolean(memgraph_with_text_indexed_data):
BOOLEAN_QUERY = """CALL text_search.search("complianceDocuments", "(data.title:Rules2023 OR data.title:Rules2024) AND data.fulltext:words") YIELD node
RETURN node.title AS title, node.version AS version
ORDER BY version ASC, title ASC;"""
# result = list(memgraph_with_text_indexed_data.execute_and_fetch(BOOLEAN_QUERY))
result = list(memgraph_with_text_indexed_data.execute_and_fetch(BOOLEAN_QUERY))
# assert len(result) == 1 and result == [{"title": "Rules2024", "version": 2}]
assert len(result) == 1 and result == [{"title": "Rules2024", "version": 2}]
def test_create_indexed_node(memgraph_with_text_indexed_data):
memgraph_with_text_indexed_data.execute("CREATE (:Document {title: 'Rules2024', version: 3});")
memgraph_with_text_indexed_data.execute("""CREATE (:Document {title: "Rules2024", version: 3});""")
result = list(memgraph_with_text_indexed_data.execute_and_fetch(GET_RULES_2024_DOCUMENT))
@ -65,7 +65,7 @@ def test_create_indexed_node(memgraph_with_text_indexed_data):
def test_delete_indexed_node(memgraph_with_text_indexed_data):
memgraph_with_text_indexed_data.execute("MATCH (n:Document {title: 'Rules2024', version: 2}) DETACH DELETE n;")
memgraph_with_text_indexed_data.execute("""MATCH (n:Document {title: "Rules2024", version: 2}) DETACH DELETE n;""")
result = list(memgraph_with_text_indexed_data.execute_and_fetch(GET_RULES_2024_DOCUMENT))
@ -73,8 +73,7 @@ def test_delete_indexed_node(memgraph_with_text_indexed_data):
def test_add_indexed_label(memgraph_with_mixed_data):
# flaky search results
memgraph_with_mixed_data.execute("MATCH (n:Revision) SET n:Document;")
memgraph_with_mixed_data.execute("""MATCH (n:Revision {version:3}) SET n:Document;""")
result = list(memgraph_with_mixed_data.execute_and_fetch(GET_RULES_2024_DOCUMENT))
@ -82,7 +81,7 @@ def test_add_indexed_label(memgraph_with_mixed_data):
def test_remove_indexed_label(memgraph_with_mixed_data):
memgraph_with_mixed_data.execute("MATCH (n:Document {version: 1}) REMOVE n:Document;")
memgraph_with_mixed_data.execute("""MATCH (n:Document {version: 1}) REMOVE n:Document;""")
result = list(memgraph_with_mixed_data.execute_and_fetch(GET_RULES_2024_DOCUMENT))
@ -90,11 +89,11 @@ def test_remove_indexed_label(memgraph_with_mixed_data):
def test_update_text_property_of_indexed_node(memgraph_with_text_indexed_data):
memgraph_with_text_indexed_data.execute("MATCH (n:Document {version:1}) SET n.title = 'Rules2030';")
memgraph_with_text_indexed_data.execute("""MATCH (n:Document {version:1}) SET n.title = "Rules2030";""")
result = list(
memgraph_with_text_indexed_data.execute_and_fetch(
"""CALL text_search.search('complianceDocuments', 'data.title:Rules2030') YIELD node
"""CALL text_search.search("complianceDocuments", "data.title:Rules2030") YIELD node
RETURN node.title AS title, node.version AS version
ORDER BY version ASC, title ASC;"""
)
@ -104,16 +103,20 @@ def test_update_text_property_of_indexed_node(memgraph_with_text_indexed_data):
def test_add_non_text_property_to_indexed_node(memgraph_with_text_indexed_data):
memgraph_with_text_indexed_data.execute("MATCH (n:Document {version:1}) SET n.randomList = [2, 3, 4, 5];")
memgraph_with_text_indexed_data.execute("""MATCH (n:Document {version:1}) SET n.randomList = [2, 3, 4, 5];""")
def test_remove_text_property_from_indexed_node(memgraph_with_text_indexed_data):
with pytest.raises(GQLAlchemyDatabaseError, match="Tantivy error.*Please check mappings.") as e:
memgraph_with_text_indexed_data.execute("MATCH (n:Document {version:1}) REMOVE n.title, n.version, n.contents;")
memgraph_with_text_indexed_data.execute(
"""MATCH (n:Document {version:1}) REMOVE n.title, n.version, n.contents;"""
)
def test_remove_non_text_property_from_indexed_node(memgraph_with_text_indexed_data):
memgraph_with_text_indexed_data.execute_and_fetch("MATCH (n:Document {date: date('2023-12-15')}) REMOVE n.date;")
memgraph_with_text_indexed_data.execute_and_fetch(
"""MATCH (n:Document {date: date("2023-12-15")}) REMOVE n.date;"""
)
if __name__ == "__main__":