Skip to content

Commit

Permalink
add trailing slashes to URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
djmitche committed Apr 17, 2015
1 parent 1b67c8d commit 10c11b0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
30 changes: 19 additions & 11 deletions test_tooltool.py
Expand Up @@ -525,17 +525,25 @@ def test_command_fetch_no_url():

def test_command_fetch():
with mock.patch('tooltool.fetch_files') as fetch_files:
eq_(call_main('tooltool', 'fetch', 'a', 'b', '--url', 'http://foo'), 0)
fetch_files.assert_called_with('manifest.tt', ['http://foo'], ['a', 'b'],
eq_(call_main('tooltool', 'fetch', 'a', 'b', '--url', 'http://foo/bar/'), 0)
fetch_files.assert_called_with('manifest.tt', ['http://foo/bar/'], ['a', 'b'],
cache_folder=None, auth_file=None,
region=None)


def test_command_fetch_no_trailing_slash():
with mock.patch('tooltool.fetch_files') as fetch_files:
eq_(call_main('tooltool', 'fetch', 'a', 'b', '--url', 'http://foo/bar'), 0)
fetch_files.assert_called_with('manifest.tt', ['http://foo/bar/'], ['a', 'b'],
cache_folder=None, auth_file=None,
region=None)


def test_command_fetch_region():
with mock.patch('tooltool.fetch_files') as fetch_files:
eq_(call_main('tooltool', 'fetch', 'a', 'b', '--url', 'http://foo',
eq_(call_main('tooltool', 'fetch', 'a', 'b', '--url', 'http://foo/bar/',
'--region', 'us-east-1'), 0)
fetch_files.assert_called_with('manifest.tt', ['http://foo'], ['a', 'b'],
fetch_files.assert_called_with('manifest.tt', ['http://foo/bar/'], ['a', 'b'],
cache_folder=None, auth_file=None,
region='us-east-1')

Expand All @@ -548,9 +556,9 @@ def test_command_fetch_auth_file():
try:
with mock.patch('tooltool.fetch_files') as fetch_files:
os.path.expanduser.side_effect = lambda path: path.replace("~", "HOME")
eq_(call_main('tooltool', 'fetch', 'a', 'b', '--url', 'http://foo',
eq_(call_main('tooltool', 'fetch', 'a', 'b', '--url', 'http://foo/bar/',
'--authentication-file', '~/.tooltool-token'), 0)
fetch_files.assert_called_with('manifest.tt', ['http://foo'],
fetch_files.assert_called_with('manifest.tt', ['http://foo/bar/'],
['a', 'b'], cache_folder=None,
auth_file="HOME/.tooltool-token",
region=None)
Expand All @@ -560,21 +568,21 @@ def test_command_fetch_auth_file():

def test_command_upload():
with mock.patch('tooltool.upload') as upload:
eq_(call_main('tooltool', 'upload', '--url', 'http://foo',
eq_(call_main('tooltool', 'upload', '--url', 'http://foo/',
'--message', 'msg'), 0)
upload.assert_called_with('manifest.tt', 'msg', ['http://foo'], None, None)
upload.assert_called_with('manifest.tt', 'msg', ['http://foo/'], None, None)


def test_command_upload_region():
with mock.patch('tooltool.upload') as upload:
eq_(call_main('tooltool', 'upload', '--url', 'http://foo',
eq_(call_main('tooltool', 'upload', '--url', 'http://foo/',
'--message', 'msg', '--region=us-west-3'), 0)
upload.assert_called_with('manifest.tt', 'msg', ['http://foo'], None, 'us-west-3')
upload.assert_called_with('manifest.tt', 'msg', ['http://foo/'], None, 'us-west-3')


def test_command_upload_no_message():
with mock.patch('tooltool.upload') as upload:
eq_(call_main('tooltool', 'upload', '--url', 'http://foo'), 1)
eq_(call_main('tooltool', 'upload', '--url', 'http://foo/'), 1)
assert not upload.called


Expand Down
5 changes: 5 additions & 0 deletions tooltool.py
Expand Up @@ -955,6 +955,11 @@ def main(argv, _skip_logging=False):
if not options_obj.base_url:
options_obj.base_url = ['https://api.pub.build.mozilla.org/tooltool/']

# ensure all URLs have a trailing slash
def add_slash(url):
return url if url.endswith('/') else (url + '/')
options_obj.base_url = [add_slash(u) for u in options_obj.base_url]

# expand ~ in --authentication-file
if options_obj.auth_file:
options_obj.auth_file = os.path.expanduser(options_obj.auth_file)
Expand Down

0 comments on commit 10c11b0

Please sign in to comment.