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