def setUp(self): test_file_system = TestFileSystem(_FILE_SYSTEM_DATA) self._github_fs_provider = _MockGithubFileSystemProvider( test_file_system) self._content_providers = ContentProviders( CompiledFileSystem.Factory(ObjectStoreCreator.ForTest()), test_file_system, self._github_fs_provider)
def setUp(self): object_store_creator = ObjectStoreCreator.ForTest() test_file_system = TestFileSystem(_FILE_SYSTEM_DATA, relative_to=CHROME_EXTENSIONS) object_store_creator = ObjectStoreCreator.ForTest() # TODO(mangini): create tests for GCS self._gcs_fs_provider = CloudStorageFileSystemProvider(object_store_creator) self._content_providers = ContentProviders( object_store_creator, CompiledFileSystem.Factory(object_store_creator), test_file_system, self._gcs_fs_provider)
class ContentProvidersTest(unittest.TestCase): def setUp(self): test_file_system = TestFileSystem(_FILE_SYSTEM_DATA) self._github_fs_provider = _MockGithubFileSystemProvider( test_file_system) self._content_providers = ContentProviders( CompiledFileSystem.Factory(ObjectStoreCreator.ForTest()), test_file_system, self._github_fs_provider) def testSimpleRootPath(self): provider = self._content_providers.GetByName('apples') self.assertEqual( 'gala apples', provider.GetContentAndType(_HOST, 'gala.txt').Get().content) self.assertEqual( 'granny smith apples', provider.GetContentAndType(_HOST, 'green/granny smith.txt').Get().content) def testComplexRootPath(self): provider = self._content_providers.GetByName('tomatoes') self.assertEqual( 'no they aren\'t', provider.GetContentAndType(_HOST, 'vegetable.txt').Get().content) self.assertEqual( 'cherry tomatoes', provider.GetContentAndType(_HOST, 'fruit/cherry.txt').Get().content) def testEmptyRootPath(self): provider = self._content_providers.GetByName('bananas') self.assertEqual( 'gala apples', provider.GetContentAndType(_HOST, 'apples/gala.txt').Get().content) def testSimpleServlet(self): provider, path = self._content_providers.GetByServeFrom('apples-dir') self.assertEqual('apples', provider.name) self.assertEqual('', path) provider, path = self._content_providers.GetByServeFrom( 'apples-dir/are/forever') self.assertEqual('apples', provider.name) self.assertEqual('are/forever', path) def testComplexServlet(self): provider, path = self._content_providers.GetByServeFrom( 'tomatoes-dir/are/a') self.assertEqual('tomatoes', provider.name) self.assertEqual('', path) provider, path = self._content_providers.GetByServeFrom( 'tomatoes-dir/are/a/fruit/they/are') self.assertEqual('tomatoes', provider.name) self.assertEqual('fruit/they/are', path) def testEmptyStringServlet(self): provider, path = self._content_providers.GetByServeFrom( 'tomatoes-dir/are') self.assertEqual('bananas', provider.name) self.assertEqual('tomatoes-dir/are', path) provider, path = self._content_providers.GetByServeFrom('') self.assertEqual('bananas', provider.name) self.assertEqual('', path) @DisableLogging('error') def testProviderNotFound(self): self.assertEqual(None, self._content_providers.GetByName('cabbages')) def testGithubContentProvider(self): provider, path = self._content_providers.GetByServeFrom( 'gh/apples/green/granny smith.txt') self.assertEqual('github-provider', provider.name) self.assertEqual('apples/green/granny smith.txt', path) self.assertEqual([('GoogleChrome', 'hello-world')], self._github_fs_provider.GetAndReset()) self.assertEqual('granny smith apples', provider.GetContentAndType(_HOST, path).Get().content) def testGithubContentProviderWithDir(self): provider, path = self._content_providers.GetByServeFrom( 'gh2/fruit/cherry.txt') self.assertEqual('github-provider-with-dir', provider.name) self.assertEqual('fruit/cherry.txt', path) self.assertEqual([('SomeOwner', 'some-repo')], self._github_fs_provider.GetAndReset()) self.assertEqual('cherry tomatoes', provider.GetContentAndType(_HOST, path).Get().content)
def __init__(self, object_store_creator, compiled_fs_factory, branch_utility, host_file_system_provider, github_file_system_provider, gcs_file_system_provider, base_path='/'): ''' |object_store_creator| The ObjectStoreCreator used to create almost all caches. |compiled_fs_factory| Factory used to create CompiledFileSystems, a higher-level cache type than ObjectStores. This can usually be derived from just |object_store_creator| but under special circumstances a different implementation needs to be passed in. |branch_utility| Has knowledge of Chrome branches, channels, and versions. |host_file_system_provider| Creates FileSystem instances which host the server at alternative revisions. |github_file_system_provider| Creates FileSystem instances backed by GitHub. |base_path| The path which all HTML is generated relative to. Usually this is / but some servlets need to override this. ''' self.object_store_creator = object_store_creator self.compiled_fs_factory = compiled_fs_factory self.host_file_system_provider = host_file_system_provider host_fs_at_trunk = host_file_system_provider.GetTrunk() self.github_file_system_provider = github_file_system_provider self.gcs_file_system_provider = gcs_file_system_provider assert base_path.startswith('/') and base_path.endswith('/') self.base_path = base_path self.host_file_system_iterator = HostFileSystemIterator( host_file_system_provider, branch_utility) self.features_bundle = FeaturesBundle( host_fs_at_trunk, self.compiled_fs_factory, self.object_store_creator) self.api_models = APIModels( self.features_bundle, self.compiled_fs_factory, host_fs_at_trunk) self.availability_finder = AvailabilityFinder( branch_utility, compiled_fs_factory, self.host_file_system_iterator, host_fs_at_trunk, object_store_creator) self.api_categorizer = APICategorizer( host_fs_at_trunk, compiled_fs_factory) self.api_data_source_factory = APIDataSource.Factory( self.compiled_fs_factory, host_fs_at_trunk, self.availability_finder, self.api_models, self.features_bundle, self.object_store_creator) self.ref_resolver_factory = ReferenceResolver.Factory( self.api_data_source_factory, self.api_models, object_store_creator) self.api_data_source_factory.SetReferenceResolverFactory( self.ref_resolver_factory) # Note: samples are super slow in the dev server because it doesn't support # async fetch, so disable them. if IsDevServer(): extension_samples_fs = EmptyDirFileSystem() app_samples_fs = EmptyDirFileSystem() else: extension_samples_fs = host_fs_at_trunk # TODO(kalman): Re-enable the apps samples, see http://crbug.com/344097. app_samples_fs = EmptyDirFileSystem() #app_samples_fs = github_file_system_provider.Create( # 'GoogleChrome', 'chrome-app-samples') self.samples_data_source_factory = SamplesDataSource.Factory( extension_samples_fs, app_samples_fs, CompiledFileSystem.Factory(object_store_creator), self.ref_resolver_factory, base_path) self.api_data_source_factory.SetSamplesDataSourceFactory( self.samples_data_source_factory) self.content_providers = ContentProviders( object_store_creator, self.compiled_fs_factory, host_fs_at_trunk, self.github_file_system_provider, self.gcs_file_system_provider) # TODO(kalman): Move all the remaining DataSources into DataSourceRegistry, # then factor out the DataSource creation into a factory method, so that # the entire ServerInstance doesn't need to be passed in here. self.template_renderer = TemplateRenderer(self) # TODO(kalman): It may be better for |document_renderer| to construct a # TemplateDataSource itself rather than depending on template_renderer, but # for that the above todo should be addressed. self.document_renderer = DocumentRenderer( TableOfContentsRenderer(host_fs_at_trunk, compiled_fs_factory, self.template_renderer), self.ref_resolver_factory.Create())
class ContentProvidersTest(unittest.TestCase): def setUp(self): object_store_creator = ObjectStoreCreator.ForTest() test_file_system = TestFileSystem(_FILE_SYSTEM_DATA, relative_to=CHROME_EXTENSIONS) self._github_fs_provider = _MockGithubFileSystemProvider(test_file_system) object_store_creator = ObjectStoreCreator.ForTest() # TODO(mangini): create tests for GCS self._gcs_fs_provider = CloudStorageFileSystemProvider(object_store_creator) self._content_providers = ContentProviders( object_store_creator, CompiledFileSystem.Factory(object_store_creator), test_file_system, self._github_fs_provider, self._gcs_fs_provider) def testSimpleRootPath(self): provider = self._content_providers.GetByName('apples') self.assertEqual( 'gala apples', provider.GetContentAndType('gala.txt').Get().content) self.assertEqual( 'granny smith apples', provider.GetContentAndType('green/granny smith.txt').Get().content) def testComplexRootPath(self): provider = self._content_providers.GetByName('tomatoes') self.assertEqual( 'no they aren\'t', provider.GetContentAndType('vegetable.txt').Get().content) self.assertEqual( 'cherry tomatoes', provider.GetContentAndType('fruit/cherry.txt').Get().content) def testParentRootPath(self): provider = self._content_providers.GetByName('bananas') self.assertEqual( 'gala apples', provider.GetContentAndType('apples/gala.txt').Get().content) def testSimpleServlet(self): provider, serve_from, path = self._content_providers.GetByServeFrom( 'apples-dir') self.assertEqual('apples', provider.name) self.assertEqual('apples-dir', serve_from) self.assertEqual('', path) provider, serve_from, path = self._content_providers.GetByServeFrom( 'apples-dir/') self.assertEqual('apples', provider.name) self.assertEqual('apples-dir', serve_from) self.assertEqual('', path) provider, serve_from, path = self._content_providers.GetByServeFrom( 'apples-dir/are/forever') self.assertEqual('apples', provider.name) self.assertEqual('apples-dir', serve_from) self.assertEqual('are/forever', path) def testComplexServlet(self): provider, serve_from, path = self._content_providers.GetByServeFrom( 'tomatoes-dir/are/a') self.assertEqual('tomatoes', provider.name) self.assertEqual('tomatoes-dir/are/a', serve_from) self.assertEqual('', path) provider, serve_from, path = self._content_providers.GetByServeFrom( 'tomatoes-dir/are/a/fruit/they/are') self.assertEqual('tomatoes', provider.name) self.assertEqual('tomatoes-dir/are/a', serve_from) self.assertEqual('fruit/they/are', path) def testEmptyStringServlet(self): provider, serve_from, path = self._content_providers.GetByServeFrom( 'tomatoes-dir/are') self.assertEqual('bananas', provider.name) self.assertEqual('', serve_from) self.assertEqual('tomatoes-dir/are', path) provider, serve_from, path = self._content_providers.GetByServeFrom('') self.assertEqual('bananas', provider.name) self.assertEqual('', serve_from) self.assertEqual('', path) @DisableLogging('error') def testProviderNotFound(self): self.assertEqual(None, self._content_providers.GetByName('cabbages')) def testGithubContentProvider(self): provider, serve_from, path = self._content_providers.GetByServeFrom( 'gh/apples/green/granny smith.txt') self.assertEqual('github-provider', provider.name) self.assertEqual('gh', serve_from) self.assertEqual('apples/green/granny smith.txt', path) self.assertEqual([('GoogleChrome', 'hello-world')], self._github_fs_provider.GetAndReset()) self.assertEqual( 'granny smith apples', provider.GetContentAndType(path).Get().content) def testGithubContentProviderWithDir(self): provider, serve_from, path = self._content_providers.GetByServeFrom( 'gh2/fruit/cherry.txt') self.assertEqual('github-provider-with-dir', provider.name) self.assertEqual('gh2', serve_from) self.assertEqual('fruit/cherry.txt', path) self.assertEqual([('SomeOwner', 'some-repo')], self._github_fs_provider.GetAndReset()) self.assertEqual( 'cherry tomatoes', provider.GetContentAndType(path).Get().content)
def __init__(self, object_store_creator, compiled_fs_factory, branch_utility, host_file_system_provider, gcs_file_system_provider, base_path='/'): ''' |object_store_creator| The ObjectStoreCreator used to create almost all caches. |compiled_fs_factory| Factory used to create CompiledFileSystems, a higher-level cache type than ObjectStores. This can usually be derived from just |object_store_creator| but under special circumstances a different implementation needs to be passed in. |branch_utility| Has knowledge of Chrome branches, channels, and versions. |host_file_system_provider| Creates FileSystem instances which host the server at alternative revisions. |base_path| The path which all HTML is generated relative to. Usually this is / but some servlets need to override this. ''' self.object_store_creator = object_store_creator self.compiled_fs_factory = compiled_fs_factory self.host_file_system_provider = host_file_system_provider host_fs_at_master = host_file_system_provider.GetMaster() self.gcs_file_system_provider = gcs_file_system_provider assert base_path.startswith('/') and base_path.endswith('/') self.base_path = base_path self.host_file_system_iterator = HostFileSystemIterator( host_file_system_provider, branch_utility) self.platform_bundle = PlatformBundle(branch_utility, self.compiled_fs_factory, host_fs_at_master, self.host_file_system_iterator, self.object_store_creator, self.base_path) self.content_providers = ContentProviders( object_store_creator, self.compiled_fs_factory, host_fs_at_master, self.gcs_file_system_provider) # TODO(kalman): Move all the remaining DataSources into DataSourceRegistry, # then factor out the DataSource creation into a factory method, so that # the entire ServerInstance doesn't need to be passed in here. self.template_renderer = TemplateRenderer(self) # TODO(kalman): It may be better for |document_renderer| to construct a # TemplateDataSource itself rather than depending on template_renderer, but # for that the above todo should be addressed. self.document_renderer = DocumentRenderer( TableOfContentsRenderer(host_fs_at_master, compiled_fs_factory, self.template_renderer), self.platform_bundle)
def __init__(self, object_store_creator, compiled_fs_factory, branch_utility, host_file_system_provider, github_file_system_provider, base_path='/'): ''' |object_store_creator| The ObjectStoreCreator used to create almost all caches. |compiled_fs_factory| Factory used to create CompiledFileSystems, a higher-level cache type than ObjectStores. This can usually be derived from just |object_store_creator| but under special circumstances a different implementation needs to be passed in. |branch_utility| Has knowledge of Chrome branches, channels, and versions. |host_file_system_provider| Creates FileSystem instances which host the server at alternative revisions. |github_file_system_provider| Creates FileSystem instances backed by GitHub. |base_path| The path which all HTML is generated relative to. Usually this is / but some servlets need to override this. ''' self.object_store_creator = object_store_creator self.compiled_fs_factory = compiled_fs_factory self.host_file_system_provider = host_file_system_provider host_fs_at_trunk = host_file_system_provider.GetTrunk() self.github_file_system_provider = github_file_system_provider assert base_path.startswith('/') and base_path.endswith('/') self.base_path = base_path self.host_file_system_iterator = HostFileSystemIterator( host_file_system_provider, branch_utility) self.features_bundle = FeaturesBundle(host_fs_at_trunk, self.compiled_fs_factory, self.object_store_creator) self.api_models = APIModels(self.features_bundle, self.compiled_fs_factory, host_fs_at_trunk) self.availability_finder = AvailabilityFinder( branch_utility, compiled_fs_factory, self.host_file_system_iterator, host_fs_at_trunk, object_store_creator) self.api_list_data_source_factory = APIListDataSource.Factory( self.compiled_fs_factory, host_fs_at_trunk, self.features_bundle, self.object_store_creator) self.api_data_source_factory = APIDataSource.Factory( self.compiled_fs_factory, host_fs_at_trunk, svn_constants.API_PATH, self.availability_finder, branch_utility) self.ref_resolver_factory = ReferenceResolver.Factory( self.api_data_source_factory, self.api_models, object_store_creator) self.api_data_source_factory.SetReferenceResolverFactory( self.ref_resolver_factory) # Note: samples are super slow in the dev server because it doesn't support # async fetch, so disable them. if IsDevServer(): extension_samples_fs = EmptyDirFileSystem() app_samples_fs = EmptyDirFileSystem() else: extension_samples_fs = host_fs_at_trunk app_samples_fs = github_file_system_provider.Create( 'GoogleChrome', 'chrome-app-samples') self.samples_data_source_factory = SamplesDataSource.Factory( extension_samples_fs, app_samples_fs, CompiledFileSystem.Factory(object_store_creator), self.ref_resolver_factory, svn_constants.EXAMPLES_PATH, base_path) self.api_data_source_factory.SetSamplesDataSourceFactory( self.samples_data_source_factory) self.intro_data_source_factory = IntroDataSource.Factory( self.compiled_fs_factory, host_fs_at_trunk, self.ref_resolver_factory, [svn_constants.INTRO_PATH, svn_constants.ARTICLE_PATH]) self.path_canonicalizer = PathCanonicalizer(self.compiled_fs_factory, host_fs_at_trunk) self.content_providers = ContentProviders( self.compiled_fs_factory, host_fs_at_trunk, self.github_file_system_provider) # TODO(kalman): Move all the remaining DataSources into DataSourceRegistry, # then factor out the DataSource creation into a factory method, so that # the entire ServerInstance doesn't need to be passed in here. self.template_renderer = TemplateRenderer(self) self.strings_json_path = svn_constants.STRINGS_JSON_PATH self.manifest_json_path = svn_constants.MANIFEST_JSON_PATH self.manifest_features_path = svn_constants.MANIFEST_FEATURES_PATH