- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / common / extensions / docs / server2 / object_store_creator_test.py
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 import unittest
7
8 from appengine_wrappers import GetAppVersion
9 from test_object_store import TestObjectStore
10 from object_store_creator import ObjectStoreCreator
11
12 class _FooClass(object):
13   def __init__(self): pass
14
15 class ObjectStoreCreatorTest(unittest.TestCase):
16   def setUp(self):
17     self._creator = ObjectStoreCreator(start_empty=False,
18                                        store_type=TestObjectStore,
19                                        disable_wrappers=True)
20
21   def testVanilla(self):
22     store = self._creator.Create(_FooClass)
23     self.assertEqual(
24         'class=_FooClass&app_version=%s' % GetAppVersion(),
25         store.namespace)
26     self.assertFalse(store.start_empty)
27
28   def testWithCategory(self):
29     store = self._creator.Create(_FooClass, category='hi')
30     self.assertEqual(
31         'class=_FooClass&category=hi&app_version=%s' % GetAppVersion(),
32         store.namespace)
33     self.assertFalse(store.start_empty)
34
35   def testWithoutAppVersion(self):
36     store = self._creator.Create(_FooClass, app_version=None)
37     self.assertEqual('class=_FooClass', store.namespace)
38     self.assertFalse(store.start_empty)
39
40   def testStartConfiguration(self):
41     store = self._creator.Create(_FooClass, start_empty=True)
42     self.assertTrue(store.start_empty)
43     store = self._creator.Create(_FooClass, start_empty=False)
44     self.assertFalse(store.start_empty)
45     self.assertRaises(ValueError, ObjectStoreCreator)
46
47   def testIllegalCharacters(self):
48     self.assertRaises(ValueError,
49                       self._creator.Create, _FooClass, app_version='1&2')
50     self.assertRaises(ValueError,
51                       self._creator.Create, _FooClass, category='a=&b')
52
53 if __name__ == '__main__':
54   unittest.main()