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

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

Issue 15009006: Docserver: refactor Servlet, ObjectStore, and ServerInstance architecture to (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cduvall, redirect fix Created 7 years, 7 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 appengine_wrappers import GetAppVersion
6 from compiled_file_system import CompiledFileSystem 7 from compiled_file_system import CompiledFileSystem
7 from copy import deepcopy 8 from copy import deepcopy
8 from file_system import FileNotFoundError 9 from file_system import FileNotFoundError
9 from object_store_creator import ObjectStoreCreator 10 from object_store_creator import ObjectStoreCreator
10 from test_file_system import TestFileSystem 11 from test_file_system import TestFileSystem
11 from test_object_store import TestObjectStore 12 from test_object_store import TestObjectStore
12 import unittest 13 import unittest
13 14
14 _TEST_DATA = { 15 _TEST_DATA = {
15 '404.html': '404.html contents', 16 '404.html': '404.html contents',
16 'apps': { 17 'apps': {
17 'a11y.html': 'a11y.html contents', 18 'a11y.html': 'a11y.html contents',
18 'about_apps.html': 'about_apps.html contents', 19 'about_apps.html': 'about_apps.html contents',
19 'fakedir': { 20 'fakedir': {
20 'file.html': 'file.html contents' 21 'file.html': 'file.html contents'
21 } 22 }
22 }, 23 },
23 'extensions': { 24 'extensions': {
24 'activeTab.html': 'activeTab.html contents', 25 'activeTab.html': 'activeTab.html contents',
25 'alarms.html': 'alarms.html contents' 26 'alarms.html': 'alarms.html contents'
26 } 27 }
27 } 28 }
28 29
29 def _CreateFactory(): 30 def _CreateFactory():
30 return CompiledFileSystem.Factory( 31 return CompiledFileSystem.Factory(
31 TestFileSystem(deepcopy(_TEST_DATA)), 32 TestFileSystem(deepcopy(_TEST_DATA)),
32 ObjectStoreCreator.TestFactory(version='3-0', branch='test')) 33 ObjectStoreCreator('test',
34 start_empty=False,
35 store_type=TestObjectStore,
36 disable_wrappers=True))
33 37
34 class CompiledFileSystemTest(unittest.TestCase): 38 class CompiledFileSystemTest(unittest.TestCase):
35 def testIdentityNamespace(self): 39 def testIdentityNamespace(self):
36 factory = _CreateFactory() 40 factory = _CreateFactory()
37 compiled_fs = factory.CreateIdentity(CompiledFileSystemTest) 41 compiled_fs = factory.CreateIdentity(CompiledFileSystemTest)
38 self.assertEqual('3-0/CompiledFileSystem@test/CompiledFileSystemTest/file', 42 self.assertEqual(
39 compiled_fs._file_object_store.namespace) 43 'class=CompiledFileSystem&category=CompiledFileSystemTest/file&'
44 'channel=test&app_version=%s' % GetAppVersion(),
45 compiled_fs._file_object_store.namespace)
40 46
41 def testIdentityFromFile(self): 47 def testIdentityFromFile(self):
42 compiled_fs = _CreateFactory().CreateIdentity(CompiledFileSystemTest) 48 compiled_fs = _CreateFactory().CreateIdentity(CompiledFileSystemTest)
43 self.assertEqual('404.html contents', compiled_fs.GetFromFile('404.html')) 49 self.assertEqual('404.html contents', compiled_fs.GetFromFile('404.html'))
44 self.assertEqual('a11y.html contents', 50 self.assertEqual('a11y.html contents',
45 compiled_fs.GetFromFile('apps/a11y.html')) 51 compiled_fs.GetFromFile('apps/a11y.html'))
46 self.assertEqual('file.html contents', 52 self.assertEqual('file.html contents',
47 compiled_fs.GetFromFile('/apps/fakedir/file.html')) 53 compiled_fs.GetFromFile('/apps/fakedir/file.html'))
48 54
49 def testIdentityFromFileListing(self): 55 def testIdentityFromFileListing(self):
(...skipping 10 matching lines...) Expand all
60 self.assertEqual(set(('file.html',)), 66 self.assertEqual(set(('file.html',)),
61 set(compiled_fs.GetFromFileListing('apps/fakedir'))) 67 set(compiled_fs.GetFromFileListing('apps/fakedir')))
62 68
63 def testPopulateNamespace(self): 69 def testPopulateNamespace(self):
64 def CheckNamespace(expected_file, expected_list, fs): 70 def CheckNamespace(expected_file, expected_list, fs):
65 self.assertEqual(expected_file, fs._file_object_store.namespace) 71 self.assertEqual(expected_file, fs._file_object_store.namespace)
66 self.assertEqual(expected_list, fs._list_object_store.namespace) 72 self.assertEqual(expected_list, fs._list_object_store.namespace)
67 factory = _CreateFactory() 73 factory = _CreateFactory()
68 f = lambda x: x 74 f = lambda x: x
69 CheckNamespace( 75 CheckNamespace(
70 '3-0/CompiledFileSystem@test/CompiledFileSystemTest/file', 76 'class=CompiledFileSystem&category=CompiledFileSystemTest/file&'
71 '3-0/CompiledFileSystem@test/CompiledFileSystemTest/list', 77 'channel=test&app_version=%s' % GetAppVersion(),
78 'class=CompiledFileSystem&category=CompiledFileSystemTest/list&'
79 'channel=test&app_version=%s' % GetAppVersion(),
72 factory.Create(f, CompiledFileSystemTest)) 80 factory.Create(f, CompiledFileSystemTest))
73 CheckNamespace( 81 CheckNamespace(
74 '3-0/CompiledFileSystem@test/CompiledFileSystemTest/foo/file', 82 'class=CompiledFileSystem&category=CompiledFileSystemTest/foo/file&'
75 '3-0/CompiledFileSystem@test/CompiledFileSystemTest/foo/list', 83 'channel=test&app_version=%s' % GetAppVersion(),
84 'class=CompiledFileSystem&category=CompiledFileSystemTest/foo/list&'
85 'channel=test&app_version=%s' % GetAppVersion(),
76 factory.Create(f, CompiledFileSystemTest, category='foo')) 86 factory.Create(f, CompiledFileSystemTest, category='foo'))
77 87
78 def testPopulateFromFile(self): 88 def testPopulateFromFile(self):
79 def Sleepy(key, val): 89 def Sleepy(key, val):
80 return '%s%s' % ('Z' * len(key), 'z' * len(val)) 90 return '%s%s' % ('Z' * len(key), 'z' * len(val))
81 compiled_fs = _CreateFactory().Create(Sleepy, CompiledFileSystemTest) 91 compiled_fs = _CreateFactory().Create(Sleepy, CompiledFileSystemTest)
82 self.assertEqual('ZZZZZZZZzzzzzzzzzzzzzzzzz', 92 self.assertEqual('ZZZZZZZZzzzzzzzzzzzzzzzzz',
83 compiled_fs.GetFromFile('404.html')) 93 compiled_fs.GetFromFile('404.html'))
84 self.assertEqual('ZZZZZZZZZZZZZZzzzzzzzzzzzzzzzzzz', 94 self.assertEqual('ZZZZZZZZZZZZZZzzzzzzzzzzzzzzzzzz',
85 compiled_fs.GetFromFile('apps/a11y.html')) 95 compiled_fs.GetFromFile('apps/a11y.html'))
(...skipping 24 matching lines...) Expand all
110 compiled_fs.GetFromFile('apps/') 120 compiled_fs.GetFromFile('apps/')
111 #self.assertRaises(SomeError, compiled_fs.GetFromFile, 'apps/') 121 #self.assertRaises(SomeError, compiled_fs.GetFromFile, 'apps/')
112 self.assertRaises(FileNotFoundError, 122 self.assertRaises(FileNotFoundError,
113 compiled_fs.GetFromFileListing, 'nodir/') 123 compiled_fs.GetFromFileListing, 'nodir/')
114 # TODO(kalman): likewise, not a FileNotFoundError. 124 # TODO(kalman): likewise, not a FileNotFoundError.
115 self.assertRaises(FileNotFoundError, 125 self.assertRaises(FileNotFoundError,
116 compiled_fs.GetFromFileListing, '404.html') 126 compiled_fs.GetFromFileListing, '404.html')
117 127
118 if __name__ == '__main__': 128 if __name__ == '__main__':
119 unittest.main() 129 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698