2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 from environment_wrappers
import CreatePersistentObjectStore
9 class PersistentObjectStoreTest(unittest
.TestCase
):
10 '''Tests for PersistentObjectStore. These are all a bit contrived because
11 ultimately it comes down to our use of the appengine datastore API, and we
12 mock it out for tests anyway. Who knows whether it's correct.
14 def testPersistence(self
):
16 object_store
= CreatePersistentObjectStore('test')
17 object_store
.Set('key', 'value')
18 self
.assertEqual('value', object_store
.Get('key').Get())
19 # Other object store should have it too.
20 another_object_store
= CreatePersistentObjectStore('test')
21 self
.assertEqual('value', another_object_store
.Get('key').Get())
22 # Setting in the other store should set in both.
23 mapping
= {'key2': 'value2', 'key3': 'value3'}
24 another_object_store
.SetMulti(mapping
)
25 self
.assertEqual(mapping
, object_store
.GetMulti(mapping
.keys()).Get())
26 self
.assertEqual(mapping
,
27 another_object_store
.GetMulti(mapping
.keys()).Get())
29 object_store
.DelMulti(mapping
.keys())
30 self
.assertEqual({}, object_store
.GetMulti(mapping
.keys()).Get())
31 self
.assertEqual({}, another_object_store
.GetMulti(mapping
.keys()).Get())
33 def testNamespaceIsolation(self
):
34 object_store
= CreatePersistentObjectStore('test')
35 another_object_store
= CreatePersistentObjectStore('another')
36 object_store
.Set('key', 'value')
37 self
.assertEqual(None, another_object_store
.Get('key').Get())
39 if __name__
== '__main__':