Implement remaining test cases and add more of them

This commit is contained in:
Ante Pušić 2024-01-16 01:51:39 +01:00
parent 5c23e313e4
commit 2d2d21bab4
2 changed files with 101 additions and 17 deletions

View File

@ -49,10 +49,27 @@ def memgraph(**kwargs) -> Memgraph:
def memgraph_with_text_indexed_data(**kwargs) -> Memgraph:
memgraph = Memgraph()
memgraph.execute_and_fetch("CREATE TEXT INDEX complianceDocuments ON :Document;")
memgraph.execute("CREATE (:Document {title: 'Rules2024', version: 1});")
memgraph.execute("CREATE (:Document:Revision {title: 'Rules2024', version: 2});")
memgraph.execute("CREATE TEXT INDEX complianceDocuments ON :Document;")
yield memgraph
memgraph.execute_and_fetch("DROP TEXT INDEX complianceDocuments;")
memgraph.execute("DROP TEXT INDEX complianceDocuments;")
memgraph.drop_database()
memgraph.drop_indexes()
@pytest.fixture
def memgraph_with_text_indexed_data(**kwargs) -> Memgraph:
memgraph = Memgraph()
memgraph.execute("CREATE (:Document:Revision {title: 'Rules2024', version: 1});")
memgraph.execute("CREATE (:Revision {title: 'Rules2024', version: 2});")
memgraph.execute("CREATE TEXT INDEX complianceDocuments ON :Document;")
yield memgraph
memgraph.execute("DROP TEXT INDEX complianceDocuments;")
memgraph.drop_database()
memgraph.drop_indexes()

View File

@ -11,51 +11,118 @@
import sys
import mgclient
import pytest
from common import memgraph, memgraph_with_text_indexed_data
from common import memgraph, memgraph_with_mixed_data, memgraph_with_text_indexed_data
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 complianceDocuments ON :Document;")
memgraph.execute("CREATE TEXT INDEX exampleIndex ON :Document;")
assert True
def test_drop_index(memgraph):
memgraph.execute("DROP TEXT INDEX complianceDocuments;")
memgraph.execute("DROP TEXT INDEX exampleIndex;")
assert True
def test_text_search_given_property(memgraph_with_text_indexed_data):
memgraph_with_text_indexed_data.execute_and_fetch("CALL text_search.search('complianceDocuments', 'b') YIELD *;")
result = list(memgraph_with_text_indexed_data.execute_and_fetch(GET_RULES_2024_DOCUMENT))
assert len(result) == 2 and result == [{"title": "Rules2024", "version": 1}, {"title": "Rules2024", "version": 2}]
def test_text_search_all_properties(memgraph_with_text_indexed_data):
memgraph_with_text_indexed_data.execute_and_fetch("CALL text_search.search('complianceDocuments', 'b') YIELD *;")
result = list(
memgraph_with_text_indexed_data.execute_and_fetch(
"""CALL text_search.search('complianceDocuments', 'Rules2024') YIELD node
RETURN node.title AS title, node.version AS version
ORDER BY version ASC, title ASC;"""
)
)
# assert len(result) == 2 and result == [{"title": "Rules2024", "version": 1}, {"title": "Rules2024", "version": 2}]
def test_create_indexed_node(memgraph_with_text_indexed_data):
memgraph_with_text_indexed_data.execute_and_fetch("CALL text_search.search('complianceDocuments', 'b') YIELD *;")
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))
assert len(result) == 3 and result == [
{"title": "Rules2024", "version": 1},
{"title": "Rules2024", "version": 2},
{"title": "Rules2024", "version": 3},
]
def test_delete_indexed_node(memgraph_with_text_indexed_data):
memgraph_with_text_indexed_data.execute_and_fetch("CALL text_search.search('complianceDocuments', 'b') YIELD *;")
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))
assert len(result) == 1 and result == [{"title": "Rules2024", "version": 1}]
def test_add_indexed_label(memgraph_with_text_indexed_data):
memgraph_with_text_indexed_data.execute_and_fetch("CALL text_search.search('complianceDocuments', 'b') YIELD *;")
def test_add_indexed_label(memgraph_with_mixed_data):
memgraph_with_mixed_data.execute("MATCH (n:Revision) SET n:Document;")
result = list(memgraph_with_mixed_data.execute_and_fetch(GET_RULES_2024_DOCUMENT))
assert len(result) == 2 and result == [{"title": "Rules2024", "version": 1}, {"title": "Rules2024", "version": 2}]
def test_remove_indexed_label(memgraph_with_text_indexed_data):
memgraph_with_text_indexed_data.execute_and_fetch("CALL text_search.search('complianceDocuments', 'b') YIELD *;")
def test_remove_indexed_label(memgraph_with_mixed_data):
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))
assert len(result) == 0
def test_add_property_to_indexed_node(memgraph_with_text_indexed_data):
memgraph_with_text_indexed_data.execute_and_fetch("CALL text_search.search('complianceDocuments', 'b') YIELD *;")
def test_add_text_property_to_indexed_node(memgraph_with_text_indexed_data):
try:
memgraph_with_text_indexed_data.execute("MATCH (n:Document {version:1}) SET n.author = 'Nenad Patel';")
except mgclient.DatabaseError:
assert True
assert False
def test_remove_property_from_indexed_node(memgraph_with_text_indexed_data):
memgraph_with_text_indexed_data.execute_and_fetch("CALL text_search.search('complianceDocuments', 'b') YIELD *;")
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';")
result = list(
memgraph_with_text_indexed_data.execute_and_fetch(
"""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;"""
)
)
assert len(result) == 1 and result == [{"title": "Rules2030", "version": 1}]
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.wordcount = 1926;")
def test_remove_text_property_from_indexed_node(memgraph_with_text_indexed_data):
try:
memgraph_with_text_indexed_data.execute("MATCH (n:Document {version:1}) REMOVE n.title;")
except mgclient.DatabaseError:
assert True
assert False
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 {version:1}) REMOVE n.version;")
if __name__ == "__main__":