| 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 import unittest | 6 import unittest |
| 7 | 7 |
| 8 from appengine_wrappers import GetAppVersion | 8 from appengine_wrappers import GetAppVersion |
| 9 from test_object_store import TestObjectStore | 9 from test_object_store import TestObjectStore |
| 10 from object_store_creator import ObjectStoreCreator | 10 from object_store_creator import ObjectStoreCreator |
| 11 | 11 |
| 12 class _FooClass(object): | 12 class _FooClass(object): |
| 13 def __init__(self): pass | 13 def __init__(self): pass |
| 14 | 14 |
| 15 class ObjectStoreCreatorTest(unittest.TestCase): | 15 class ObjectStoreCreatorTest(unittest.TestCase): |
| 16 def setUp(self): | 16 def setUp(self): |
| 17 self._creator = ObjectStoreCreator('trunk', | 17 self._creator = ObjectStoreCreator(start_empty=False, |
| 18 start_empty=False, | |
| 19 store_type=TestObjectStore, | 18 store_type=TestObjectStore, |
| 20 disable_wrappers=True) | 19 disable_wrappers=True) |
| 21 | 20 |
| 22 def testVanilla(self): | 21 def testVanilla(self): |
| 23 store = self._creator.Create(_FooClass) | 22 store = self._creator.Create(_FooClass) |
| 24 self.assertEqual( | 23 self.assertEqual( |
| 25 'class=_FooClass&channel=trunk&app_version=%s' % GetAppVersion(), | 24 'class=_FooClass&app_version=%s' % GetAppVersion(), |
| 26 store.namespace) | 25 store.namespace) |
| 27 self.assertFalse(store.start_empty) | 26 self.assertFalse(store.start_empty) |
| 28 | 27 |
| 29 def testWithCategory(self): | 28 def testWithCategory(self): |
| 30 store = self._creator.Create(_FooClass, category='hi') | 29 store = self._creator.Create(_FooClass, category='hi') |
| 31 self.assertEqual( | 30 self.assertEqual( |
| 32 'class=_FooClass&category=hi&channel=trunk&app_version=%s' % | 31 'class=_FooClass&category=hi&app_version=%s' % GetAppVersion(), |
| 33 GetAppVersion(), | |
| 34 store.namespace) | 32 store.namespace) |
| 35 self.assertFalse(store.start_empty) | 33 self.assertFalse(store.start_empty) |
| 36 | 34 |
| 37 def testWithoutChannel(self): | |
| 38 store = self._creator.Create(_FooClass, channel=None) | |
| 39 self.assertEqual('class=_FooClass&app_version=%s' % GetAppVersion(), | |
| 40 store.namespace) | |
| 41 self.assertFalse(store.start_empty) | |
| 42 | |
| 43 def testWithoutAppVersion(self): | 35 def testWithoutAppVersion(self): |
| 44 store = self._creator.Create(_FooClass, app_version=None) | 36 store = self._creator.Create(_FooClass, app_version=None) |
| 45 self.assertEqual('class=_FooClass&channel=trunk', store.namespace) | 37 self.assertEqual('class=_FooClass', store.namespace) |
| 46 self.assertFalse(store.start_empty) | 38 self.assertFalse(store.start_empty) |
| 47 | 39 |
| 48 def testStartConfiguration(self): | 40 def testStartConfiguration(self): |
| 49 store = self._creator.Create(_FooClass, start_empty=True) | 41 store = self._creator.Create(_FooClass, start_empty=True) |
| 50 self.assertTrue(store.start_empty) | 42 self.assertTrue(store.start_empty) |
| 51 store = self._creator.Create(_FooClass, start_empty=False) | 43 store = self._creator.Create(_FooClass, start_empty=False) |
| 52 self.assertFalse(store.start_empty) | 44 self.assertFalse(store.start_empty) |
| 53 self.assertRaises(ValueError, ObjectStoreCreator, 'foo') | 45 self.assertRaises(ValueError, ObjectStoreCreator) |
| 54 | 46 |
| 55 def testIllegalCharacters(self): | 47 def testIllegalCharacters(self): |
| 56 self.assertRaises(ValueError, | 48 self.assertRaises(ValueError, |
| 57 self._creator.Create, _FooClass, channel='foo=') | |
| 58 self.assertRaises(ValueError, | |
| 59 self._creator.Create, _FooClass, app_version='1&2') | 49 self._creator.Create, _FooClass, app_version='1&2') |
| 60 self.assertRaises(ValueError, | 50 self.assertRaises(ValueError, |
| 61 self._creator.Create, _FooClass, category='a=&b') | 51 self._creator.Create, _FooClass, category='a=&b') |
| 62 | 52 |
| 63 if __name__ == '__main__': | 53 if __name__ == '__main__': |
| 64 unittest.main() | 54 unittest.main() |
| OLD | NEW |