OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 import os | 6 import os |
7 import unittest | 7 import unittest |
8 | 8 |
9 from appengine_memcache import AppEngineMemcache | 9 from in_memory_object_store import InMemoryObjectStore |
not at google - send to devlin
2012/08/21 00:30:11
import order
cduvall
2012/08/21 01:33:33
Done.
| |
10 from fake_url_fetcher import FakeUrlFetcher | 10 from fake_url_fetcher import FakeUrlFetcher |
11 from github_file_system import GithubFileSystem | 11 from github_file_system import GithubFileSystem |
12 | 12 |
13 class FakeBlobstore(object): | 13 class FakeBlobstore(object): |
14 def Set(self, blob, key, version): | 14 def Set(self, blob, key, version): |
15 return None | 15 return None |
16 | 16 |
17 def Get(self, key, version): | 17 def Get(self, key, version): |
18 return None | 18 return None |
19 | 19 |
20 def Delete(self, key, version): | 20 def Delete(self, key, version): |
21 return None | 21 return None |
22 | 22 |
23 class FakeGithubFetcher(FakeUrlFetcher): | 23 class FakeGithubFetcher(FakeUrlFetcher): |
24 class _Response(object): | 24 class _Response(object): |
25 def __init__(self, content): | 25 def __init__(self, content): |
26 self.content = content | 26 self.content = content |
27 | 27 |
28 def Fetch(self, path): | 28 def Fetch(self, path): |
29 if path == 'zipball': | 29 if path == 'zipball': |
30 return super(FakeGithubFetcher, self).Fetch('file_system.zip') | 30 return super(FakeGithubFetcher, self).Fetch('file_system.zip') |
31 return self._Response('{ "commit": { "tree": { "sha": 0 } } }') | 31 return self._Response('{ "commit": { "tree": { "sha": 0 } } }') |
32 | 32 |
33 class GithubFileSystemTest(unittest.TestCase): | 33 class GithubFileSystemTest(unittest.TestCase): |
34 def setUp(self): | 34 def setUp(self): |
35 self._file_system = GithubFileSystem(FakeGithubFetcher('test_data'), | 35 self._file_system = GithubFileSystem(FakeGithubFetcher('test_data'), |
36 AppEngineMemcache('test'), | 36 InMemoryObjectStore('test'), |
37 FakeBlobstore()) | 37 FakeBlobstore()) |
38 | 38 |
39 def testReadFiles(self): | 39 def testReadFiles(self): |
40 expected = { | 40 expected = { |
41 '/test1.txt': 'test1\n', | 41 '/test1.txt': 'test1\n', |
42 '/test2.txt': 'test2\n', | 42 '/test2.txt': 'test2\n', |
43 '/test3.txt': 'test3\n', | 43 '/test3.txt': 'test3\n', |
44 } | 44 } |
45 self.assertEqual( | 45 self.assertEqual( |
46 expected, | 46 expected, |
47 self._file_system.Read( | 47 self._file_system.Read( |
48 ['/test1.txt', '/test2.txt', '/test3.txt']).Get()) | 48 ['/test1.txt', '/test2.txt', '/test3.txt']).Get()) |
49 | 49 |
50 def testListDir(self): | 50 def testListDir(self): |
51 expected = ['dir/'] | 51 expected = ['dir/'] |
52 for i in range(7): | 52 for i in range(7): |
53 expected.append('file%d.html' % i) | 53 expected.append('file%d.html' % i) |
54 self.assertEqual(expected, | 54 self.assertEqual(expected, |
55 sorted(self._file_system.ReadSingle('/list/'))) | 55 sorted(self._file_system.ReadSingle('/list/'))) |
56 | 56 |
57 if __name__ == '__main__': | 57 if __name__ == '__main__': |
58 unittest.main() | 58 unittest.main() |
OLD | NEW |