Skip to content

Commit

Permalink
Merge pull request #27 from mozilla/3-product-details-published
Browse files Browse the repository at this point in the history
Add the product-details tasks and endpoint
  • Loading branch information
Natim committed Aug 7, 2017
2 parents 50483a8 + 549ec1b commit 478c490
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 6 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ CHANGELOG
------------------

- Add the /v1/ info page (#10)
- Add the release status checks
- Add the releasenotes bot (#16)
- Add the bedrock release-notes bot (#16)
- Add the archive.mozilla.org bot (#17)
- Expose the Open API Specification (#23)
- Add the contribute.json endpoint (#25)
- Add the bedrock security-advisories bot (#26)
- Add the product-details bot (#27)
2 changes: 2 additions & 0 deletions pollbot/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ def get_app(loop=None):
release.bedrock_release_notes)
app.router.add_get('/v1/{product}/{version}/bedrock/security-advisories',
release.bedrock_security_advisories)
app.router.add_get('/v1/{product}/{version}/product-details',
release.product_details)
return app
13 changes: 13 additions & 0 deletions pollbot/tasks/product_details.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import aiohttp
from pollbot.exceptions import TaskError


async def product_details_published(product, version):
with aiohttp.ClientSession() as session:
url = 'https://product-details.mozilla.org/1.0/{}.json'.format(product)
async with session.get(url) as resp:
if resp.status != 200:
msg = 'Product Details info not available ({})'.format(resp.status)
raise TaskError(msg)
body = await resp.json()
return '{}-{}'.format(product, version) in body['releases']
2 changes: 2 additions & 0 deletions pollbot/views/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from ..exceptions import TaskError
from ..tasks.archives import archives_published
from ..tasks.bedrock import release_notes_published, security_advisories_published
from ..tasks.product_details import product_details_published


def status_response(task):
Expand Down Expand Up @@ -33,3 +34,4 @@ async def wrapped(request):
archive = status_response(archives_published)
bedrock_release_notes = status_response(release_notes_published)
bedrock_security_advisories = status_response(security_advisories_published)
product_details = status_response(product_details_published)
33 changes: 29 additions & 4 deletions tests/test_tasks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json

import aiohttp
import asynctest
import pytest
Expand All @@ -7,6 +9,7 @@
from pollbot.exceptions import TaskError
from pollbot.tasks.archives import archives_published
from pollbot.tasks.bedrock import release_notes_published, security_advisories_published
from pollbot.tasks.product_details import product_details_published


class DeliveryTasksTest(asynctest.TestCase):
Expand Down Expand Up @@ -46,31 +49,53 @@ async def test_archives_tasks_returns_false_if_absent(self):
received = await archives_published('firefox', '52.0.2')
assert received is False

async def test_security_advisory_tasks_returns_true_if_version_matches(self):
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_published('firefox', '52.0.2')
assert received is True

async def test_security_advisory_tasks_returns_true_if_older_version(self):
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>')

received = await security_advisories_published('firefox', '52.0')
assert received is True

async def test_security_advisory_tasks_returns_false_if_newer_version(self):
async def test_security_advisories_tasks_returns_false_if_newer_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>')

received = await security_advisories_published('firefox', '54.0')
assert received is False

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

with pytest.raises(TaskError) as excinfo:
await security_advisories_published('firefox', '54.0')
assert str(excinfo.value) == 'Security advisories page not available (404)'

async def test_product_details_tasks_returns_true_if_present(self):
url = 'https://product-details.mozilla.org/1.0/firefox.json'
self.mocked.get(url, status=200, body=json.dumps({"releases": {"firefox-52.0": {}}}))

received = await product_details_published('firefox', '52.0')
assert received is True

async def test_product_details_tasks_returns_false_if_absent(self):
url = 'https://product-details.mozilla.org/1.0/firefox.json'
self.mocked.get(url, status=200, body=json.dumps({"releases": {"firefox-52.0": {}}}))

received = await product_details_published('firefox', '54.0')
assert received is False

async def test_product_details_tasks_returns_error_if_error(self):
url = 'https://product-details.mozilla.org/1.0/firefox.json'
self.mocked.get(url, status=404)

with pytest.raises(TaskError) as excinfo:
await product_details_published('firefox', '54.0')
assert str(excinfo.value) == 'Product Details info not available (404)'
15 changes: 15 additions & 0 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,18 @@ async def test_release_bedrock_security_advisories_404(cli):
"status": 404,
"message": "Invalid product: invalid-product not in ['firefox']"
})


async def test_release_product_details(cli):
await check_response(cli, "/v1/firefox/54.0/product-details",
body={
"status": "exists"
})


async def test_release_product_details_404(cli):
await check_response(cli, "/v1/invalid-product/54.0/product-details",
status=404, body={
"status": 404,
"message": "Invalid product: invalid-product not in ['firefox']"
})

0 comments on commit 478c490

Please sign in to comment.