##// END OF EJS Templates
dictdb queries should [shallow] copy records...
MinRK -
Show More
@@ -46,7 +46,7 b' We support a subset of mongodb operators:'
46 46 # the file COPYING, distributed as part of this software.
47 47 #-----------------------------------------------------------------------------
48 48
49
49 from copy import copy
50 50 from datetime import datetime
51 51
52 52 from IPython.config.configurable import LoggingConfigurable
@@ -120,7 +120,7 b' class DictDB(BaseDB):'
120 120
121 121 for rec in self._records.itervalues():
122 122 if self._match_one(rec, tests):
123 matches.append(rec)
123 matches.append(copy(rec))
124 124 return matches
125 125
126 126 def _extract_subdict(self, rec, keys):
@@ -139,9 +139,9 b' class DictDB(BaseDB):'
139 139
140 140 def get_record(self, msg_id):
141 141 """Get a specific Task Record, by msg_id."""
142 if not self._records.has_key(msg_id):
142 if not msg_id in self._records:
143 143 raise KeyError("No such msg_id %r"%(msg_id))
144 return self._records[msg_id]
144 return copy(self._records[msg_id])
145 145
146 146 def update_record(self, msg_id, rec):
147 147 """Update the data in an existing record."""
@@ -238,6 +238,18 b' class TestClient(ClusterTestCase):'
238 238 for rec in found:
239 239 self.assertTrue('msg_id' in rec.keys())
240 240
241 def test_db_query_get_result(self):
242 """pop in db_query shouldn't pop from result itself"""
243 self.client[:].apply_sync(lambda : 1)
244 found = self.client.db_query({'msg_id': {'$ne' : ''}})
245 rc2 = clientmod.Client(profile='iptest')
246 # If this bug is not fixed, this call will hang:
247 ar = rc2.get_result(self.client.history[-1])
248 ar.wait(2)
249 self.assertTrue(ar.ready())
250 ar.get()
251 rc2.close()
252
241 253 def test_db_query_in(self):
242 254 """test db query with '$in','$nin' operators"""
243 255 hist = self.client.hub_history()
@@ -183,6 +183,36 b' class TestDictBackend(TestCase):'
183 183 recs = self.db.find_records(query)
184 184 self.assertTrue(len(recs) >= 10)
185 185
186 def test_pop_safe_get(self):
187 """editing query results shouldn't affect record [get]"""
188 msg_id = self.db.get_history()[-1]
189 rec = self.db.get_record(msg_id)
190 rec.pop('buffers')
191 rec['garbage'] = 'hello'
192 rec2 = self.db.get_record(msg_id)
193 self.assertTrue('buffers' in rec2)
194 self.assertFalse('garbage' in rec2)
195
196 def test_pop_safe_find(self):
197 """editing query results shouldn't affect record [find]"""
198 msg_id = self.db.get_history()[-1]
199 rec = self.db.find_records({'msg_id' : msg_id})[0]
200 rec.pop('buffers')
201 rec['garbage'] = 'hello'
202 rec2 = self.db.find_records({'msg_id' : msg_id})[0]
203 self.assertTrue('buffers' in rec2)
204 self.assertFalse('garbage' in rec2)
205
206 def test_pop_safe_find_keys(self):
207 """editing query results shouldn't affect record [find+keys]"""
208 msg_id = self.db.get_history()[-1]
209 rec = self.db.find_records({'msg_id' : msg_id}, keys=['buffers'])[0]
210 rec.pop('buffers')
211 rec['garbage'] = 'hello'
212 rec2 = self.db.find_records({'msg_id' : msg_id})[0]
213 self.assertTrue('buffers' in rec2)
214 self.assertFalse('garbage' in rec2)
215
186 216
187 217 class TestSQLiteBackend(TestDictBackend):
188 218
General Comments 0
You need to be logged in to leave comments. Login now