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)
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())
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)
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)
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)
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)
def _CreateSubversionFileSystem(path): fetcher = FakeUrlFetcher(path) return SubversionFileSystem(fetcher, fetcher, path), fetcher
def _CreateSubversionFileSystem(self): fetcher = FakeUrlFetcher(self._base_path) return SubversionFileSystem(fetcher, fetcher, self._base_path)
def CreateHostFileSystemForBranchAndRevision(self, branch, revision): return SubversionFileSystem.Create(branch, revision=revision)
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)