Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 import json | 6 import json |
| 7 import unittest | 7 import unittest |
| 8 | 8 |
| 9 from compiled_file_system import CompiledFileSystem | 9 from compiled_file_system import CompiledFileSystem |
| 10 from content_providers import ContentProviders | 10 from content_providers import ContentProviders |
| 11 from empty_dir_file_system import EmptyDirFileSystem | |
| 12 from github_file_system_provider import GithubFileSystemProvider | |
|
Jeffrey Yasskin
2013/11/06 04:00:19
I don't think you use this.
not at google - send to devlin
2013/11/06 23:00:13
Done.
| |
| 11 from object_store_creator import ObjectStoreCreator | 13 from object_store_creator import ObjectStoreCreator |
| 12 from test_file_system import TestFileSystem | 14 from test_file_system import TestFileSystem |
| 13 from test_util import DisableLogging | 15 from test_util import DisableLogging |
| 14 | 16 |
| 15 | 17 |
| 16 _HOST = 'https://developer.chrome.com' | 18 _HOST = 'https://developer.chrome.com' |
| 17 | 19 |
| 18 | 20 |
| 19 _CONTENT_PROVIDERS = { | 21 _CONTENT_PROVIDERS = { |
| 20 'apples': { | 22 'apples': { |
| 21 'chromium': { | 23 'chromium': { |
| 22 'dir': 'apples' | 24 'dir': 'apples' |
| 23 }, | 25 }, |
| 24 'serveFrom': 'apples-dir', | 26 'serveFrom': 'apples-dir', |
| 25 }, | 27 }, |
| 26 'bananas': { | 28 'bananas': { |
| 27 'serveFrom': '', | 29 'serveFrom': '', |
| 28 'chromium': { | 30 'chromium': { |
| 29 'dir': '' | 31 'dir': '' |
| 30 }, | 32 }, |
| 31 }, | 33 }, |
| 34 'github-provider': { | |
| 35 'serveFrom': 'gh', | |
| 36 'github': { | |
| 37 'owner': 'GoogleChrome', | |
| 38 'repo': 'hello-world', | |
| 39 }, | |
| 40 }, | |
| 32 'tomatoes': { | 41 'tomatoes': { |
| 33 'serveFrom': 'tomatoes-dir/are/a', | 42 'serveFrom': 'tomatoes-dir/are/a', |
| 34 'chromium': { | 43 'chromium': { |
| 35 'dir': 'tomatoes/are/a' | 44 'dir': 'tomatoes/are/a' |
| 36 }, | 45 }, |
| 37 }, | 46 }, |
| 38 } | 47 } |
| 39 | 48 |
| 40 | 49 |
| 41 _FILE_SYSTEM_DATA = { | 50 _FILE_SYSTEM_DATA = { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 58 'vegetable.txt': 'no they aren\'t', | 67 'vegetable.txt': 'no they aren\'t', |
| 59 'fruit': { | 68 'fruit': { |
| 60 'cherry.txt': 'cherry tomatoes', | 69 'cherry.txt': 'cherry tomatoes', |
| 61 }, | 70 }, |
| 62 }, | 71 }, |
| 63 }, | 72 }, |
| 64 }, | 73 }, |
| 65 } | 74 } |
| 66 | 75 |
| 67 | 76 |
| 77 class _MockGithubFileSystemProvider(object): | |
| 78 '''A GithubFileSystemProvider imitation which records every call to Create | |
| 79 and returns them from GetAndReset. | |
| 80 ''' | |
| 81 | |
| 82 def __init__(self): | |
| 83 self._calls = [] | |
| 84 | |
| 85 def Create(self, owner, repo): | |
| 86 self._calls.append((owner, repo)) | |
| 87 return EmptyDirFileSystem() | |
| 88 | |
| 89 def GetAndReset(self): | |
| 90 calls = self._calls | |
| 91 self._calls = [] | |
| 92 return calls | |
| 93 | |
| 94 | |
| 68 class ContentProvidersTest(unittest.TestCase): | 95 class ContentProvidersTest(unittest.TestCase): |
| 69 def setUp(self): | 96 def setUp(self): |
| 97 self._github_fs_provider = _MockGithubFileSystemProvider() | |
| 70 self._content_providers = ContentProviders( | 98 self._content_providers = ContentProviders( |
| 71 CompiledFileSystem.Factory(ObjectStoreCreator.ForTest()), | 99 CompiledFileSystem.Factory(ObjectStoreCreator.ForTest()), |
| 72 TestFileSystem(_FILE_SYSTEM_DATA)) | 100 TestFileSystem(_FILE_SYSTEM_DATA), |
| 101 self._github_fs_provider) | |
| 73 | 102 |
| 74 def testSimpleRootPath(self): | 103 def testSimpleRootPath(self): |
| 75 provider = self._content_providers.GetByName('apples') | 104 provider = self._content_providers.GetByName('apples') |
| 76 self.assertEqual( | 105 self.assertEqual( |
| 77 'gala apples', | 106 'gala apples', |
| 78 provider.GetContentAndType(_HOST, 'gala.txt').Get().content) | 107 provider.GetContentAndType(_HOST, 'gala.txt').Get().content) |
| 79 self.assertEqual( | 108 self.assertEqual( |
| 80 'granny smith apples', | 109 'granny smith apples', |
| 81 provider.GetContentAndType(_HOST, 'green/granny smith.txt').Get() | 110 provider.GetContentAndType(_HOST, 'green/granny smith.txt').Get() |
| 82 .content) | 111 .content) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 self.assertEqual('bananas', provider.name) | 149 self.assertEqual('bananas', provider.name) |
| 121 self.assertEqual('tomatoes-dir/are', path) | 150 self.assertEqual('tomatoes-dir/are', path) |
| 122 provider, path = self._content_providers.GetByServeFrom('') | 151 provider, path = self._content_providers.GetByServeFrom('') |
| 123 self.assertEqual('bananas', provider.name) | 152 self.assertEqual('bananas', provider.name) |
| 124 self.assertEqual('', path) | 153 self.assertEqual('', path) |
| 125 | 154 |
| 126 @DisableLogging('error') | 155 @DisableLogging('error') |
| 127 def testProviderNotFound(self): | 156 def testProviderNotFound(self): |
| 128 self.assertEqual(None, self._content_providers.GetByName('cabbages')) | 157 self.assertEqual(None, self._content_providers.GetByName('cabbages')) |
| 129 | 158 |
| 159 def testGithubContentProvider(self): | |
| 160 provider, path = self._content_providers.GetByServeFrom('gh/some/path') | |
| 161 self.assertEqual('github-provider', provider.name) | |
| 162 self.assertEqual('some/path', path) | |
| 163 self.assertEqual([('GoogleChrome', 'hello-world')], | |
| 164 self._github_fs_provider.GetAndReset()) | |
| 165 | |
| 130 | 166 |
| 131 if __name__ == '__main__': | 167 if __name__ == '__main__': |
| 132 unittest.main() | 168 unittest.main() |
| OLD | NEW |