Skip to content

Commit

Permalink
Merge branch 'GoogleChrome:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafacco7 authored Sep 30, 2024
2 parents 3a0b25a + 92b37fe commit cf12aa5
Show file tree
Hide file tree
Showing 64 changed files with 1,254 additions and 595 deletions.
48 changes: 5 additions & 43 deletions api/channels_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
import settings


SCHEDULE_CACHE_TIME = 60 * 60 # 1 hour


def construct_chrome_channels_details():
omaha_data = fetchchannels.get_omaha_data()
channels = {}
Expand All @@ -34,71 +31,36 @@ def construct_chrome_channels_details():
for v in win_versions:
channel = v['channel']
major_version = int(v['version'].split('.')[0])
channels[channel] = fetch_chrome_release_info(major_version)
channels[channel] = fetchchannels.fetch_chrome_release_info(major_version)
channels[channel]['version'] = major_version

# Adjust for the brief period after next miletone gets promted to stable/beta
# channel and their major versions are the same.
if channels['stable']['version'] == channels['beta']['version']:
new_beta_version = channels['stable']['version'] + 1
channels['beta'] = fetch_chrome_release_info(new_beta_version)
channels['beta'] = fetchchannels.fetch_chrome_release_info(new_beta_version)
channels['beta']['version'] = new_beta_version
if channels['beta']['version'] == channels['dev']['version']:
new_dev_version = channels['beta']['version'] + 1
channels['dev'] = fetch_chrome_release_info(new_dev_version)
channels['dev'] = fetchchannels.fetch_chrome_release_info(new_dev_version)
channels['dev']['version'] = new_dev_version

# In the situation where some versions are in a gap between
# stable and beta, show one as 'stable_soon'.
if channels['stable']['version'] + 1 < channels['beta']['version']:
stable_soon_version = channels['stable']['version'] + 1
channels['stable_soon'] = fetch_chrome_release_info(stable_soon_version)
channels['stable_soon'] = fetchchannels.fetch_chrome_release_info(stable_soon_version)
channels['stable_soon']['version'] = stable_soon_version

return channels


def fetch_chrome_release_info(version):
key = 'chromerelease|%s' % version

data = rediscache.get(key)
if data is None:
url = ('https://chromiumdash.appspot.com/fetch_milestone_schedule?'
'mstone=%s' % version)
result = requests.get(url, timeout=60)
if result.status_code == 200:
try:
logging.info(
'result.content is:\n%s', result.content[:settings.MAX_LOG_LINE])
result_json = json.loads(result.content)
if 'mstones' in result_json:
data = result_json['mstones'][0]
del data['owners']
del data['feature_freeze']
del data['ldaps']
rediscache.set(key, data, time=SCHEDULE_CACHE_TIME)
except ValueError:
pass # Handled by next statement

if not data:
data = {
'stable_date': None,
'earliest_beta': None,
'latest_beta': None,
'mstone': version,
'version': version,
}
# Note: we don't put placeholder data into redis.

return data


def construct_specified_milestones_details(start, end):
channels = {}
win_versions = list(range(start,end+1))

for milestone in win_versions:
channels[milestone] = fetch_chrome_release_info(milestone)
channels[milestone] = fetchchannels.fetch_chrome_release_info(milestone)

return channels

Expand Down
63 changes: 4 additions & 59 deletions api/channels_api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def setUp(self):
self.handler = channels_api.ChannelsAPI()
self.request_path = '/api/v0/channels'

@mock.patch('api.channels_api.fetch_chrome_release_info')
@mock.patch('internals.fetchchannels.fetch_chrome_release_info')
@mock.patch('internals.fetchchannels.get_omaha_data')
def test_construct_chrome_channels_details(
self, mock_get_omaha_data, mock_fetch_chrome_release_info):
Expand Down Expand Up @@ -93,7 +93,7 @@ def fcri(version):
self.maxDiff = None
self.assertEqual(expected, actual)

@mock.patch('api.channels_api.fetch_chrome_release_info')
@mock.patch('internals.fetchchannels.fetch_chrome_release_info')
@mock.patch('internals.fetchchannels.get_omaha_data')
def test_construct_chrome_channels_details__beta_promotion(
self, mock_get_omaha_data, mock_fetch_chrome_release_info):
Expand Down Expand Up @@ -142,7 +142,7 @@ def fcri(version):
self.maxDiff = None
self.assertEqual(expected, actual)

@mock.patch('api.channels_api.fetch_chrome_release_info')
@mock.patch('internals.fetchchannels.fetch_chrome_release_info')
@mock.patch('internals.fetchchannels.get_omaha_data')
def test_construct_chrome_channels_details__dev_promotion(
self, mock_get_omaha_data, mock_fetch_chrome_release_info):
Expand Down Expand Up @@ -192,62 +192,7 @@ def fcri(version):
self.maxDiff = None
self.assertEqual(expected, actual)

@mock.patch('requests.get')
def test_fetch_chrome_release_info__found(self, mock_requests_get):
"""We can get channel data from the chromiumdash app."""
mock_requests_get.return_value = testing_config.Blank(
status_code=200,
content=json.dumps({
'mstones': [{
'owners': 'ignored',
'feature_freeze': 'ignored',
'ldaps': 'ignored',
'everything else': 'kept',
}],
}))

actual = channels_api.fetch_chrome_release_info(90)

self.assertEqual(
{'everything else': 'kept'},
actual)

@mock.patch('requests.get')
def test_fetch_chrome_release_info__not_found(self, mock_requests_get):
"""If chromiumdash app does not have the data, use a placeholder."""
mock_requests_get.return_value = testing_config.Blank(
status_code=404, content='')

actual = channels_api.fetch_chrome_release_info(91)

self.assertEqual(
{'stable_date': None,
'earliest_beta': None,
'latest_beta': None,
'mstone': 91,
'version': 91,
},
actual)

@mock.patch('requests.get')
def test_fetch_chrome_release_info__error(self, mock_requests_get):
"""We can get channel data from the chromiumdash app."""
mock_requests_get.return_value = testing_config.Blank(
status_code=200,
content='{')

actual = channels_api.fetch_chrome_release_info(90)

self.assertEqual(
{'stable_date': None,
'earliest_beta': None,
'latest_beta': None,
'mstone': 90,
'version': 90,
},
actual)

@mock.patch('api.channels_api.fetch_chrome_release_info')
@mock.patch('internals.fetchchannels.fetch_chrome_release_info')
def test_construct_specified_milestones_details(
self, mock_fetch_chrome_release_info):
mstone_data = {
Expand Down
2 changes: 1 addition & 1 deletion api/converters_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def test_feature_entry_to_json_verbose__normal(self):
'is_released': True,
'category': 'Web Components',
'category_int': 1,
'feature_type': 'New feature incubation',
'feature_type': 'New or changed feature',
'feature_type_int': 0,
'is_enterprise_feature': False,
'intent_stage': 'Start prototyping',
Expand Down
2 changes: 2 additions & 0 deletions api/feature_latency_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

from api import channels_api
from framework import basehandlers
from framework import permissions
from internals import stage_helpers
from internals.core_enums import *
from internals.core_models import FeatureEntry, Stage
Expand Down Expand Up @@ -53,6 +54,7 @@ def get_date_range(

return start_date, end_date

@permissions.require_create_feature
def do_get(self, **kwargs):
"""Calculate feature latency for features in a date range.
Expand Down
23 changes: 23 additions & 0 deletions api/feature_latency_api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from api import feature_latency_api
from internals.core_enums import *
from internals.core_models import FeatureEntry, Stage, MilestoneSet
from internals import user_models


test_app = flask.Flask(__name__)
Expand All @@ -45,6 +46,10 @@ def make_feature(name, created_tuple, status, shipped):
class FeatureLatencyAPITest(testing_config.CustomTestCase):

def setUp(self):
self.app_admin = user_models.AppUser(email='[email protected]')
self.app_admin.is_admin = True
self.app_admin.put()

self.handler = feature_latency_api.FeatureLatencyAPI()
self.request_path = '/api/v0/feature-latency'

Expand All @@ -64,6 +69,8 @@ def setUp(self):
'launched after end', (2023, 9, 29), ENABLED_BY_DEFAULT, 125)

def tearDown(self):
testing_config.sign_out()
self.app_admin.key.delete()
kinds: list[ndb.Model] = [FeatureEntry, Stage]
for kind in kinds:
for entity in kind.query():
Expand All @@ -85,8 +92,23 @@ def test_get_date_range__specified(self):
datetime(2023, 12, 24)),
actual)

def test_do_get__anon(self):
"""Only users who can create features can view reports."""
testing_config.sign_out()
with test_app.test_request_context(self.request_path):
with self.assertRaises(werkzeug.exceptions.Forbidden):
self.handler.do_get()

def test_do_get__rando(self):
"""Only users who can create features can view reports."""
testing_config.sign_in('[email protected]', 1232345)
with test_app.test_request_context(self.request_path):
with self.assertRaises(werkzeug.exceptions.Forbidden):
self.handler.do_get()

def test_do_get__normal(self):
"""It finds some feature launches to include and excludes others."""
testing_config.sign_in('[email protected]', 123567890)
path = self.request_path + '?startAt=2023-01-01&endAt=2024-01-01'
with test_app.test_request_context(path):
actual = self.handler.do_get()
Expand All @@ -103,6 +125,7 @@ def test_do_get__normal(self):

def test_do_get__zero_results(self):
"""There were no test launches in this range."""
testing_config.sign_in('[email protected]', 123567890)
path = self.request_path + '?startAt=2020-01-01&endAt=2020-03-01'
with test_app.test_request_context(path):
actual = self.handler.do_get()
Expand Down
Loading

0 comments on commit cf12aa5

Please sign in to comment.