Skip to content

Commit aba37c8

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

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

tests/neo4j/test_summary.py

Lines changed: 28 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,45 @@ 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 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 FOR (n:ALabel) ON (n.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 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 FOR (book:Book) "
273+
"REQUIRE book.isbn IS UNIQUE")
274+
else: # 4.3-
275+
query = ("DROP CONSTRAINT ON (book:Book) "
276+
"ASSERT book.isbn IS UNIQUE")
254277
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()
278+
summary = self._session.run(query).consume()
257279
self._assert_counters(summary,
258280
constraints_removed=1, contains_updates=True)
259281
self._session.close()

0 commit comments

Comments
 (0)