@@ -19,15 +19,15 @@ def __testSkip(self, coll, numToSkip, expectedContent):
19
19
def testInvalidJson (self ):
20
20
"test inserting invalid JSON value into SODA collection"
21
21
invalidJson = "{testKey:testValue}"
22
- sodaDatabase = self .connection . getSodaDatabase ()
22
+ sodaDatabase = self .getSodaDatabase ()
23
23
coll = sodaDatabase .createCollection ("cxoInvalidJSON" )
24
24
doc = sodaDatabase .createDocument (invalidJson )
25
25
self .assertRaises (cx_Oracle .IntegrityError , coll .insertOne , doc )
26
26
coll .drop ()
27
27
28
28
def testInsertDocuments (self ):
29
29
"test inserting documents into a SODA collection"
30
- sodaDatabase = self .connection . getSodaDatabase ()
30
+ sodaDatabase = self .getSodaDatabase ()
31
31
coll = sodaDatabase .createCollection ("cxoInsertDocs" )
32
32
coll .find ().remove ()
33
33
valuesToInsert = [
@@ -49,7 +49,7 @@ def testInsertDocuments(self):
49
49
50
50
def testSkipDocuments (self ):
51
51
"test skipping documents in a SODA collection"
52
- sodaDatabase = self .connection . getSodaDatabase ()
52
+ sodaDatabase = self .getSodaDatabase ()
53
53
coll = sodaDatabase .createCollection ("cxoSkipDocs" )
54
54
coll .find ().remove ()
55
55
valuesToInsert = [
@@ -69,7 +69,7 @@ def testSkipDocuments(self):
69
69
70
70
def testReplaceDocument (self ):
71
71
"test replace documents in SODA collection"
72
- sodaDatabase = self .connection . getSodaDatabase ()
72
+ sodaDatabase = self .getSodaDatabase ()
73
73
coll = sodaDatabase .createCollection ("cxoReplaceDoc" )
74
74
coll .find ().remove ()
75
75
content = {'name' : 'John' , 'address' : {'city' : 'Sydney' }}
@@ -83,7 +83,7 @@ def testReplaceDocument(self):
83
83
84
84
def testSearchDocumentsWithContent (self ):
85
85
"test search documents with content using $like and $regex"
86
- sodaDatabase = self .connection . getSodaDatabase ()
86
+ sodaDatabase = self .getSodaDatabase ()
87
87
coll = sodaDatabase .createCollection ("cxoSearchDocContent" )
88
88
coll .find ().remove ()
89
89
data = [
@@ -120,7 +120,7 @@ def testSearchDocumentsWithContent(self):
120
120
121
121
def testDocumentRemove (self ):
122
122
"test removing documents"
123
- sodaDatabase = self .connection . getSodaDatabase ()
123
+ sodaDatabase = self .getSodaDatabase ()
124
124
coll = sodaDatabase .createCollection ("cxoRemoveDocs" )
125
125
coll .find ().remove ()
126
126
data = [
@@ -156,7 +156,7 @@ def testCreateAndDropIndex(self):
156
156
}
157
157
]
158
158
}
159
- sodaDatabase = self .connection . getSodaDatabase ()
159
+ sodaDatabase = self .getSodaDatabase ()
160
160
coll = sodaDatabase .createCollection ("cxoTestIndexes" )
161
161
coll .find ().remove ()
162
162
self .connection .commit ()
@@ -170,7 +170,7 @@ def testCreateAndDropIndex(self):
170
170
def testGetDocuments (self ):
171
171
"test getting documents from Collection"
172
172
self .connection .autocommit = True
173
- sodaDatabase = self .connection . getSodaDatabase ()
173
+ sodaDatabase = self .getSodaDatabase ()
174
174
coll = sodaDatabase .createCollection ("cxoTestGetDocs" )
175
175
coll .find ().remove ()
176
176
data = [
@@ -188,7 +188,7 @@ def testGetDocuments(self):
188
188
def testCursor (self ):
189
189
"test fetching documents from a cursor"
190
190
self .connection .autocommit = True
191
- sodaDatabase = self .connection . getSodaDatabase ()
191
+ sodaDatabase = self .getSodaDatabase ()
192
192
coll = sodaDatabase .createCollection ("cxoFindViaCursor" )
193
193
coll .find ().remove ()
194
194
data = [
@@ -203,7 +203,7 @@ def testCursor(self):
203
203
204
204
def testMultipleDocumentRemove (self ):
205
205
"test removing multiple documents using multiple keys"
206
- sodaDatabase = self .connection . getSodaDatabase ()
206
+ sodaDatabase = self .getSodaDatabase ()
207
207
coll = sodaDatabase .createCollection ("cxoRemoveMultipleDocs" )
208
208
coll .find ().remove ()
209
209
data = [
@@ -224,7 +224,7 @@ def testMultipleDocumentRemove(self):
224
224
225
225
def testDocumentVersion (self ):
226
226
"test using version to get documents and remove them"
227
- sodaDatabase = self .connection . getSodaDatabase ()
227
+ sodaDatabase = self .getSodaDatabase ()
228
228
coll = sodaDatabase .createCollection ("cxoDocumentVersion" )
229
229
coll .find ().remove ()
230
230
content = {'name' : 'John' , 'address' : {'city' : 'Bangalore' }}
@@ -248,7 +248,7 @@ def testDocumentVersion(self):
248
248
249
249
def testGetCursor (self ):
250
250
"test keys with GetCursor"
251
- sodaDatabase = self .connection . getSodaDatabase ()
251
+ sodaDatabase = self .getSodaDatabase ()
252
252
coll = sodaDatabase .createCollection ("cxoKeysWithGetCursor" )
253
253
coll .find ().remove ()
254
254
data = [
@@ -268,13 +268,32 @@ def testGetCursor(self):
268
268
269
269
def testCreatedOn (self ):
270
270
"test createdOn attribute of Document"
271
- sodaDatabase = self .connection . getSodaDatabase ()
271
+ sodaDatabase = self .getSodaDatabase ()
272
272
coll = sodaDatabase .createCollection ("cxoCreatedOn" )
273
273
coll .find ().remove ()
274
274
data = {'name' : 'John' , 'address' : {'city' : 'Bangalore' }}
275
275
doc = coll .insertOneAndGet (data )
276
276
self .assertEqual (doc .createdOn , doc .lastModified )
277
277
278
+ def testSodaTruncate (self ):
279
+ "test Soda truncate"
280
+ sodaDatabase = self .getSodaDatabase (minclient = (20 ,1 ))
281
+ coll = sodaDatabase .createCollection ("cxoTruncateDocs" )
282
+ coll .find ().remove ()
283
+ valuesToInsert = [
284
+ { "name" : "George" , "age" : 47 },
285
+ { "name" : "Susan" , "age" : 39 },
286
+ { "name" : "John" , "age" : 50 },
287
+ { "name" : "Jill" , "age" : 54 }
288
+ ]
289
+ for value in valuesToInsert :
290
+ coll .insertOne (value )
291
+ self .connection .commit ()
292
+ self .assertEqual (coll .find ().count (), len (valuesToInsert ))
293
+ coll .truncate ()
294
+ self .assertEqual (coll .find ().count (), 0 )
295
+ coll .drop ()
296
+
278
297
if __name__ == "__main__" :
279
298
TestEnv .RunTestCases ()
280
299
0 commit comments