Skip to content

Commit b027e86

Browse files
committed
Fix new index and constraint syntax
1 parent 0f85580 commit b027e86

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

tests/neo4j/test_summary.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ def test_summary_counters_case_1(self):
151151
@requires_multi_db_support
152152
@cluster_unsafe_test
153153
def test_summary_counters_case_2(self):
154+
version = get_server_info().version
155+
new_index_syntax = version >= "4"
156+
new_constraint_syntax = version >= "4.4"
157+
154158
self._session = self._driver.session("w", database="system")
155159

156160
self._session.run("DROP DATABASE test IF EXISTS").consume()
@@ -233,27 +237,44 @@ def test_summary_counters_case_2(self):
233237
contains_updates=True)
234238
self._session.close()
235239

240+
if new_index_syntax: # 4.0+
241+
query = "CREATE INDEX test_label_prop FOR (n:ALabel) ON (n.prop)"
242+
else: # 3.5-
243+
query = "CREATE INDEX ON :ALabel (prop)"
236244
self._session = self._driver.session("w", database="test")
237-
summary = self._session.run("CREATE INDEX ON :ALabel(prop)").consume()
245+
summary = self._session.run(query).consume()
238246
self._assert_counters(summary, indexes_added=1, contains_updates=True)
239247
self._session.close()
240248

249+
if new_index_syntax: # 4.0+
250+
query = "DROP INDEX test_label_prop"
251+
else: # 3.5-
252+
query = "DROP INDEX ON :ALabel(prop)"
241253
self._session = self._driver.session("w", database="test")
242-
summary = self._session.run("DROP INDEX ON :ALabel(prop)").consume()
254+
summary = self._session.run(query).consume()
243255
self._assert_counters(summary, indexes_removed=1,
244256
contains_updates=True)
245257
self._session.close()
246258

259+
if new_constraint_syntax: # 4.4+
260+
query = ("CREATE CONSTRAINT test_book_isbn FOR (book:Book) "
261+
"REQUIRE book.isbn IS UNIQUE")
262+
else: # 4.3-
263+
query = ("CREATE CONSTRAINT ON (book:Book) "
264+
"ASSERT book.isbn IS UNIQUE")
247265
self._session = self._driver.session("w", database="test")
248-
summary = self._session.run("CREATE CONSTRAINT ON (book:Book) "
249-
"ASSERT book.isbn IS UNIQUE").consume()
266+
summary = self._session.run(query).consume()
250267
self._assert_counters(summary,
251268
constraints_added=1, contains_updates=True)
252269
self._session.close()
253270

271+
if new_constraint_syntax: # 4.4+
272+
query = "DROP CONSTRAINT test_book_isbn"
273+
else: # 4.3-
274+
query = ("DROP CONSTRAINT ON (book:Book) "
275+
"ASSERT book.isbn IS UNIQUE")
254276
self._session = self._driver.session("w", database="test")
255-
summary = self._session.run("DROP CONSTRAINT ON (book:Book) "
256-
"ASSERT book.isbn IS UNIQUE").consume()
277+
summary = self._session.run(query).consume()
257278
self._assert_counters(summary,
258279
constraints_removed=1, contains_updates=True)
259280
self._session.close()

0 commit comments

Comments
 (0)