Adding AvailabilityFinder to Doc Server.

This is a large part of automatically generating API intro tables.
This patch does not connect AvailabilityFinder with the rest of the server; a future patch will take care of that.

BUG=233968

Review URL: https://chromiumcodereview.appspot.com/17397010

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@208075 0039d316-1c4b-4281-b951-d872f2087c98
parent 15fe3270
application: chrome-apps-doc
version: 2-7-1
version: 2-7-2
runtime: python27
api_version: 1
threadsafe: false
......
This diff is collapsed.
#!/usr/bin/env python
# Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import os
import sys
import unittest
from availability_finder import AvailabilityFinder
from branch_utility import BranchUtility
from compiled_file_system import CompiledFileSystem
from fake_url_fetcher import FakeUrlFetcher
from object_store_creator import ObjectStoreCreator
from test_file_system import TestFileSystem
from test_data.canned_data import (CANNED_API_FILE_SYSTEM_DATA, CANNED_BRANCHES)
def _CreateCannedFileSystem(version):
branch = CANNED_BRANCHES[version]
return TestFileSystem(CANNED_API_FILE_SYSTEM_DATA[str(branch)])
class AvailabilityFinderTest(unittest.TestCase):
def setUp(self):
self._avail_ds_factory = AvailabilityFinder.Factory(
ObjectStoreCreator.ForTest(),
CompiledFileSystem.Factory(
TestFileSystem(CANNED_API_FILE_SYSTEM_DATA['trunk']),
ObjectStoreCreator.ForTest()),
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()),
_CreateCannedFileSystem)
self._avail_ds = self._avail_ds_factory.Create()
def testGetApiAvailability(self):
# Key: Using 'channel' (i.e. 'beta') to represent an availability listing
# for an API in a _features.json file, and using |channel| (i.e. |dev|) to
# represent the development channel, or phase of development, where an API's
# availability is being checked.
# Testing the predetermined APIs found in
# templates/json/api_availabilities.json.
self.assertEqual('stable',
self._avail_ds.GetApiAvailability('jsonAPI1').channel)
self.assertEqual(10,
self._avail_ds.GetApiAvailability('jsonAPI1').version)
self.assertEqual('trunk',
self._avail_ds.GetApiAvailability('jsonAPI2').channel)
self.assertEqual(None,
self._avail_ds.GetApiAvailability('jsonAPI2').version)
self.assertEqual('dev',
self._avail_ds.GetApiAvailability('jsonAPI3').channel)
self.assertEqual(None,
self._avail_ds.GetApiAvailability('jsonAPI3').version)
# Testing APIs found only by checking file system existence.
self.assertEquals('stable',
self._avail_ds.GetApiAvailability('windows').channel)
self.assertEquals(23,
self._avail_ds.GetApiAvailability('windows').version)
self.assertEquals('stable',
self._avail_ds.GetApiAvailability('tabs').channel)
self.assertEquals(18,
self._avail_ds.GetApiAvailability('tabs').version)
self.assertEquals('stable',
self._avail_ds.GetApiAvailability('input.ime').channel)
self.assertEquals(18,
self._avail_ds.GetApiAvailability('input.ime').version)
# Testing API channel existence for _api_features.json.
# Listed as 'dev' on |beta|, 'dev' on |dev|.
self.assertEquals('dev',
self._avail_ds.GetApiAvailability('systemInfo.stuff').channel)
self.assertEquals(28,
self._avail_ds.GetApiAvailability('systemInfo.stuff').version)
# Listed as 'stable' on |beta|.
self.assertEquals('beta',
self._avail_ds.GetApiAvailability('systemInfo.cpu').channel)
self.assertEquals(27,
self._avail_ds.GetApiAvailability('systemInfo.cpu').version)
# Testing API channel existence for _manifest_features.json.
# Listed as 'trunk' on all channels.
self.assertEquals('trunk',
self._avail_ds.GetApiAvailability('sync').channel)
self.assertEquals('trunk',
self._avail_ds.GetApiAvailability('sync').version)
# No records of API until |trunk|.
self.assertEquals('trunk',
self._avail_ds.GetApiAvailability('history').channel)
self.assertEquals('trunk',
self._avail_ds.GetApiAvailability('history').version)
# Listed as 'dev' on |dev|.
self.assertEquals('dev',
self._avail_ds.GetApiAvailability('storage').channel)
self.assertEquals(28,
self._avail_ds.GetApiAvailability('storage').version)
# Stable in _manifest_features and into pre-18 versions.
self.assertEquals('stable',
self._avail_ds.GetApiAvailability('pageAction').channel)
self.assertEquals(8,
self._avail_ds.GetApiAvailability('pageAction').version)
# Testing API channel existence for _permission_features.json.
# Listed as 'beta' on |trunk|.
self.assertEquals('trunk',
self._avail_ds.GetApiAvailability('falseBetaAPI').version)
self.assertEquals('trunk',
self._avail_ds.GetApiAvailability('falseBetaAPI').version)
# Listed as 'trunk' on |trunk|.
self.assertEquals('trunk',
self._avail_ds.GetApiAvailability('trunkAPI').channel)
self.assertEquals('trunk',
self._avail_ds.GetApiAvailability('trunkAPI').version)
# Listed as 'trunk' on all development channels.
self.assertEquals('trunk',
self._avail_ds.GetApiAvailability('declarativeContent').channel)
self.assertEquals('trunk',
self._avail_ds.GetApiAvailability('declarativeContent').version)
# Listed as 'dev' on all development channels.
self.assertEquals('dev',
self._avail_ds.GetApiAvailability('bluetooth').channel)
self.assertEquals(28,
self._avail_ds.GetApiAvailability('bluetooth').version)
# Listed as 'dev' on |dev|.
self.assertEquals('dev',
self._avail_ds.GetApiAvailability('cookies').channel)
self.assertEquals(28,
self._avail_ds.GetApiAvailability('cookies').version)
# Treated as 'stable' APIs.
self.assertEquals('stable',
self._avail_ds.GetApiAvailability('alarms').channel)
self.assertEquals(24,
self._avail_ds.GetApiAvailability('alarms').version)
self.assertEquals('stable',
self._avail_ds.GetApiAvailability('bookmarks').channel)
self.assertEquals(21,
self._avail_ds.GetApiAvailability('bookmarks').version)
# Testing older API existence using extension_api.json.
self.assertEquals('stable',
self._avail_ds.GetApiAvailability('menus').channel)
self.assertEquals(6,
self._avail_ds.GetApiAvailability('menus').version)
self.assertEquals('stable',
self._avail_ds.GetApiAvailability('idle').channel)
self.assertEquals(5,
self._avail_ds.GetApiAvailability('idle').version)
# Switches between _features.json files across branches.
# Listed as 'trunk' on all channels, in _api, _permission, or _manifest.
self.assertEquals('trunk',
self._avail_ds.GetApiAvailability('contextMenus').channel)
self.assertEquals('trunk',
self._avail_ds.GetApiAvailability('contextMenus').version)
# Moves between _permission and _manifest as file system is traversed.
self.assertEquals('stable',
self._avail_ds.GetApiAvailability('systemInfo.display').channel)
self.assertEquals(23,
self._avail_ds.GetApiAvailability('systemInfo.display').version)
self.assertEquals('stable',
self._avail_ds.GetApiAvailability('webRequest').channel)
self.assertEquals(17,
self._avail_ds.GetApiAvailability('webRequest').version)
# Mid-upgrade cases:
# Listed as 'dev' on |beta| and 'beta' on |dev|.
self.assertEquals('dev',
self._avail_ds.GetApiAvailability('notifications').channel)
self.assertEquals(28,
self._avail_ds.GetApiAvailability('notifications').version)
# Listed as 'beta' on |stable|, 'dev' on |beta| ... until |stable| on trunk.
self.assertEquals('trunk',
self._avail_ds.GetApiAvailability('events').channel)
self.assertEquals('trunk',
self._avail_ds.GetApiAvailability('events').version)
if __name__ == '__main__':
unittest.main()
......@@ -137,14 +137,23 @@ class BranchUtility(object):
version_json = json.loads(self._history_result.Get().content)
for entry in version_json['events']:
# Here, entry['title'] looks like: 'title - version#.#.branch#.#'
# Here, entry['title'] looks like: '<title> - <version>.##.<branch>.##'
version_title = entry['title'].split(' - ')[1].split('.')
if version_title[0] == str(version):
self._branch_object_store.Set(str(version), version_title[2])
return int(version_title[2])
raise ValueError(
'The branch for %s could not be found.' % version)
raise ValueError('The branch for %s could not be found.' % version)
def GetChannelForVersion(self, version):
'''Returns the name of the development channel corresponding to a given
version number.
'''
for channel_info in self.GetAllChannelInfo():
if channel_info.channel == 'stable' and version <= channel_info.version:
return channel_info.channel
if version == channel_info.version:
return channel_info.channel
def GetLatestVersionNumber(self):
'''Returns the most recent version number found using data stored on
......
......@@ -120,5 +120,26 @@ class BranchUtilityTest(unittest.TestCase):
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))
if __name__ == '__main__':
unittest.main()
......@@ -2,19 +2,19 @@ cron:
- description: Load everything for trunk.
url: /_cron/trunk
schedule: every 5 minutes
target: 2-7-1
target: 2-7-2
- description: Load everything for dev.
url: /_cron/dev
schedule: every 5 minutes
target: 2-7-1
target: 2-7-2
- description: Load everything for beta.
url: /_cron/beta
schedule: every 5 minutes
target: 2-7-1
target: 2-7-2
- description: Load everything for stable.
url: /_cron/stable
schedule: every 5 minutes
target: 2-7-1
target: 2-7-2
......@@ -27,7 +27,7 @@ class _TestDelegate(CronServlet.Delegate):
self._app_version = GetAppVersion()
def CreateBranchUtility(self, object_store_creator):
return TestBranchUtility()
return TestBranchUtility.CreateWithCannedData()
def CreateHostFileSystemForBranchAndRevision(self, branch, revision):
file_system = self._create_file_system(revision)
......
......@@ -19,7 +19,7 @@ class _TestDelegate(InstanceServlet.Delegate):
self._file_system_type = file_system_type
def CreateBranchUtility(self, object_store_creator):
return TestBranchUtility()
return TestBranchUtility.CreateWithCannedData()
def CreateHostFileSystemForBranch(self, branch):
return self._file_system_type()
......
......@@ -3,19 +3,38 @@
# found in the LICENSE file.
from branch_utility import BranchUtility, ChannelInfo
from test_data.canned_data import (CANNED_BRANCHES, CANNED_CHANNELS)
class TestBranchUtility(object):
'''Mimics BranchUtility to return valid-ish data without needing omahaproxy
data.
'''
def __init__(self, branches, channels):
''' Parameters: |branches| is a mapping of versions to branches, and
|channels| is a mapping of channels to versions.
'''
self._branches = branches
self._channels = channels
@staticmethod
def CreateWithCannedData():
'''Returns a TestBranchUtility that uses 'canned' test data pulled from
older branches of SVN data.
'''
return TestBranchUtility(CANNED_BRANCHES, CANNED_CHANNELS)
def GetAllChannelInfo(self):
return [self.GetChannelInfo(channel)
for channel in BranchUtility.GetAllChannelNames()]
def GetChannelInfo(self, channel):
return ChannelInfo(channel,
'fakebranch-%s' % channel,
'fakeversion-%s' % channel)
version = self._channels[channel]
return ChannelInfo(channel, self.GetBranchForVersion(version), version)
def GetBranchForVersion(self, version):
return 'fakebranch-%s' % version
return self._branches[version]
def GetChannelForVersion(self, version):
for channel in self._channels.iterkeys():
if self._channels[channel] == version:
return channel
This diff is collapsed.
{
"devtools.inspectedWindow": {
"channel": "stable",
"version": 18
},
"devtools.network": {
"channel": "stable",
"version": 18
},
"devtools.panels": {
"channel": "stable",
"version": 18
},
"webstore": {
"channel": "stable",
"version": 15
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment