OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 from persistent_object_store import PersistentObjectStore | 6 from environment_wrappers import CreatePersistentObjectStore |
7 import unittest | 7 import unittest |
8 | 8 |
9 class PersistentObjectStoreTest(unittest.TestCase): | 9 class PersistentObjectStoreTest(unittest.TestCase): |
10 '''Tests for PersistentObjectStore. These are all a bit contrived because | 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 | 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. | 12 mock it out for tests anyway. Who knows whether it's correct. |
13 ''' | 13 ''' |
14 def testPersistence(self): | 14 def testPersistence(self): |
15 # First object store. | 15 # First object store. |
16 object_store = PersistentObjectStore('test') | 16 object_store = CreatePersistentObjectStore('test') |
17 object_store.Set('key', 'value') | 17 object_store.Set('key', 'value') |
18 self.assertEqual('value', object_store.Get('key').Get()) | 18 self.assertEqual('value', object_store.Get('key').Get()) |
19 # Other object store should have it too. | 19 # Other object store should have it too. |
20 another_object_store = PersistentObjectStore('test') | 20 another_object_store = CreatePersistentObjectStore('test') |
21 self.assertEqual('value', another_object_store.Get('key').Get()) | 21 self.assertEqual('value', another_object_store.Get('key').Get()) |
22 # Setting in the other store should set in both. | 22 # Setting in the other store should set in both. |
23 mapping = {'key2': 'value2', 'key3': 'value3'} | 23 mapping = {'key2': 'value2', 'key3': 'value3'} |
24 another_object_store.SetMulti(mapping) | 24 another_object_store.SetMulti(mapping) |
25 self.assertEqual(mapping, object_store.GetMulti(mapping.keys()).Get()) | 25 self.assertEqual(mapping, object_store.GetMulti(mapping.keys()).Get()) |
26 self.assertEqual(mapping, | 26 self.assertEqual(mapping, |
27 another_object_store.GetMulti(mapping.keys()).Get()) | 27 another_object_store.GetMulti(mapping.keys()).Get()) |
28 # And delete. | 28 # And delete. |
29 object_store.DelMulti(mapping.keys()) | 29 object_store.DelMulti(mapping.keys()) |
30 self.assertEqual({}, object_store.GetMulti(mapping.keys()).Get()) | 30 self.assertEqual({}, object_store.GetMulti(mapping.keys()).Get()) |
31 self.assertEqual({}, another_object_store.GetMulti(mapping.keys()).Get()) | 31 self.assertEqual({}, another_object_store.GetMulti(mapping.keys()).Get()) |
32 | 32 |
33 def testNamespaceIsolation(self): | 33 def testNamespaceIsolation(self): |
34 object_store = PersistentObjectStore('test') | 34 object_store = CreatePersistentObjectStore('test') |
35 another_object_store = PersistentObjectStore('another') | 35 another_object_store = CreatePersistentObjectStore('another') |
36 object_store.Set('key', 'value') | 36 object_store.Set('key', 'value') |
37 self.assertEqual(None, another_object_store.Get('key').Get()) | 37 self.assertEqual(None, another_object_store.Get('key').Get()) |
38 | 38 |
39 if __name__ == '__main__': | 39 if __name__ == '__main__': |
40 unittest.main() | 40 unittest.main() |
OLD | NEW |