Skip to content

Commit

Permalink
Add a config variable to add a link to whatsdeployed in contribute.json
Browse files Browse the repository at this point in the history
  • Loading branch information
Rémy HUBSCHER committed Jan 11, 2018
1 parent 1dcc71d commit 3a6f93e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
26 changes: 14 additions & 12 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,17 @@ database services to configure.

However you can configure the following parameters using environment variables:

+-----------------------+-------------------------------------------------+
| **VARIABLE** | **Description** |
+-----------------------+-------------------------------------------------+
| ``PORT`` | The service PORT, by default runs on 9876 |
+-----------------------+-------------------------------------------------+
| ``VERSION_FILE`` | The JSON version file, default PWD/version.json |
+-----------------------+-------------------------------------------------+
| ``CACHE_MAX_AGE`` | The Cache-Control max-age value, default to 30 |
| | seconds. Set it to 0 to set it to no-cache |
+-----------------------+-------------------------------------------------+
| ``TELEMETRY_API_KEY`` | API KEY to use to query the Telemetry Service |
+-----------------------+-------------------------------------------------+
+-----------------------+--------------------------------------------------+
| **VARIABLE** | **Description** |
+-----------------------+--------------------------------------------------+
| ``PORT`` | The service PORT, by default runs on 9876 |
+-----------------------+--------------------------------------------------+
| ``VERSION_FILE`` | The JSON version file, default PWD/version.json |
+-----------------------+--------------------------------------------------+
| ``CACHE_MAX_AGE`` | The Cache-Control max-age value, default to 30 |
| | seconds. Set it to 0 to set it to no-cache |
+-----------------------+--------------------------------------------------+
| ``TELEMETRY_API_KEY`` | API KEY to use to query the Telemetry Service |
+-----------------------+--------------------------------------------------+
| ``WHATSDEPLOYED_URL`` | Short URL link to https://whatsdeployed.io/s-9sl |
+-----------------------+--------------------------------------------------+
9 changes: 7 additions & 2 deletions pollbot/views/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ async def version(request):
return web.HTTPNotFound()


def render_yaml_file(filename):
def render_yaml_file(filename, **options):
with open(os.path.join(HERE, "..", filename)) as stream:
content = yaml.safe_load(stream)
content.update(options)
return web.json_response(content)


Expand All @@ -34,7 +35,11 @@ async def oas_spec(request):


async def contribute_json(request):
return render_yaml_file("contribute.yaml")
settings = {}
whatsdeployed_url = os.getenv('WHATSDEPLOYED_URL')
if whatsdeployed_url:
settings['whatsdeployed'] = whatsdeployed_url
return render_yaml_file("contribute.yaml", **settings)


async def contribute_redirect(request):
Expand Down
13 changes: 12 additions & 1 deletion tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ async def test_redirects_trailing_slashes(cli):
assert resp.headers['Location'] == "/v1/firefox/54.0"


async def check_yaml_resource(cli, url, filename):
async def check_yaml_resource(cli, url, filename, **options):
with open(os.path.join(HERE, "..", "pollbot", filename)) as stream:
content = yaml.safe_load(stream)
content.update(options)
resp = await cli.get(url)
assert await resp.json() == content

Expand All @@ -77,6 +78,16 @@ async def test_contribute_redirect(cli):
assert resp.headers['Location'] == "/v1/contribute.json"


async def test_contribute_json_with_whatsdeployed_url(cli):
whatsdeployed_url = ' https://whatsdeployed.io/s-9sl'
os.environ['WHATSDEPLOYED_URL'] = whatsdeployed_url
try:
await check_yaml_resource(cli, "/v1/contribute.json", "contribute.yaml",
whatsdeployed=whatsdeployed_url)
finally:
del os.environ['WHATSDEPLOYED_URL']


async def test_contribute_json(cli):
await check_yaml_resource(cli, "/v1/contribute.json", "contribute.yaml")

Expand Down

0 comments on commit 3a6f93e

Please sign in to comment.