OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 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. |
| 5 |
| 6 from persistent_object_store import PersistentObjectStore |
| 7 import unittest |
| 8 |
| 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. |
| 13 ''' |
| 14 def testPersistence(self): |
| 15 # First object store. |
| 16 object_store = PersistentObjectStore('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 = PersistentObjectStore('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()) |
| 28 # And delete. |
| 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()) |
| 32 |
| 33 def testNamespaceIsolation(self): |
| 34 object_store = PersistentObjectStore('test') |
| 35 another_object_store = PersistentObjectStore('another') |
| 36 object_store.Set('key', 'value') |
| 37 self.assertEqual(None, another_object_store.Get('key').Get()) |
| 38 |
| 39 if __name__ == '__main__': |
| 40 unittest.main() |
OLD | NEW |