##// END OF EJS Templates
further fix/tests for record edits clobbering DictDB
MinRK -
Show More
@@ -46,7 +46,7 b' We support a subset of mongodb operators:'
46 # the file COPYING, distributed as part of this software.
46 # the file COPYING, distributed as part of this software.
47 #-----------------------------------------------------------------------------
47 #-----------------------------------------------------------------------------
48
48
49 from copy import copy
49 from copy import deepcopy as copy
50 from datetime import datetime
50 from datetime import datetime
51
51
52 from IPython.config.configurable import LoggingConfigurable
52 from IPython.config.configurable import LoggingConfigurable
@@ -129,7 +129,7 b' class DictDB(BaseDB):'
129 d['msg_id'] = rec['msg_id']
129 d['msg_id'] = rec['msg_id']
130 for key in keys:
130 for key in keys:
131 d[key] = rec[key]
131 d[key] = rec[key]
132 return d
132 return copy(d)
133
133
134 def add_record(self, msg_id, rec):
134 def add_record(self, msg_id, rec):
135 """Add a new Task Record, by msg_id."""
135 """Add a new Task Record, by msg_id."""
@@ -197,9 +197,11 b' class TestDictBackend(TestCase):'
197 rec = self.db.get_record(msg_id)
197 rec = self.db.get_record(msg_id)
198 rec.pop('buffers')
198 rec.pop('buffers')
199 rec['garbage'] = 'hello'
199 rec['garbage'] = 'hello'
200 rec['header']['msg_id'] = 'fubar'
200 rec2 = self.db.get_record(msg_id)
201 rec2 = self.db.get_record(msg_id)
201 self.assertTrue('buffers' in rec2)
202 self.assertTrue('buffers' in rec2)
202 self.assertFalse('garbage' in rec2)
203 self.assertFalse('garbage' in rec2)
204 self.assertEquals(rec2['header']['msg_id'], msg_id)
203
205
204 def test_pop_safe_find(self):
206 def test_pop_safe_find(self):
205 """editing query results shouldn't affect record [find]"""
207 """editing query results shouldn't affect record [find]"""
@@ -207,19 +209,23 b' class TestDictBackend(TestCase):'
207 rec = self.db.find_records({'msg_id' : msg_id})[0]
209 rec = self.db.find_records({'msg_id' : msg_id})[0]
208 rec.pop('buffers')
210 rec.pop('buffers')
209 rec['garbage'] = 'hello'
211 rec['garbage'] = 'hello'
212 rec['header']['msg_id'] = 'fubar'
210 rec2 = self.db.find_records({'msg_id' : msg_id})[0]
213 rec2 = self.db.find_records({'msg_id' : msg_id})[0]
211 self.assertTrue('buffers' in rec2)
214 self.assertTrue('buffers' in rec2)
212 self.assertFalse('garbage' in rec2)
215 self.assertFalse('garbage' in rec2)
216 self.assertEquals(rec2['header']['msg_id'], msg_id)
213
217
214 def test_pop_safe_find_keys(self):
218 def test_pop_safe_find_keys(self):
215 """editing query results shouldn't affect record [find+keys]"""
219 """editing query results shouldn't affect record [find+keys]"""
216 msg_id = self.db.get_history()[-1]
220 msg_id = self.db.get_history()[-1]
217 rec = self.db.find_records({'msg_id' : msg_id}, keys=['buffers'])[0]
221 rec = self.db.find_records({'msg_id' : msg_id}, keys=['buffers', 'header'])[0]
218 rec.pop('buffers')
222 rec.pop('buffers')
219 rec['garbage'] = 'hello'
223 rec['garbage'] = 'hello'
224 rec['header']['msg_id'] = 'fubar'
220 rec2 = self.db.find_records({'msg_id' : msg_id})[0]
225 rec2 = self.db.find_records({'msg_id' : msg_id})[0]
221 self.assertTrue('buffers' in rec2)
226 self.assertTrue('buffers' in rec2)
222 self.assertFalse('garbage' in rec2)
227 self.assertFalse('garbage' in rec2)
228 self.assertEquals(rec2['header']['msg_id'], msg_id)
223
229
224
230
225 class TestSQLiteBackend(TestDictBackend):
231 class TestSQLiteBackend(TestDictBackend):
General Comments 0
You need to be logged in to leave comments. Login now