-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
286 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
include LICENSE | ||
global-exclude *.py[co] | ||
include specification.yml | ||
include package.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[tools:pytest] | ||
flake8-max-line-length = 120 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import json | ||
import os | ||
from setuptools import setup | ||
|
||
package_json = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'package.json') | ||
with open(package_json) as f: | ||
version = json.load(f)['version'] | ||
|
||
setup( | ||
name='taskcluster-urls', | ||
description='Standardized url generator for taskcluster resources.', | ||
long_description=open(os.path.join(os.path.dirname(__file__), 'README.md')).read(), | ||
url='https://github.com/taskcluster/taskcluster-lib-urls', | ||
version=version, | ||
packages=['taskcluster_urls'], | ||
author='Brian Stack', | ||
author_email='[email protected]', | ||
license='MPL2', | ||
classifiers=[ | ||
'License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)', | ||
'Programming Language :: Python :: 2', | ||
'Programming Language :: Python :: 2.7', | ||
'Programming Language :: Python :: 3', | ||
'Programming Language :: Python :: 3.5', | ||
'Programming Language :: Python :: 3.6', | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
OLD_ROOT_URL = 'https://taskcluster.net' | ||
|
||
def api(root_url, service, version, path): | ||
"""Generate URL for path in a Taskcluster service.""" | ||
root_url = root_url.rstrip('/') | ||
path = path.lstrip('/') | ||
if root_url == OLD_ROOT_URL: | ||
return 'https://{}.taskcluster.net/{}/{}'.format(service, version, path) | ||
else: | ||
return '{}/api/{}/{}/{}'.format(root_url, service, version, path) | ||
|
||
def apiReference(root_url, service, version): | ||
"""Generate URL for a Taskcluster api reference.""" | ||
root_url = root_url.rstrip('/') | ||
if root_url == OLD_ROOT_URL: | ||
return 'https://references.taskcluster.net/{}/{}/api.json'.format(service, version) | ||
else: | ||
return '{}/references/{}/{}/api.json'.format(root_url, service, version) | ||
|
||
def docs(root_url, path): | ||
"""Generate URL for path in the Taskcluster docs.""" | ||
root_url = root_url.rstrip('/') | ||
path = path.lstrip('/') | ||
if root_url == OLD_ROOT_URL: | ||
return 'https://docs.taskcluster.net/{}'.format(path) | ||
else: | ||
return '{}/docs/{}'.format(root_url, path) | ||
|
||
def exchangeReference(root_url, service, version): | ||
"""Generate URL for a Taskcluster exchange reference.""" | ||
root_url = root_url.rstrip('/') | ||
if root_url == OLD_ROOT_URL: | ||
return 'https://references.taskcluster.net/{}/{}/exchanges.json'.format(service, version) | ||
else: | ||
return '{}/references/{}/{}/exchanges.json'.format(root_url, service, version) | ||
|
||
def schema(root_url, service, name): | ||
"""Generate URL for a schema in a Taskcluster service.""" | ||
root_url = root_url.rstrip('/') | ||
name = name.lstrip('/') | ||
if root_url == OLD_ROOT_URL: | ||
return 'https://schemas.taskcluster.net/{}/{}'.format(service, name) | ||
else: | ||
return '{}/schemas/{}/{}'.format(root_url, service, name) | ||
|
||
def ui(root_url, path): | ||
"""Generate URL for a path in the Taskcluster ui.""" | ||
root_url = root_url.rstrip('/') | ||
path = path.lstrip('/') | ||
if root_url == OLD_ROOT_URL: | ||
return 'https://tools.taskcluster.net/{}'.format(path) | ||
else: | ||
return '{}/{}'.format(root_url, path) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import os | ||
|
||
import yaml | ||
|
||
import taskcluster_urls as t | ||
|
||
|
||
SPEC_FILE = os.path.join(os.path.dirname(__file__), '..', 'specification.yml') | ||
OLD_ROOT_URL = 'https://taskcluster.net' | ||
ROOT_URL = 'https://taskcluster.example.com' | ||
|
||
|
||
def pytest_generate_tests(metafunc): | ||
with open(SPEC_FILE) as f: | ||
specs = yaml.load(f)['specs'] | ||
metafunc.parametrize( | ||
['func', 'args', 'expected_url', 'old_expected_url'], | ||
[(getattr(t, s['type']), | ||
a, s['expectedUrl'], s['oldExpectedUrl']) | ||
for s in specs | ||
for a in s['argSets'] | ||
] | ||
) | ||
|
||
|
||
def test_basic(func, args, expected_url, old_expected_url): | ||
assert func(ROOT_URL + '/', *args) == expected_url | ||
assert func(ROOT_URL, *args) == expected_url | ||
assert func(OLD_ROOT_URL + '/', *args) == old_expected_url | ||
assert func(OLD_ROOT_URL, *args) == old_expected_url |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[tox] | ||
envlist = py27,py36 | ||
|
||
[testenv] | ||
deps = | ||
pyyaml | ||
pytest | ||
pytest-cov | ||
pytest-flake8 | ||
commands = | ||
pytest -v --flake8 --cov=taskcluster_urls {posargs:test} |