Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(417)

Side by Side Diff: chrome/common/extensions/docs/server2/compiled_file_system_test.py

Issue 14267024: Devserver: have a separate ObjectStore namespace (both memcache and datastore) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove _CheckVersions Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 compiled_file_system import CompiledFileSystem 6 from compiled_file_system import CompiledFileSystem
7 from copy import deepcopy 7 from copy import deepcopy
8 from file_system import FileNotFoundError 8 from file_system import FileNotFoundError
9 from object_store_creator import ObjectStoreCreator 9 from object_store_creator import ObjectStoreCreator
10 from test_file_system import TestFileSystem 10 from test_file_system import TestFileSystem
(...skipping 10 matching lines...) Expand all
21 } 21 }
22 }, 22 },
23 'extensions': { 23 'extensions': {
24 'activeTab.html': 'activeTab.html contents', 24 'activeTab.html': 'activeTab.html contents',
25 'alarms.html': 'alarms.html contents' 25 'alarms.html': 'alarms.html contents'
26 } 26 }
27 } 27 }
28 28
29 def _CreateFactory(): 29 def _CreateFactory():
30 return CompiledFileSystem.Factory(TestFileSystem(deepcopy(_TEST_DATA)), 30 return CompiledFileSystem.Factory(TestFileSystem(deepcopy(_TEST_DATA)),
31 ObjectStoreCreator.Factory(), 31 ObjectStoreCreator.Factory('3-0', 'test'),
32 store_type=TestObjectStore) 32 store_type=TestObjectStore)
33 33
34 class CompiledFileSystemTest(unittest.TestCase): 34 class CompiledFileSystemTest(unittest.TestCase):
35 def testIdentityNamespace(self): 35 def testIdentityNamespace(self):
36 factory = _CreateFactory() 36 factory = _CreateFactory()
37 compiled_fs = factory.GetOrCreateIdentity() 37 compiled_fs = factory.GetOrCreateIdentity()
38 self.assertEqual('CompiledFileSystem/id/file', 38 self.assertEqual('3-0/CompiledFileSystem@test/id/file',
39 compiled_fs._file_object_store.namespace) 39 compiled_fs._file_object_store.namespace)
40 compiled_fs = factory.GetOrCreateIdentity() # should be the same 40 compiled_fs = factory.GetOrCreateIdentity() # should be the same
41 self.assertEqual('CompiledFileSystem/id/list', 41 self.assertEqual('3-0/CompiledFileSystem@test/id/list',
42 compiled_fs._list_object_store.namespace) 42 compiled_fs._list_object_store.namespace)
43 43
44 def testIdentityFromFile(self): 44 def testIdentityFromFile(self):
45 compiled_fs = _CreateFactory().GetOrCreateIdentity() 45 compiled_fs = _CreateFactory().GetOrCreateIdentity()
46 self.assertEqual('404.html contents', compiled_fs.GetFromFile('404.html')) 46 self.assertEqual('404.html contents', compiled_fs.GetFromFile('404.html'))
47 self.assertEqual('a11y.html contents', 47 self.assertEqual('a11y.html contents',
48 compiled_fs.GetFromFile('apps/a11y.html')) 48 compiled_fs.GetFromFile('apps/a11y.html'))
49 self.assertEqual('file.html contents', 49 self.assertEqual('file.html contents',
50 compiled_fs.GetFromFile('/apps/fakedir/file.html')) 50 compiled_fs.GetFromFile('/apps/fakedir/file.html'))
51 51
(...skipping 10 matching lines...) Expand all
62 set(compiled_fs.GetFromFileListing('apps/'))) 62 set(compiled_fs.GetFromFileListing('apps/')))
63 self.assertEqual(set(('file.html',)), 63 self.assertEqual(set(('file.html',)),
64 set(compiled_fs.GetFromFileListing('apps/fakedir'))) 64 set(compiled_fs.GetFromFileListing('apps/fakedir')))
65 65
66 def testPopulateNamespace(self): 66 def testPopulateNamespace(self):
67 def CheckNamespace(expected_file, expected_list, fs): 67 def CheckNamespace(expected_file, expected_list, fs):
68 self.assertEqual(expected_file, fs._file_object_store.namespace) 68 self.assertEqual(expected_file, fs._file_object_store.namespace)
69 self.assertEqual(expected_list, fs._list_object_store.namespace) 69 self.assertEqual(expected_list, fs._list_object_store.namespace)
70 factory = _CreateFactory() 70 factory = _CreateFactory()
71 f = lambda x: x 71 f = lambda x: x
72 CheckNamespace('CompiledFileSystem/CompiledFileSystemTest/file', 72 CheckNamespace(
73 'CompiledFileSystem/CompiledFileSystemTest/list', 73 '3-0/CompiledFileSystem@test/CompiledFileSystemTest/file',
74 factory.Create(f, CompiledFileSystemTest)) 74 '3-0/CompiledFileSystem@test/CompiledFileSystemTest/list',
75 CheckNamespace('CompiledFileSystem/CompiledFileSystemTest/foo/file', 75 factory.Create(f, CompiledFileSystemTest))
76 'CompiledFileSystem/CompiledFileSystemTest/foo/list', 76 CheckNamespace(
77 factory.Create(f, CompiledFileSystemTest, category='foo')) 77 '3-0/CompiledFileSystem@test/CompiledFileSystemTest/foo/file',
78 CheckNamespace('CompiledFileSystem/CompiledFileSystemTest/file/6', 78 '3-0/CompiledFileSystem@test/CompiledFileSystemTest/foo/list',
79 'CompiledFileSystem/CompiledFileSystemTest/list/6', 79 factory.Create(f, CompiledFileSystemTest, category='foo'))
80 factory.Create(f, CompiledFileSystemTest, version=6))
81 CheckNamespace('CompiledFileSystem/CompiledFileSystemTest/foo/file/6',
82 'CompiledFileSystem/CompiledFileSystemTest/foo/list/6',
83 factory.Create(f, CompiledFileSystemTest, category='foo',
84 version=6))
85 80
86 def testPopulateFromFile(self): 81 def testPopulateFromFile(self):
87 def Sleepy(key, val): 82 def Sleepy(key, val):
88 return '%s%s' % ('Z' * len(key), 'z' * len(val)) 83 return '%s%s' % ('Z' * len(key), 'z' * len(val))
89 compiled_fs = _CreateFactory().Create(Sleepy, CompiledFileSystemTest) 84 compiled_fs = _CreateFactory().Create(Sleepy, CompiledFileSystemTest)
90 self.assertEqual('ZZZZZZZZzzzzzzzzzzzzzzzzz', 85 self.assertEqual('ZZZZZZZZzzzzzzzzzzzzzzzzz',
91 compiled_fs.GetFromFile('404.html')) 86 compiled_fs.GetFromFile('404.html'))
92 self.assertEqual('ZZZZZZZZZZZZZZzzzzzzzzzzzzzzzzzz', 87 self.assertEqual('ZZZZZZZZZZZZZZzzzzzzzzzzzzzzzzzz',
93 compiled_fs.GetFromFile('apps/a11y.html')) 88 compiled_fs.GetFromFile('apps/a11y.html'))
94 self.assertEqual('ZZZZZZZZZZZZZZZZZZZZZZZzzzzzzzzzzzzzzzzzz', 89 self.assertEqual('ZZZZZZZZZZZZZZZZZZZZZZZzzzzzzzzzzzzzzzzzz',
(...skipping 23 matching lines...) Expand all
118 compiled_fs.GetFromFile('apps/') 113 compiled_fs.GetFromFile('apps/')
119 #self.assertRaises(SomeError, compiled_fs.GetFromFile, 'apps/') 114 #self.assertRaises(SomeError, compiled_fs.GetFromFile, 'apps/')
120 self.assertRaises(FileNotFoundError, 115 self.assertRaises(FileNotFoundError,
121 compiled_fs.GetFromFileListing, 'nodir/') 116 compiled_fs.GetFromFileListing, 'nodir/')
122 # TODO(kalman): likewise, not a FileNotFoundError. 117 # TODO(kalman): likewise, not a FileNotFoundError.
123 self.assertRaises(FileNotFoundError, 118 self.assertRaises(FileNotFoundError,
124 compiled_fs.GetFromFileListing, '404.html') 119 compiled_fs.GetFromFileListing, '404.html')
125 120
126 if __name__ == '__main__': 121 if __name__ == '__main__':
127 unittest.main() 122 unittest.main()
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/server2/compiled_file_system.py ('k') | chrome/common/extensions/docs/server2/example_zipper.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698