Skip to content

Commit

Permalink
Merge pull request #60 from mozilla/49-handle-other-release-channels
Browse files Browse the repository at this point in the history
Add support for other release channels
  • Loading branch information
Natim committed Aug 11, 2017
2 parents 98b2cca + 7644f47 commit 12bd738
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 6 deletions.
52 changes: 46 additions & 6 deletions pollbot/tasks/bedrock.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import re

from pyquery import PyQuery as pq
from urllib.parse import urlparse, parse_qs

from pollbot.exceptions import TaskError
from pollbot.utils import build_version_id
from pollbot.utils import build_version_id, Channel, get_version_channel
from . import get_session, heartbeat_factory


Expand All @@ -19,13 +23,27 @@ async def get_releases(product):


async def release_notes(product, version):
channel = get_version_channel(version)
if channel is Channel.BETA:
parts = version.split('b')
version = "{}beta".format(parts[0])
elif channel is Channel.ESR:
version = re.sub('esr$', '', version)

url = 'https://www.mozilla.org/en-US/{}/{}/releasenotes/'.format(product, version)

with get_session() as session:
url = 'https://www.mozilla.org/en-US/{}/{}/releasenotes/'.format(product, version)
async with session.get(url) as resp:
return resp.status != 404


async def security_advisories(product, version):
channel = get_version_channel(version)
# Security advisories are always present for BETA and NIGHTLY
# because we don't publish any.
if channel in (Channel.BETA, Channel.NIGHTLY):
return True

with get_session() as session:
url = 'https://www.mozilla.org/en-US/security/known-vulnerabilities/{}/'.format(product)
async with session.get(url) as resp:
Expand All @@ -35,21 +53,43 @@ async def security_advisories(product, version):
# Does the content contains the version number?
body = await resp.text()
d = pq(body)
last_release = d("html").attr('data-latest-firefox')

if channel is Channel.ESR:
version = re.sub('esr$', '', version)
last_release = d("html").attr('data-esr-versions')
else:
last_release = d("html").attr('data-latest-firefox')
return build_version_id(last_release) >= build_version_id(version)


async def download_links(product, version):
with get_session() as session:
channel = get_version_channel(version)
if channel in (Channel.ESR, Channel.RELEASE):
url = 'https://www.mozilla.org/en-US/{}/all/'.format(product)
else:
url = 'https://www.mozilla.org/fr/firefox/channel/desktop/'

with get_session() as session:
async with session.get(url) as resp:
if resp.status != 200:
msg = 'Download page not available ({})'.format(resp.status)
raise TaskError(msg)
# Does the content contains the version number?
body = await resp.text()
d = pq(body)
last_release = d("html").attr('data-latest-firefox')

if channel is Channel.BETA:
link_path = "#desktop-beta-download > .download-list > .os_linux64 > a"
url = d(link_path).attr('href')
qs = parse_qs(urlparse(url).query)
product_parts = qs["product"][0].split('-')
last_release = product_parts[1]
elif channel is Channel.ESR:
version = re.sub('esr$', '', version)
last_release = d("html").attr('data-esr-versions')
else:
# Does the content contains the version number?
last_release = d("html").attr('data-latest-firefox')

return build_version_id(last_release) >= build_version_id(version)


Expand Down
21 changes: 21 additions & 0 deletions pollbot/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
from enum import Enum


class Channel(Enum):
ESR = "ESR"
RELEASE = "RELEASE"
BETA = "BETA"
NIGHTLY = "NIGHTLY"


def version_parts(parts):
patch = '0'
major = parts[0]
Expand Down Expand Up @@ -27,3 +37,14 @@ def build_version_id(version):
major, minor, patch = version_parts(parts)
return '{}{}{}{}{}'.format(major.zfill(3), minor.zfill(3), patch.zfill(3),
release_code, channel.zfill(3))


def get_version_channel(version): # pragma: no cover
if version.endswith('esr'):
return Channel.ESR
elif 'a' in version:
return Channel.NIGHTLY
elif 'b' in version:
return Channel.BETA
else:
return Channel.RELEASE
71 changes: 71 additions & 0 deletions tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,27 @@ async def test_get_releases_tasks_returns_error_if_error(self):
await get_releases('firefox')
assert str(excinfo.value) == 'Releases page not available (404)'

async def test_releasenotes_tasks_returns_true_if_present_for_beta(self):
url = 'https://www.mozilla.org/en-US/firefox/56.0beta/releasenotes/'
self.mocked.get(url, status=200)

received = await release_notes('firefox', '56.0b2')
assert received is True

async def test_releasenotes_tasks_returns_true_if_present(self):
url = 'https://www.mozilla.org/en-US/firefox/52.0.2/releasenotes/'
self.mocked.get(url, status=200)

received = await release_notes('firefox', '52.0.2')
assert received is True

async def test_releasenotes_tasks_strip_esr_from_version_number(self):
url = 'https://www.mozilla.org/en-US/firefox/52.3.0/releasenotes/'
self.mocked.get(url, status=200)

received = await release_notes('firefox', '52.3.0esr')
assert received is True

async def test_releasenotes_tasks_returns_false_if_absent(self):
url = 'https://www.mozilla.org/en-US/firefox/52.0.2/releasenotes/'
self.mocked.get(url, status=404)
Expand Down Expand Up @@ -106,6 +120,49 @@ async def test_download_links_tasks_returns_true_if_version_matches(self):
received = await download_links('firefox', '52.0.2')
assert received is True

async def test_download_links_tasks_returns_true_if_version_matches_for_beta(self):
url = 'https://www.mozilla.org/fr/firefox/channel/desktop/'
self.mocked.get(url, status=200, body='''
<html>
<div id="desktop-beta-download">
<ul class="download-list">
<li class="os_linux64">
<a class="download-link"
href="https://download.mozilla.org/?product=firefox-56.0b1-SSL&amp;os=linux64"
>Téléchargement</a>
</li>
</ul>
</div>
</html>''')

received = await download_links('firefox', '56.0b1')
assert received is True

async def test_download_links_tasks_returns_true_if_older_version_for_beta(self):
url = 'https://www.mozilla.org/fr/firefox/channel/desktop/'
self.mocked.get(url, status=200, body='''
<html>
<div id="desktop-beta-download">
<ul class="download-list">
<li class="os_linux64">
<a class="download-link"
href="https://download.mozilla.org/?product=firefox-56.0b1-SSL&amp;os=linux64"
>Téléchargement</a>
</li>
</ul>
</div>
</html>''')

received = await download_links('firefox', '55.0b1')
assert received is True

async def test_download_links_tasks_returns_true_if_version_matches_esr(self):
url = 'https://www.mozilla.org/en-US/firefox/all/'
self.mocked.get(url, status=200, body='<html data-esr-versions="52.3.0"></html>')

received = await download_links('firefox', '52.3.0esr')
assert received is True

async def test_download_links_tasks_returns_true_if_older_version(self):
url = 'https://www.mozilla.org/en-US/firefox/all/'
self.mocked.get(url, status=200, body='<html data-latest-firefox="52.0.2"></html>')
Expand All @@ -128,13 +185,27 @@ async def test_download_links_tasks_returns_error_if_error(self):
await download_links('firefox', '54.0')
assert str(excinfo.value) == 'Download page not available (404)'

async def test_security_advisories_tasks_returns_true_for_beta(self):
url = 'https://www.mozilla.org/en-US/security/known-vulnerabilities/firefox/'
self.mocked.get(url, status=200)

received = await security_advisories('firefox', '56.b2')
assert received is True

async def test_security_advisories_tasks_returns_true_if_version_matches(self):
url = 'https://www.mozilla.org/en-US/security/known-vulnerabilities/firefox/'
self.mocked.get(url, status=200, body='<html data-latest-firefox="52.0.2"></html>')

received = await security_advisories('firefox', '52.0.2')
assert received is True

async def test_security_advisories_tasks_returns_true_if_version_matches_esr(self):
url = 'https://www.mozilla.org/en-US/security/known-vulnerabilities/firefox/'
self.mocked.get(url, status=200, body='<html data-esr-versions="52.3.0"></html>')

received = await security_advisories('firefox', '52.3.0esr')
assert received is True

async def test_security_advisories_tasks_returns_true_if_older_version(self):
url = 'https://www.mozilla.org/en-US/security/known-vulnerabilities/firefox/'
self.mocked.get(url, status=200, body='<html data-latest-firefox="52.0.2"></html>')
Expand Down

0 comments on commit 12bd738

Please sign in to comment.