Index: chrome/common/extensions/docs/server2/zip_file_system_test.py |
diff --git a/chrome/common/extensions/docs/server2/zip_file_system_test.py b/chrome/common/extensions/docs/server2/zip_file_system_test.py |
new file mode 100755 |
index 0000000000000000000000000000000000000000..f93a345dd5f9b78ad926aacfbca234767df589b5 |
--- /dev/null |
+++ b/chrome/common/extensions/docs/server2/zip_file_system_test.py |
@@ -0,0 +1,47 @@ |
+#!/usr/bin/env python |
+# Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+import os |
+import unittest |
+ |
+from zip_file_system import ZipFileSystem |
+ |
+class FakeFetcher(object): |
+ def __init__(self, base_path): |
+ self._base_path = base_path |
+ |
+ def _ReadFile(self, filename): |
+ with open(os.path.join(self._base_path, filename), 'r') as f: |
+ return f.read() |
+ |
+ def Fetch(self, path): |
+ if path == 'zipball': |
+ return self._ReadFile('file_system.zip') |
+ return '[ { "sha": 0 } ]' |
+ |
+class ZipFileSystemTest(unittest.TestCase): |
+ def setUp(self): |
+ self._file_system = ZipFileSystem(FakeFetcher('test_data')) |
+ |
+ def testReadFiles(self): |
+ expected = { |
+ '/test1.txt': 'test1\n', |
+ '/test2.txt': 'test2\n', |
+ '/test3.txt': 'test3\n', |
+ } |
+ self.assertEqual( |
+ expected, |
+ self._file_system.Read( |
+ ['/test1.txt', '/test2.txt', '/test3.txt']).Get()) |
+ |
+ def testListDir(self): |
+ expected = ['dir/'] |
+ for i in range(7): |
+ expected.append('file%d.html' % i) |
+ self.assertEqual(expected, |
+ sorted(self._file_system.ReadSingle('/list/'))) |
+ |
+if __name__ == '__main__': |
+ unittest.main() |