Exemple #1
0
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)
Exemple #2
0
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)