def CreateServerInstance(self): object_store_creator = ObjectStoreCreator(start_empty=False) branch_utility = self._delegate.CreateBranchUtility( object_store_creator) host_file_system_creator = self._delegate.CreateHostFileSystemCreator( object_store_creator) # offline=False because a patch can rely on files that are already in SVN # repository but not yet pulled into data store by cron jobs (a typical # example is to add documentation for an existing API). base_file_system = CachingFileSystem( host_file_system_creator.Create(offline=False), object_store_creator) base_compiled_fs_factory = CompiledFileSystem.Factory( base_file_system, object_store_creator) rietveld_patcher = CachingRietveldPatcher( RietveldPatcher( svn_constants.EXTENSIONS_PATH, self._issue, AppEngineUrlFetcher(url_constants.CODEREVIEW_SERVER)), object_store_creator) patched_file_system = PatchedFileSystem(base_file_system, rietveld_patcher) patched_compiled_fs_factory = CompiledFileSystem.Factory( patched_file_system, object_store_creator) compiled_fs_factory = ChainedCompiledFileSystem.Factory([ (patched_compiled_fs_factory, patched_file_system), (base_compiled_fs_factory, base_file_system) ]) return ServerInstance( object_store_creator, patched_file_system, self._delegate.CreateAppSamplesFileSystem(object_store_creator), '/_patch/%s' % self._issue, compiled_fs_factory, branch_utility, host_file_system_creator)
def CreateServerInstanceForChannel(self, channel): base_object_store_creator = ObjectStoreCreator(channel, start_empty=False) # TODO(fj): Use OfflineFileSystem here once all json/idl files in api/ # are pulled into data store by cron jobs. base_file_system = CachingFileSystem( self._delegate.CreateHostFileSystemForBranch(channel), base_object_store_creator) base_compiled_fs_factory = CompiledFileSystem.Factory( base_file_system, base_object_store_creator) object_store_creator = ObjectStoreCreator('trunk@%s' % self._issue, start_empty=False) rietveld_patcher = CachingRietveldPatcher( RietveldPatcher( svn_constants.EXTENSIONS_PATH, self._issue, AppEngineUrlFetcher(url_constants.CODEREVIEW_SERVER)), object_store_creator) patched_file_system = PatchedFileSystem(base_file_system, rietveld_patcher) patched_compiled_fs_factory = CompiledFileSystem.Factory( patched_file_system, object_store_creator) compiled_fs_factory = ChainedCompiledFileSystem.Factory([ (patched_compiled_fs_factory, patched_file_system), (base_compiled_fs_factory, base_file_system) ]) return ServerInstance( channel, object_store_creator, patched_file_system, self._delegate.CreateAppSamplesFileSystem( base_object_store_creator), '/_patch/%s' % self._issue, compiled_fs_factory)
def CreateServerInstance(self): # start_empty=False because a patch can rely on files that are already in # SVN repository but not yet pulled into data store by cron jobs (a typical # example is to add documentation for an existing API). object_store_creator = ObjectStoreCreator(start_empty=False) unpatched_file_system = self._delegate.CreateHostFileSystemProvider( object_store_creator).GetTrunk() rietveld_patcher = CachingRietveldPatcher( RietveldPatcher( self._issue, AppEngineUrlFetcher(url_constants.CODEREVIEW_SERVER)), object_store_creator) patched_file_system = PatchedFileSystem(unpatched_file_system, rietveld_patcher) patched_host_file_system_provider = ( self._delegate.CreateHostFileSystemProvider( object_store_creator, # The patched file system needs to be online otherwise it'd be # impossible to add files in the patches. offline=False, # The trunk file system for this creator should be the patched one. default_trunk_instance=patched_file_system)) combined_compiled_fs_factory = ChainedCompiledFileSystem.Factory( [unpatched_file_system], object_store_creator) branch_utility = self._delegate.CreateBranchUtility( object_store_creator) server_instance = ServerInstance( object_store_creator, combined_compiled_fs_factory, branch_utility, patched_host_file_system_provider, self._delegate.CreateGithubFileSystemProvider( object_store_creator), CloudStorageFileSystemProvider(object_store_creator), base_path='/_patch/%s/' % self._issue) # HACK: if content_providers.json changes in this patch then the cron needs # to be re-run to pull in the new configuration. _, _, modified = rietveld_patcher.GetPatchedFiles() if CONTENT_PROVIDERS in modified: server_instance.content_providers.Cron().Get() return server_instance
def setUp(self): self._patcher = TestPatcher(_TEST_PATCH_VERSION, _TEST_PATCH_FILES, _TEST_PATCH_DATA) self._host_file_system = TestFileSystem(_TEST_FS_DATA) self._file_system = PatchedFileSystem(self._host_file_system, self._patcher)
class PatchedFileSystemTest(unittest.TestCase): def setUp(self): self._patcher = TestPatcher(_TEST_PATCH_VERSION, _TEST_PATCH_FILES, _TEST_PATCH_DATA) self._host_file_system = TestFileSystem(_TEST_FS_DATA) self._file_system = PatchedFileSystem(self._host_file_system, self._patcher) def testRead(self): expected = deepcopy(_TEST_PATCH_DATA) # Files that are not modified. expected.update({ 'dir2/subdir1/sub3.txt': 'in subdir(3)', 'dir1/file1.html': 'This is dir1/file1.html', }) for key in expected: self.assertEqual(expected[key], self._file_system.ReadSingle(key).Get()) self.assertEqual(expected, self._file_system.Read(expected.keys()).Get()) self.assertRaises(FileNotFoundError, self._file_system.ReadSingle('test2.txt').Get) self.assertRaises( FileNotFoundError, self._file_system.ReadSingle('dir2/subdir1/sub1.txt').Get) self.assertRaises(FileNotFoundError, self._file_system.ReadSingle('not_existing').Get) self.assertRaises( FileNotFoundError, self._file_system.ReadSingle('dir1/not_existing').Get) self.assertRaises( FileNotFoundError, self._file_system.ReadSingle('dir1/newsubdir/not_existing').Get) def testReadDir(self): self.assertEqual( sorted(self._file_system.ReadSingle('dir1/').Get()), sorted( set(self._host_file_system.ReadSingle('dir1/').Get()) | set(('file2.html', 'newsubdir/')))) self.assertEqual( sorted(self._file_system.ReadSingle('dir1/newsubdir/').Get()), sorted(['a.js'])) self.assertEqual( sorted(self._file_system.ReadSingle('dir2/').Get()), sorted(self._host_file_system.ReadSingle('dir2/').Get())) self.assertEqual( sorted(self._file_system.ReadSingle('dir2/subdir1/').Get()), sorted( set(self._host_file_system.ReadSingle('dir2/subdir1/').Get()) - set(('sub1.txt', )))) self.assertEqual(sorted(self._file_system.ReadSingle('newdir/').Get()), sorted(['1.html'])) self.assertEqual(self._file_system.ReadSingle('dir3/').Get(), []) self.assertEqual(self._file_system.ReadSingle('dir4/').Get(), []) self.assertRaises( FileNotFoundError, self._file_system.ReadSingle('not_existing_dir/').Get) def testStat(self): version = 'patched_%s' % self._patcher.GetVersion() old_version = self._host_file_system.Stat('dir1/file1.html').version # Stat an unmodified file. self.assertEqual(self._file_system.Stat('dir1/file1.html'), self._host_file_system.Stat('dir1/file1.html')) # Stat an unmodified directory. self.assertEqual(self._file_system.Stat('dir1/unmodified/'), self._host_file_system.Stat('dir1/unmodified/')) # Stat a modified directory. self.assertEqual(self._file_system.Stat('dir2/'), StatInfo(version, {'subdir1/': version})) self.assertEqual( self._file_system.Stat('dir2/subdir1/'), StatInfo(version, { 'sub2.txt': version, 'sub3.txt': old_version })) # Stat a modified directory with new files. expected = self._host_file_system.Stat('dir1/') expected.version = version expected.child_versions.update({ 'file2.html': version, 'newsubdir/': version }) self.assertEqual(self._file_system.Stat('dir1/'), expected) # Stat an added directory. self.assertEqual(self._file_system.Stat('dir1/newsubdir/'), StatInfo(version, {'a.js': version})) self.assertEqual(self._file_system.Stat('dir1/newsubdir/a.js'), StatInfo(version)) self.assertEqual(self._file_system.Stat('newdir/'), StatInfo(version, {'1.html': version})) self.assertEqual(self._file_system.Stat('newdir/1.html'), StatInfo(version)) # Stat files removed in the patch. self.assertRaises(FileNotFoundError, self._file_system.Stat, 'dir2/subdir1/sub1.txt') self.assertRaises(FileNotFoundError, self._file_system.Stat, 'dir4/one.txt') # Stat empty directories. self.assertEqual(self._file_system.Stat('dir3/'), StatInfo(old_version, {})) self.assertEqual(self._file_system.Stat('dir4/'), StatInfo(version, {})) self.assertEqual(self._file_system.Stat('dir5/subdir/'), StatInfo(version, {})) # Stat empty (after patch) directory's parent self.assertEqual(self._file_system.Stat('dir5/'), StatInfo(version, {'subdir/': version})) # Stat files that don't exist either before or after patching. self.assertRaises(FileNotFoundError, self._file_system.Stat, 'not_existing/') self.assertRaises(FileNotFoundError, self._file_system.Stat, 'dir1/not_existing/') self.assertRaises(FileNotFoundError, self._file_system.Stat, 'dir1/not_existing')