def Get(self): ''' Render the page for a request. ''' path = self._request.path.lstrip('/') # The server used to be partitioned based on Chrome channel, but it isn't # anymore. Redirect from the old state. channel_name, path = BranchUtility.SplitChannelNameFromPath(path) if channel_name is not None: return Response.Redirect('/' + path, permanent=True) server_instance = self._delegate.CreateServerInstance() try: return self._GetSuccessResponse(path, server_instance) except FileNotFoundError: # Find the closest 404.html file and serve that, e.g. if the path is # extensions/manifest/typo.html then first look for # extensions/manifest/404.html, then extensions/404.html, then 404.html. # # Failing that just print 'Not Found' but that should preferrably never # happen, because it would look really bad. path_components = path.split('/') for i in xrange(len(path_components) - 1, -1, -1): try: path_404 = posixpath.join(*(path_components[0:i] + ['404'])) response = self._GetSuccessResponse(path_404, server_instance) if response.status != 200: continue return Response.NotFound(response.content.ToString(), headers=response.headers) except FileNotFoundError: continue logging.warning('No 404.html found in %s' % path) return Response.NotFound('Not Found', headers=_MakeHeaders('text/plain'))
def _HandleGet(self, path): channel_name, real_path = BranchUtility.SplitChannelNameFromPath(path) if channel_name == _DEFAULT_CHANNEL: self.redirect('/%s' % real_path) return if channel_name is None: channel_name = _DEFAULT_CHANNEL # TODO(kalman): Check if |path| is a directory and serve path/index.html # rather than special-casing apps/extensions. if real_path.strip('/') == 'apps': real_path = 'apps/index.html' if real_path.strip('/') == 'extensions': real_path = 'extensions/index.html' server_instance = ServerInstance.GetOrCreate(channel_name) canonical_path = server_instance.path_canonicalizer.Canonicalize( real_path) if real_path != canonical_path: self.redirect(canonical_path) return ServerInstance.GetOrCreate(channel_name).Get(real_path, self.request, self.response)
def _HandleGet(self, path): if os.environ.get('CRXDOCZH_SLAVE_TYPE') is None: self._OriginalHandleGet(path) return channel_name, real_path = BranchUtility.SplitChannelNameFromPath(path) if channel_name is None: channel_name = _DEFAULT_CHANNEL if os.environ.get('CRXDOCZH_SLAVE_TYPE') == 'samples': self._HandleSamplesAPI(channel_name, real_path) else: self._OriginalHandleGet(path)
class BranchUtilityTest(unittest.TestCase): def setUp(self): self._branch_util = BranchUtility( os.path.join('branch_utility', 'first.json'), FakeUrlFetcher(os.path.join(sys.path[0], 'test_data')), object_store=TestObjectStore('test')) def testSplitChannelNameFromPath(self): self.assertEquals(('stable', 'extensions/stuff.html'), self._branch_util.SplitChannelNameFromPath( 'stable/extensions/stuff.html')) self.assertEquals(('dev', 'extensions/stuff.html'), self._branch_util.SplitChannelNameFromPath( 'dev/extensions/stuff.html')) self.assertEquals(('beta', 'extensions/stuff.html'), self._branch_util.SplitChannelNameFromPath( 'beta/extensions/stuff.html')) self.assertEquals(('trunk', 'extensions/stuff.html'), self._branch_util.SplitChannelNameFromPath( 'trunk/extensions/stuff.html')) self.assertEquals((None, 'extensions/stuff.html'), self._branch_util.SplitChannelNameFromPath( 'extensions/stuff.html')) self.assertEquals( (None, 'apps/stuff.html'), self._branch_util.SplitChannelNameFromPath('apps/stuff.html')) self.assertEquals((None, 'extensions/dev/stuff.html'), self._branch_util.SplitChannelNameFromPath( 'extensions/dev/stuff.html')) self.assertEquals( (None, 'stuff.html'), self._branch_util.SplitChannelNameFromPath('stuff.html')) def testGetBranchNumberForChannelName(self): self.assertEquals( '1145', self._branch_util.GetBranchNumberForChannelName('dev')) self.assertEquals( '1084', self._branch_util.GetBranchNumberForChannelName('beta')) self.assertEquals( '1084', self._branch_util.GetBranchNumberForChannelName('stable')) self.assertEquals( 'trunk', self._branch_util.GetBranchNumberForChannelName('trunk'))
class BranchUtilityTest(unittest.TestCase): def setUp(self): self._branch_util = BranchUtility( os.path.join('branch_utility', 'first.json'), os.path.join('branch_utility', 'second.json'), FakeUrlFetcher(Server2Path('test_data')), ObjectStoreCreator.ForTest()) def testSplitChannelNameFromPath(self): self.assertEquals(('stable', 'extensions/stuff.html'), self._branch_util.SplitChannelNameFromPath( 'stable/extensions/stuff.html')) self.assertEquals(('dev', 'extensions/stuff.html'), self._branch_util.SplitChannelNameFromPath( 'dev/extensions/stuff.html')) self.assertEquals(('beta', 'extensions/stuff.html'), self._branch_util.SplitChannelNameFromPath( 'beta/extensions/stuff.html')) self.assertEquals(('master', 'extensions/stuff.html'), self._branch_util.SplitChannelNameFromPath( 'master/extensions/stuff.html')) self.assertEquals((None, 'extensions/stuff.html'), self._branch_util.SplitChannelNameFromPath( 'extensions/stuff.html')) self.assertEquals( (None, 'apps/stuff.html'), self._branch_util.SplitChannelNameFromPath('apps/stuff.html')) self.assertEquals((None, 'extensions/dev/stuff.html'), self._branch_util.SplitChannelNameFromPath( 'extensions/dev/stuff.html')) self.assertEquals( (None, 'stuff.html'), self._branch_util.SplitChannelNameFromPath('stuff.html')) def testNewestChannel(self): self.assertEquals( 'master', self._branch_util.NewestChannel( ('master', 'dev', 'beta', 'stable'))) self.assertEquals( 'master', self._branch_util.NewestChannel( ('stable', 'beta', 'dev', 'master'))) self.assertEquals( 'dev', self._branch_util.NewestChannel(('stable', 'beta', 'dev'))) self.assertEquals( 'dev', self._branch_util.NewestChannel(('dev', 'beta', 'stable'))) self.assertEquals('beta', self._branch_util.NewestChannel(('beta', 'stable'))) self.assertEquals('beta', self._branch_util.NewestChannel(('stable', 'beta'))) self.assertEquals('stable', self._branch_util.NewestChannel(('stable', ))) self.assertEquals('beta', self._branch_util.NewestChannel(('beta', ))) self.assertEquals('dev', self._branch_util.NewestChannel(('dev', ))) self.assertEquals('master', self._branch_util.NewestChannel(('master', ))) @unittest.skipIf(os.name == 'nt', "crbug.com/1114884") def testNewer(self): oldest_stable_info = ChannelInfo('stable', '963', 17) older_stable_info = ChannelInfo('stable', '1025', 18) old_stable_info = ChannelInfo('stable', '1084', 19) sort_of_old_stable_info = ChannelInfo('stable', '1500', 28) stable_info = ChannelInfo('stable', '1547', 29) beta_info = ChannelInfo('beta', '1599', 30) dev_info = ChannelInfo('dev', '1612', 31) master_info = ChannelInfo('master', 'master', 'master') self.assertEquals(older_stable_info, self._branch_util.Newer(oldest_stable_info)) self.assertEquals(old_stable_info, self._branch_util.Newer(older_stable_info)) self.assertEquals(stable_info, self._branch_util.Newer(sort_of_old_stable_info)) self.assertEquals(beta_info, self._branch_util.Newer(stable_info)) self.assertEquals(dev_info, self._branch_util.Newer(beta_info)) self.assertEquals(master_info, self._branch_util.Newer(dev_info)) # Test the upper limit. self.assertEquals(None, self._branch_util.Newer(master_info)) @unittest.skipIf(os.name == 'nt', "crbug.com/1114884") def testOlder(self): master_info = ChannelInfo('master', 'master', 'master') dev_info = ChannelInfo('dev', '1612', 31) beta_info = ChannelInfo('beta', '1599', 30) stable_info = ChannelInfo('stable', '1547', 29) old_stable_info = ChannelInfo('stable', '1500', 28) older_stable_info = ChannelInfo('stable', '1453', 27) oldest_stable_info = ChannelInfo('stable', '396', 5) self.assertEquals(dev_info, self._branch_util.Older(master_info)) self.assertEquals(beta_info, self._branch_util.Older(dev_info)) self.assertEquals(stable_info, self._branch_util.Older(beta_info)) self.assertEquals(old_stable_info, self._branch_util.Older(stable_info)) self.assertEquals(older_stable_info, self._branch_util.Older(old_stable_info)) # Test the lower limit. self.assertEquals(None, self._branch_util.Older(oldest_stable_info)) @unittest.skipIf(os.name == 'nt', "crbug.com/1114884") def testGetChannelInfo(self): master_info = ChannelInfo('master', 'master', 'master') self.assertEquals(master_info, self._branch_util.GetChannelInfo('master')) dev_info = ChannelInfo('dev', '1612', 31) self.assertEquals(dev_info, self._branch_util.GetChannelInfo('dev')) beta_info = ChannelInfo('beta', '1599', 30) self.assertEquals(beta_info, self._branch_util.GetChannelInfo('beta')) stable_info = ChannelInfo('stable', '1547', 29) self.assertEquals(stable_info, self._branch_util.GetChannelInfo('stable')) @unittest.skipIf(os.name == 'nt', "crbug.com/1114884") def testGetLatestVersionNumber(self): self.assertEquals(37, self._branch_util.GetLatestVersionNumber()) @unittest.skipIf(os.name == 'nt', "crbug.com/1114884") def testGetBranchForVersion(self): self.assertEquals('1500', self._branch_util.GetBranchForVersion(28)) self.assertEquals('1453', self._branch_util.GetBranchForVersion(27)) self.assertEquals('1410', self._branch_util.GetBranchForVersion(26)) self.assertEquals('1364', self._branch_util.GetBranchForVersion(25)) self.assertEquals('1312', self._branch_util.GetBranchForVersion(24)) self.assertEquals('1271', self._branch_util.GetBranchForVersion(23)) self.assertEquals('1229', self._branch_util.GetBranchForVersion(22)) self.assertEquals('1180', self._branch_util.GetBranchForVersion(21)) self.assertEquals('1132', self._branch_util.GetBranchForVersion(20)) self.assertEquals('1084', self._branch_util.GetBranchForVersion(19)) self.assertEquals('1025', self._branch_util.GetBranchForVersion(18)) self.assertEquals('963', self._branch_util.GetBranchForVersion(17)) self.assertEquals('696', self._branch_util.GetBranchForVersion(11)) self.assertEquals('396', self._branch_util.GetBranchForVersion(5)) @unittest.skipIf(os.name == 'nt', "crbug.com/1114884") def testGetChannelForVersion(self): self.assertEquals('master', self._branch_util.GetChannelForVersion('master')) self.assertEquals('dev', self._branch_util.GetChannelForVersion(31)) self.assertEquals('beta', self._branch_util.GetChannelForVersion(30)) self.assertEquals('stable', self._branch_util.GetChannelForVersion(26)) self.assertEquals('stable', self._branch_util.GetChannelForVersion(22)) self.assertEquals('stable', self._branch_util.GetChannelForVersion(18)) self.assertEquals('stable', self._branch_util.GetChannelForVersion(14)) self.assertEquals(None, self._branch_util.GetChannelForVersion(32)) self.assertEquals(None, self._branch_util.GetChannelForVersion(42))
class BranchUtilityTest(unittest.TestCase): def setUp(self): self._branch_util = BranchUtility( os.path.join('branch_utility', 'first.json'), os.path.join('branch_utility', 'second.json'), FakeUrlFetcher(os.path.join(sys.path[0], 'test_data')), ObjectStoreCreator.ForTest()) def testSplitChannelNameFromPath(self): self.assertEquals(('stable', 'extensions/stuff.html'), self._branch_util.SplitChannelNameFromPath( 'stable/extensions/stuff.html')) self.assertEquals(('dev', 'extensions/stuff.html'), self._branch_util.SplitChannelNameFromPath( 'dev/extensions/stuff.html')) self.assertEquals(('beta', 'extensions/stuff.html'), self._branch_util.SplitChannelNameFromPath( 'beta/extensions/stuff.html')) self.assertEquals(('trunk', 'extensions/stuff.html'), self._branch_util.SplitChannelNameFromPath( 'trunk/extensions/stuff.html')) self.assertEquals((None, 'extensions/stuff.html'), self._branch_util.SplitChannelNameFromPath( 'extensions/stuff.html')) self.assertEquals( (None, 'apps/stuff.html'), self._branch_util.SplitChannelNameFromPath('apps/stuff.html')) self.assertEquals((None, 'extensions/dev/stuff.html'), self._branch_util.SplitChannelNameFromPath( 'extensions/dev/stuff.html')) self.assertEquals( (None, 'stuff.html'), self._branch_util.SplitChannelNameFromPath('stuff.html')) def testNewestChannel(self): self.assertEquals( 'trunk', self._branch_util.NewestChannel( ('trunk', 'dev', 'beta', 'stable'))) self.assertEquals( 'trunk', self._branch_util.NewestChannel( ('stable', 'beta', 'dev', 'trunk'))) self.assertEquals( 'dev', self._branch_util.NewestChannel(('stable', 'beta', 'dev'))) self.assertEquals( 'dev', self._branch_util.NewestChannel(('dev', 'beta', 'stable'))) self.assertEquals('beta', self._branch_util.NewestChannel(('beta', 'stable'))) self.assertEquals('beta', self._branch_util.NewestChannel(('stable', 'beta'))) self.assertEquals('stable', self._branch_util.NewestChannel(('stable', ))) self.assertEquals('beta', self._branch_util.NewestChannel(('beta', ))) self.assertEquals('dev', self._branch_util.NewestChannel(('dev', ))) self.assertEquals('trunk', self._branch_util.NewestChannel( ('trunk', ))) def testGetChannelInfo(self): self.assertEquals('trunk', self._branch_util.GetChannelInfo('trunk').channel) self.assertEquals('trunk', self._branch_util.GetChannelInfo('trunk').branch) self.assertEquals('trunk', self._branch_util.GetChannelInfo('trunk').version) self.assertEquals('dev', self._branch_util.GetChannelInfo('dev').channel) self.assertEquals(1500, self._branch_util.GetChannelInfo('dev').branch) self.assertEquals(28, self._branch_util.GetChannelInfo('dev').version) self.assertEquals('beta', self._branch_util.GetChannelInfo('beta').channel) self.assertEquals(1453, self._branch_util.GetChannelInfo('beta').branch) self.assertEquals(27, self._branch_util.GetChannelInfo('beta').version) self.assertEquals('stable', self._branch_util.GetChannelInfo('stable').channel) self.assertEquals(1410, self._branch_util.GetChannelInfo('stable').branch) self.assertEquals(26, self._branch_util.GetChannelInfo('stable').version) def testGetLatestVersionNumber(self): self.assertEquals(28, self._branch_util.GetLatestVersionNumber()) def testGetBranchForVersion(self): self.assertEquals(1453, self._branch_util.GetBranchForVersion(27)) self.assertEquals(1410, self._branch_util.GetBranchForVersion(26)) self.assertEquals(1364, self._branch_util.GetBranchForVersion(25)) self.assertEquals(1312, self._branch_util.GetBranchForVersion(24)) self.assertEquals(1271, self._branch_util.GetBranchForVersion(23)) self.assertEquals(1229, self._branch_util.GetBranchForVersion(22)) self.assertEquals(1180, self._branch_util.GetBranchForVersion(21)) self.assertEquals(1132, self._branch_util.GetBranchForVersion(20)) self.assertEquals(1084, self._branch_util.GetBranchForVersion(19)) self.assertEquals(1025, self._branch_util.GetBranchForVersion(18)) self.assertEquals(963, self._branch_util.GetBranchForVersion(17)) self.assertEquals(696, self._branch_util.GetBranchForVersion(11)) self.assertEquals(396, self._branch_util.GetBranchForVersion(5)) def testGetChannelForVersion(self): self.assertEquals('trunk', self._branch_util.GetChannelForVersion('trunk')) self.assertEquals('dev', self._branch_util.GetChannelForVersion(28)) self.assertEquals('beta', self._branch_util.GetChannelForVersion(27)) self.assertEquals('stable', self._branch_util.GetChannelForVersion(26)) self.assertEquals('stable', self._branch_util.GetChannelForVersion(22)) self.assertEquals('stable', self._branch_util.GetChannelForVersion(18)) self.assertEquals('stable', self._branch_util.GetChannelForVersion(14)) self.assertEquals(None, self._branch_util.GetChannelForVersion(30)) self.assertEquals(None, self._branch_util.GetChannelForVersion(42))
def Get(self): ''' Render the page for a request. ''' headers = self._request.headers channel, path = BranchUtility.SplitChannelNameFromPath( self._request.path) if path.split('/')[-1] == 'redirects.json': return Response.Ok('') if channel == self._default_channel: return Response.Redirect('/' + path) if channel is None: channel = self._default_channel server_instance = self._delegate.CreateServerInstanceForChannel( channel) redirect = server_instance.redirector.Redirect(self._request.host, path) if redirect is not None: if (channel != self._default_channel and not urlsplit(redirect).scheme in ('http', 'https')): redirect = '/%s%s' % (channel, redirect) return Response.Redirect(redirect) canonical_path = server_instance.path_canonicalizer.Canonicalize(path) redirect = canonical_path.lstrip('/') if path != redirect: if channel is not None: redirect = '%s/%s' % (channel, canonical_path) return Response.Redirect('/' + redirect) templates = server_instance.template_data_source_factory.Create( self._request, path) content = None content_type = None try: if fnmatch(path, 'extensions/examples/*.zip'): content = server_instance.example_zipper.Create( path[len('extensions/'):-len('.zip')]) content_type = 'application/zip' elif path.startswith('extensions/examples/'): mimetype = mimetypes.guess_type(path)[0] or 'text/plain' content = server_instance.content_cache.GetFromFile( '%s/%s' % (svn_constants.DOCS_PATH, path[len('extensions/'):]), binary=_IsBinaryMimetype(mimetype)) content_type = mimetype elif path.startswith('static/'): mimetype = mimetypes.guess_type(path)[0] or 'text/plain' content = server_instance.content_cache.GetFromFile( ('%s/%s' % (svn_constants.DOCS_PATH, path)), binary=_IsBinaryMimetype(mimetype)) content_type = mimetype elif path.endswith('.html'): content = templates.Render(path) content_type = 'text/html' except FileNotFoundError: logging.warning(traceback.format_exc()) content = None headers = {'x-frame-options': 'sameorigin'} if content is None: doc_class = path.split('/', 1)[0] content = templates.Render('%s/404' % doc_class) if not content: content = templates.Render('extensions/404') return Response.NotFound(content, headers=headers) if not content: logging.error('%s had empty content' % path) headers.update({ 'content-type': content_type, 'cache-control': 'max-age=300', }) return Response.Ok(content, headers=headers)
def Get(self): path_with_channel, headers = (self._request.path, self._request.headers) # Redirect "extensions" and "extensions/" to "extensions/index.html", etc. if (os.path.splitext(path_with_channel)[1] == '' and path_with_channel.find('/') == -1): path_with_channel += '/' if path_with_channel.endswith('/'): return Response.Redirect('/%sindex.html' % path_with_channel) channel, path = BranchUtility.SplitChannelNameFromPath( path_with_channel) if channel == self._default_channel: return Response.Redirect('/%s' % path) if channel is None: channel = self._default_channel server_instance = self._delegate.CreateServerInstanceForChannel( channel) canonical_path = ( server_instance.path_canonicalizer.Canonicalize(path).lstrip('/')) if path != canonical_path: redirect_path = (canonical_path if channel is None else '%s/%s' % (channel, canonical_path)) return Response.Redirect('/%s' % redirect_path) templates = server_instance.template_data_source_factory.Create( self._request, path) content = None content_type = None try: if fnmatch(path, 'extensions/examples/*.zip'): content = server_instance.example_zipper.Create( path[len('extensions/'):-len('.zip')]) content_type = 'application/zip' elif path.startswith('extensions/examples/'): mimetype = mimetypes.guess_type(path)[0] or 'text/plain' content = server_instance.content_cache.GetFromFile( '%s/%s' % (svn_constants.DOCS_PATH, path[len('extensions/'):]), binary=_IsBinaryMimetype(mimetype)) content_type = mimetype elif path.startswith('static/'): mimetype = mimetypes.guess_type(path)[0] or 'text/plain' content = server_instance.content_cache.GetFromFile( ('%s/%s' % (svn_constants.DOCS_PATH, path)), binary=_IsBinaryMimetype(mimetype)) content_type = mimetype elif path.endswith('.html'): content = templates.Render(path) content_type = 'text/html' except FileNotFoundError as e: logging.warning(traceback.format_exc()) content = None headers = {'x-frame-options': 'sameorigin'} if content is None: doc_class = path.split('/', 1)[0] content = templates.Render('%s/404' % doc_class) if not content: content = templates.Render('extensions/404') return Response.NotFound(content, headers=headers) if not content: logging.error('%s had empty content' % path) headers.update({ 'content-type': content_type, 'cache-control': 'max-age=300', }) return Response.Ok(content, headers=headers)
def Get(self, server_instance=None): path_with_channel, headers = (self._request.path.lstrip('/'), self._request.headers) # Redirect "extensions" and "extensions/" to "extensions/index.html", etc. if (os.path.splitext(path_with_channel)[1] == '' and path_with_channel.find('/') == -1): path_with_channel += '/' if path_with_channel.endswith('/'): return Response.Redirect(path_with_channel + 'index.html') channel, path = BranchUtility.SplitChannelNameFromPath( path_with_channel) if channel == _DEFAULT_CHANNEL: return Response.Redirect('/%s' % path) if channel is None: channel = _DEFAULT_CHANNEL # AppEngine instances should never need to call out to SVN. That should # only ever be done by the cronjobs, which then write the result into # DataStore, which is as far as instances look. To enable this, crons can # pass a custom (presumably online) ServerInstance into Get(). # # Why? SVN is slow and a bit flaky. Cronjobs failing is annoying but # temporary. Instances failing affects users, and is really bad. # # Anyway - to enforce this, we actually don't give instances access to SVN. # If anything is missing from datastore, it'll be a 404. If the cronjobs # don't manage to catch everything - uhoh. On the other hand, we'll figure # it out pretty soon, and it also means that legitimate 404s are caught # before a round trip to SVN. if server_instance is None: # The ALWAYS_ONLINE thing is for tests and preview.py that shouldn't need # to run the cron before rendering things. constructor = (ServerInstance.CreateOnline if _ALWAYS_ONLINE else ServerInstance.GetOrCreateOffline) server_instance = constructor(channel) canonical_path = server_instance.path_canonicalizer.Canonicalize(path) if path != canonical_path: return Response.Redirect( canonical_path if channel is None else '%s/%s' % (channel, canonical_path)) templates = server_instance.template_data_source_factory.Create( self._request, path) content = None content_type = None try: if fnmatch(path, 'extensions/examples/*.zip'): content = server_instance.example_zipper.Create( path[len('extensions/'):-len('.zip')]) content_type = 'application/zip' elif path.startswith('extensions/examples/'): mimetype = mimetypes.guess_type(path)[0] or 'text/plain' content = server_instance.content_cache.GetFromFile( '%s/%s' % (svn_constants.DOCS_PATH, path[len('extensions/'):]), binary=_IsBinaryMimetype(mimetype)) content_type = mimetype elif path.startswith('static/'): mimetype = mimetypes.guess_type(path)[0] or 'text/plain' content = server_instance.content_cache.GetFromFile( ('%s/%s' % (svn_constants.DOCS_PATH, path)), binary=_IsBinaryMimetype(mimetype)) content_type = mimetype elif path.endswith('.html'): content = templates.Render(path) content_type = 'text/html' except FileNotFoundError as e: logging.warning(traceback.format_exc()) content = None headers = {'x-frame-options': 'sameorigin'} if content is None: return Response.NotFound(templates.Render('404'), headers=headers) if not content: logging.error('%s had empty content' % path) headers.update({ 'content-type': content_type, 'cache-control': 'max-age=300', }) return Response.Ok(content, headers=headers)
class BranchUtilityTest(unittest.TestCase): def setUp(self): self._branch_util = BranchUtility( os.path.join('branch_utility', 'first.json'), os.path.join('branch_utility', 'second.json'), FakeUrlFetcher(os.path.join(sys.path[0], 'test_data')), ObjectStoreCreator.ForTest()) def testSplitChannelNameFromPath(self): self.assertEquals(('stable', 'extensions/stuff.html'), self._branch_util.SplitChannelNameFromPath( 'stable/extensions/stuff.html')) self.assertEquals(('dev', 'extensions/stuff.html'), self._branch_util.SplitChannelNameFromPath( 'dev/extensions/stuff.html')) self.assertEquals(('beta', 'extensions/stuff.html'), self._branch_util.SplitChannelNameFromPath( 'beta/extensions/stuff.html')) self.assertEquals(('trunk', 'extensions/stuff.html'), self._branch_util.SplitChannelNameFromPath( 'trunk/extensions/stuff.html')) self.assertEquals((None, 'extensions/stuff.html'), self._branch_util.SplitChannelNameFromPath( 'extensions/stuff.html')) self.assertEquals( (None, 'apps/stuff.html'), self._branch_util.SplitChannelNameFromPath('apps/stuff.html')) self.assertEquals((None, 'extensions/dev/stuff.html'), self._branch_util.SplitChannelNameFromPath( 'extensions/dev/stuff.html')) self.assertEquals( (None, 'stuff.html'), self._branch_util.SplitChannelNameFromPath('stuff.html')) def testNewestChannel(self): self.assertEquals( 'trunk', self._branch_util.NewestChannel( ('trunk', 'dev', 'beta', 'stable'))) self.assertEquals( 'trunk', self._branch_util.NewestChannel( ('stable', 'beta', 'dev', 'trunk'))) self.assertEquals( 'dev', self._branch_util.NewestChannel(('stable', 'beta', 'dev'))) self.assertEquals( 'dev', self._branch_util.NewestChannel(('dev', 'beta', 'stable'))) self.assertEquals('beta', self._branch_util.NewestChannel(('beta', 'stable'))) self.assertEquals('beta', self._branch_util.NewestChannel(('stable', 'beta'))) self.assertEquals('stable', self._branch_util.NewestChannel(('stable', ))) self.assertEquals('beta', self._branch_util.NewestChannel(('beta', ))) self.assertEquals('dev', self._branch_util.NewestChannel(('dev', ))) self.assertEquals('trunk', self._branch_util.NewestChannel( ('trunk', ))) def testNewer(self): oldest_stable_info = ChannelInfo('stable', '963', 17) older_stable_info = ChannelInfo('stable', '1025', 18) old_stable_info = ChannelInfo('stable', '1084', 19) sort_of_old_stable_info = ChannelInfo('stable', '1364', 25) stable_info = ChannelInfo('stable', '1410', 26) beta_info = ChannelInfo('beta', '1453', 27) dev_info = ChannelInfo('dev', '1500', 28) trunk_info = ChannelInfo('trunk', 'trunk', 'trunk') self.assertEquals(older_stable_info, self._branch_util.Newer(oldest_stable_info)) self.assertEquals(old_stable_info, self._branch_util.Newer(older_stable_info)) self.assertEquals(stable_info, self._branch_util.Newer(sort_of_old_stable_info)) self.assertEquals(beta_info, self._branch_util.Newer(stable_info)) self.assertEquals(dev_info, self._branch_util.Newer(beta_info)) self.assertEquals(trunk_info, self._branch_util.Newer(dev_info)) # Test the upper limit. self.assertEquals(None, self._branch_util.Newer(trunk_info)) def testOlder(self): trunk_info = ChannelInfo('trunk', 'trunk', 'trunk') dev_info = ChannelInfo('dev', '1500', 28) beta_info = ChannelInfo('beta', '1453', 27) stable_info = ChannelInfo('stable', '1410', 26) old_stable_info = ChannelInfo('stable', '1364', 25) older_stable_info = ChannelInfo('stable', '1312', 24) oldest_stable_info = ChannelInfo('stable', '396', 5) self.assertEquals(dev_info, self._branch_util.Older(trunk_info)) self.assertEquals(beta_info, self._branch_util.Older(dev_info)) self.assertEquals(stable_info, self._branch_util.Older(beta_info)) self.assertEquals(old_stable_info, self._branch_util.Older(stable_info)) self.assertEquals(older_stable_info, self._branch_util.Older(old_stable_info)) # Test the lower limit. self.assertEquals(None, self._branch_util.Older(oldest_stable_info)) def testGetChannelInfo(self): trunk_info = ChannelInfo('trunk', 'trunk', 'trunk') self.assertEquals(trunk_info, self._branch_util.GetChannelInfo('trunk')) dev_info = ChannelInfo('dev', '1500', 28) self.assertEquals(dev_info, self._branch_util.GetChannelInfo('dev')) beta_info = ChannelInfo('beta', '1453', 27) self.assertEquals(beta_info, self._branch_util.GetChannelInfo('beta')) stable_info = ChannelInfo('stable', '1410', 26) self.assertEquals(stable_info, self._branch_util.GetChannelInfo('stable')) def testGetLatestVersionNumber(self): self.assertEquals(28, self._branch_util.GetLatestVersionNumber()) def testGetBranchForVersion(self): self.assertEquals('1500', self._branch_util.GetBranchForVersion(28)) self.assertEquals('1453', self._branch_util.GetBranchForVersion(27)) self.assertEquals('1410', self._branch_util.GetBranchForVersion(26)) self.assertEquals('1364', self._branch_util.GetBranchForVersion(25)) self.assertEquals('1312', self._branch_util.GetBranchForVersion(24)) self.assertEquals('1271', self._branch_util.GetBranchForVersion(23)) self.assertEquals('1229', self._branch_util.GetBranchForVersion(22)) self.assertEquals('1180', self._branch_util.GetBranchForVersion(21)) self.assertEquals('1132', self._branch_util.GetBranchForVersion(20)) self.assertEquals('1084', self._branch_util.GetBranchForVersion(19)) self.assertEquals('1025', self._branch_util.GetBranchForVersion(18)) self.assertEquals('963', self._branch_util.GetBranchForVersion(17)) self.assertEquals('696', self._branch_util.GetBranchForVersion(11)) self.assertEquals('396', self._branch_util.GetBranchForVersion(5)) def testGetChannelForVersion(self): self.assertEquals('trunk', self._branch_util.GetChannelForVersion('trunk')) self.assertEquals('dev', self._branch_util.GetChannelForVersion(28)) self.assertEquals('beta', self._branch_util.GetChannelForVersion(27)) self.assertEquals('stable', self._branch_util.GetChannelForVersion(26)) self.assertEquals('stable', self._branch_util.GetChannelForVersion(22)) self.assertEquals('stable', self._branch_util.GetChannelForVersion(18)) self.assertEquals('stable', self._branch_util.GetChannelForVersion(14)) self.assertEquals(None, self._branch_util.GetChannelForVersion(30)) self.assertEquals(None, self._branch_util.GetChannelForVersion(42))