@@ -97,10 +97,35 @@ def test02_traversal_updates(self):
97
97
["c" , "c2" ]]
98
98
self .assertEqual (query_result .result_set , expected_result )
99
99
100
- def test03_custom_delimiter (self ):
101
- """Validate that non-comma delimiters produce the correct results ."""
100
+ def test03_datatypes (self ):
101
+ """Validate that all RedisGraph datatypes are supported by the bulk updater ."""
102
102
graphname = "tmpgraph2"
103
103
# Write temporary files
104
+ with open ('/tmp/csv.tmp' , mode = 'w' ) as csv_file :
105
+ out = csv .writer (csv_file )
106
+ out .writerow ([0 , 1.5 , "true" , "string" , "[1, 'nested_str']" ])
107
+
108
+ runner = CliRunner ()
109
+ res = runner .invoke (bulk_update , ['--csv' , '/tmp/csv.tmp' ,
110
+ '--query' , 'CREATE (a:L) SET a.intval = row[0], a.doubleval = row[1], a.boolval = row[2], a.stringval = row[3], a.arrayval = row[4]' ,
111
+ '--no-header' ,
112
+ graphname ], catch_exceptions = False )
113
+
114
+ self .assertEqual (res .exit_code , 0 )
115
+ self .assertIn ('Nodes created: 1' , res .output )
116
+ self .assertIn ('Properties set: 5' , res .output )
117
+
118
+ tmp_graph = Graph (graphname , self .redis_con )
119
+ query_result = tmp_graph .query ('MATCH (a) RETURN a.intval, a.doubleval, a.boolval, a.stringval, a.arrayval' )
120
+
121
+ # Validate that the expected results are all present in the graph
122
+ expected_result = [[0 , 1.5 , True , "string" , "[1,'nested_str']" ]]
123
+ self .assertEqual (query_result .result_set , expected_result )
124
+
125
+ def test04_custom_delimiter (self ):
126
+ """Validate that non-comma delimiters produce the correct results."""
127
+ graphname = "tmpgraph3"
128
+ # Write temporary files
104
129
with open ('/tmp/csv.tmp' , mode = 'w' ) as csv_file :
105
130
out = csv .writer (csv_file , delimiter = '|' )
106
131
out .writerow (["id" , "name" ])
@@ -140,7 +165,7 @@ def test03_custom_delimiter(self):
140
165
self .assertNotIn ('Nodes created' , res .output )
141
166
self .assertNotIn ('Properties set' , res .output )
142
167
143
- def test04_custom_variable_name (self ):
168
+ def test05_custom_variable_name (self ):
144
169
"""Validate that the user can specify the name of the 'row' query variable."""
145
170
graphname = "variable_name"
146
171
runner = CliRunner ()
@@ -178,9 +203,9 @@ def test04_custom_variable_name(self):
178
203
['Valerie Abigail Arad' , 31 , 'female' , 'married' ]]
179
204
self .assertEqual (query_result .result_set , expected_result )
180
205
181
- def test05_no_header (self ):
206
+ def test06_no_header (self ):
182
207
"""Validate that the '--no-header' option works properly."""
183
- graphname = "tmpgraph3 "
208
+ graphname = "tmpgraph4 "
184
209
# Write temporary files
185
210
with open ('/tmp/csv.tmp' , mode = 'w' ) as csv_file :
186
211
out = csv .writer (csv_file )
@@ -208,7 +233,7 @@ def test05_no_header(self):
208
233
[5 , "b" ]]
209
234
self .assertEqual (query_result .result_set , expected_result )
210
235
211
- def test06_batched_update (self ):
236
+ def test07_batched_update (self ):
212
237
"""Validate that updates performed over multiple batches produce the correct results."""
213
238
graphname = "batched_update"
214
239
@@ -238,9 +263,9 @@ def test06_batched_update(self):
238
263
expected_result = [[prop_str ]]
239
264
self .assertEqual (query_result .result_set , expected_result )
240
265
241
- def test07_runtime_error (self ):
266
+ def test08_runtime_error (self ):
242
267
"""Validate that run-time errors are captured by the bulk updater."""
243
- graphname = "tmpgraph1 "
268
+ graphname = "tmpgraph5 "
244
269
245
270
# Write temporary files
246
271
with open ('/tmp/csv.tmp' , mode = 'w' ) as csv_file :
@@ -255,9 +280,21 @@ def test07_runtime_error(self):
255
280
self .assertNotEqual (res .exit_code , 0 )
256
281
self .assertIn ("Cannot merge node" , str (res .exception ))
257
282
258
- def test07_invalid_inputs (self ):
283
+ def test09_compile_time_error (self ):
284
+ """Validate that malformed queries trigger an early exit from the bulk updater."""
285
+ graphname = "tmpgraph5"
286
+ runner = CliRunner ()
287
+ res = runner .invoke (bulk_update , ['--csv' , '/tmp/csv.tmp' ,
288
+ '--query' , 'CREATE (:L {val: row[0], val2: undefined_identifier})' ,
289
+ '--no-header' ,
290
+ graphname ])
291
+
292
+ self .assertNotEqual (res .exit_code , 0 )
293
+ self .assertIn ("undefined_identifier not defined" , str (res .exception ))
294
+
295
+ def test10_invalid_inputs (self ):
259
296
"""Validate that the bulk updater handles invalid inputs incorrectly."""
260
- graphname = "tmpgraph1 "
297
+ graphname = "tmpgraph6 "
261
298
262
299
# Attempt to insert a non-existent CSV file.
263
300
runner = CliRunner ()
@@ -267,21 +304,3 @@ def test07_invalid_inputs(self):
267
304
268
305
self .assertNotEqual (res .exit_code , 0 )
269
306
self .assertIn ("No such file" , str (res .exception ))
270
-
271
- # Write temporary files
272
- with open ('/tmp/csv.tmp' , mode = 'w' ) as csv_file :
273
- out = csv .writer (csv_file )
274
- out .writerow (["id" , "name" ])
275
- out .writerow ([0 , "a" ])
276
- out .writerow ([5 , "b" ])
277
- out .writerow ([3 , "c" ])
278
-
279
- # Attempt to access a non-existent column.
280
- res = runner .invoke (bulk_update , ['--csv' , '/tmp/csv.tmp' ,
281
- '--query' , 'CREATE (:L {val: row[3]})' ,
282
- graphname ])
283
-
284
- # self.assertNotEqual(res.exit_code, 0)
285
- # import ipdb
286
- # ipdb.set_trace()
287
- # self.assertIn("No such file", str(res.exception))
0 commit comments