class SubversionFileSystemTest(unittest.TestCase):
    def setUp(self):
        self._base_path = os.path.join(sys.path[0], 'test_data', 'file_system')
        fetcher = FakeUrlFetcher(self._base_path)
        self._file_system = SubversionFileSystem(fetcher, fetcher)

    def _ReadLocalFile(self, filename):
        with open(os.path.join(self._base_path, filename), 'r') as f:
            return f.read()

    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/')))

    def testStat(self):
        stat_info = self._file_system.Stat('stat/')
        self.assertEquals('151113', stat_info.version)
        self.assertEquals(json.loads(self._ReadLocalFile('stat_result.json')),
                          stat_info.child_versions)
示例#2
0
    def CreateOnline(channel):
        '''Creates/creates an online server instance, meaning that both local and
    subversion/github resources are queried.
    '''
        branch_utility = ServerInstance._GetOrCreateBranchUtility()
        branch = branch_utility.GetBranchNumberForChannelName(channel)

        if branch == 'trunk':
            svn_url = '/'.join((url_constants.SVN_TRUNK_URL, 'src',
                                svn_constants.EXTENSIONS_PATH))
        else:
            svn_url = '/'.join((url_constants.SVN_BRANCH_URL, branch, 'src',
                                svn_constants.EXTENSIONS_PATH))

        viewvc_url = svn_url.replace(url_constants.SVN_URL,
                                     url_constants.VIEWVC_URL)

        object_store_creator_factory = ObjectStoreCreator.Factory(
            GetAppVersion(), branch, start_empty=True)

        svn_file_system = CachingFileSystem(
            SubversionFileSystem(AppEngineUrlFetcher(svn_url),
                                 AppEngineUrlFetcher(viewvc_url)),
            object_store_creator_factory)

        return ServerInstance(channel, object_store_creator_factory,
                              svn_file_system,
                              ServerInstance._GetOrCreateGithubFileSystem())
示例#3
0
文件: handler.py 项目: ftanx/k2cro4
def _CreateMemcacheFileSystem(branch, branch_memcache):
    svn_url = _GetURLFromBranch(branch) + '/' + EXTENSIONS_PATH
    stat_fetcher = AppEngineUrlFetcher(
        svn_url.replace(url_constants.SVN_URL, url_constants.VIEWVC_URL))
    fetcher = AppEngineUrlFetcher(svn_url)
    return MemcacheFileSystem(SubversionFileSystem(fetcher, stat_fetcher),
                              branch_memcache)
示例#4
0
  def testRevisions(self):
    # This is a super hacky test. Record the path that was fetched then exit the
    # test. Compare.
    class ValueErrorFetcher(object):
      def __init__(self):
        self.last_fetched = None

      def FetchAsync(self, path):
        self.last_fetched = path
        raise ValueError()

      def Fetch(self, path):
        self.last_fetched = path
        raise ValueError()

    file_fetcher = ValueErrorFetcher()
    stat_fetcher = ValueErrorFetcher()
    svn_path = 'svn:'

    svn_file_system = SubversionFileSystem(file_fetcher,
                                           stat_fetcher,
                                           svn_path,
                                           revision=42)

    self.assertRaises(ValueError, svn_file_system.ReadSingle, 'dir/file')
    self.assertEqual('dir/file?p=42', file_fetcher.last_fetched)
    # Stat() will always stat directories.
    self.assertRaises(ValueError, svn_file_system.Stat, 'dir/file')
    self.assertEqual('dir/?pathrev=42', stat_fetcher.last_fetched)

    self.assertRaises(ValueError, svn_file_system.ReadSingle, 'dir/')
    self.assertEqual('dir/?p=42', file_fetcher.last_fetched)
    self.assertRaises(ValueError, svn_file_system.Stat, 'dir/')
    self.assertEqual('dir/?pathrev=42', stat_fetcher.last_fetched)
示例#5
0
 def Create(self, branch='trunk', revision=None, offline=None):
     '''Creates either SVN file systems or specialized file systems from the
 constructor passed into this instance. Wraps the resulting file system in
 an Offline file system if the offline flag is set, and finally wraps it in a
 Caching file system.
 '''
     if self._constructor_for_test is not None:
         file_system = self._constructor_for_test(branch=branch,
                                                  revision=revision)
     else:
         file_system = SubversionFileSystem.Create(branch=branch,
                                                   revision=revision)
     if offline or (offline is None and self._offline):
         file_system = OfflineFileSystem(file_system)
     return CachingFileSystem(file_system, self._object_store_creator)
示例#6
0
 def _Create(self, branch, revision=None):
     '''Creates SVN file systems (or if in a test, potentially whatever
 |self._constructor_for_test specifies). Wraps the resulting file system in
 an Offline file system if the offline flag is set, and finally wraps it in
 a Caching file system.
 '''
     if self._constructor_for_test is not None:
         file_system = self._constructor_for_test(branch=branch,
                                                  revision=revision)
     else:
         file_system = SubversionFileSystem.Create(branch=branch,
                                                   revision=revision)
     if self._offline:
         file_system = OfflineFileSystem(file_system)
     return CachingFileSystem(file_system, self._object_store_creator)
示例#7
0
def _CreateSubversionFileSystem(path):
    fetcher = FakeUrlFetcher(path)
    return SubversionFileSystem(fetcher, fetcher, path), fetcher
示例#8
0
 def _CreateSubversionFileSystem(self):
   fetcher = FakeUrlFetcher(self._base_path)
   return SubversionFileSystem(fetcher, fetcher, self._base_path)
示例#9
0
 def CreateHostFileSystemForBranchAndRevision(self, branch, revision):
     return SubversionFileSystem.Create(branch, revision=revision)
示例#10
0
 def setUp(self):
     self._base_path = os.path.join(sys.path[0], 'test_data', 'file_system')
     fetcher = FakeUrlFetcher(self._base_path)
     self._file_system = SubversionFileSystem(fetcher, fetcher)