From c7be58e1dca09453c06a925fa7565d3292568e09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ante=20Pu=C5=A1i=C4=87?= Date: Mon, 22 Jan 2024 10:28:29 +0100 Subject: [PATCH] Improve tests --- tests/e2e/text_search/common.py | 16 +++++++++++---- tests/e2e/text_search/test_text_search.py | 25 +++++++++-------------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/tests/e2e/text_search/common.py b/tests/e2e/text_search/common.py index 43f3e74ca..300498c19 100644 --- a/tests/e2e/text_search/common.py +++ b/tests/e2e/text_search/common.py @@ -49,8 +49,12 @@ def memgraph(**kwargs) -> Memgraph: def memgraph_with_text_indexed_data(**kwargs) -> Memgraph: memgraph = Memgraph() - memgraph.execute("CREATE (:Document {title: 'Rules2024', version: 1});") - memgraph.execute("CREATE (:Document:Revision {title: 'Rules2024', version: 2});") + memgraph.execute( + "CREATE (:Document {title: 'Rules2024', version: 1, date: date('2023-11-14'), contents: 'Lorem ipsum dolor sit amet'});" + ) + memgraph.execute( + "CREATE (:Document:Revision {title: 'Rules2024', version: 2, date: date('2023-12-15'), contents: 'consectetur adipiscing elit'});" + ) memgraph.execute("CREATE TEXT INDEX complianceDocuments ON :Document;") yield memgraph @@ -64,8 +68,12 @@ def memgraph_with_text_indexed_data(**kwargs) -> Memgraph: def memgraph_with_mixed_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 (: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'});" + ) memgraph.execute("CREATE TEXT INDEX complianceDocuments ON :Document;") yield memgraph diff --git a/tests/e2e/text_search/test_text_search.py b/tests/e2e/text_search/test_text_search.py index abe262398..86a15497b 100644 --- a/tests/e2e/text_search/test_text_search.py +++ b/tests/e2e/text_search/test_text_search.py @@ -42,19 +42,14 @@ 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_all_properties(memgraph_with_text_indexed_data): -# # issue -# result = list(memgraph_with_text_indexed_data.execute_and_fetch(GET_RULES_2024_DOCUMENT)) -# print(result) -# 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;""" -# ) -# ) +# 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;""" -# assert len(result) == 2 and result == [{"title": "Rules2024", "version": 1}, {"title": "Rules2024", "version": 2}] +# result = list(memgraph_with_text_indexed_data.execute_and_fetch(BOOLEAN_QUERY)) + +# assert len(result) == 1 and result == [{"title": "Rules2024", "version": 2}] def test_create_indexed_node(memgraph_with_text_indexed_data): @@ -109,16 +104,16 @@ 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.wordcount = 1926;") + 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;") + 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 {version:1}) REMOVE n.version;") + memgraph_with_text_indexed_data.execute_and_fetch("MATCH (n:Document {date: date('2023-12-15')}) REMOVE n.date;") if __name__ == "__main__":