Skip to content

Commit

Permalink
Merge pull request #66 from digitalocean/url-sanitization
Browse files Browse the repository at this point in the history
Fixes #61 - URL with trailing frontslash
  • Loading branch information
Zach Moody committed Jul 3, 2018
2 parents 40dbd68 + fbe152c commit 14f629c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pynetbox/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def __init__(self, url, token=None, private_key=None,
raise ValueError(
'"private_key" and "private_key_file" cannot be used together.'
)
base_url = "{}/api".format(url)
base_url = "{}/api".format(url if url[-1] != '/' else url[:-1])

self.api_kwargs = {
"token": token,
Expand Down
12 changes: 12 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ def test_get(self, mock):
)
self.assertTrue(api)

@patch(
'pynetbox.lib.query.requests.post',
return_value=Response(fixture='api/get_session_key.json')
)
def test_sanitize_url(self, mock):
api = pynetbox.api(
'http://localhost:8000/',
**def_kwargs
)
self.assertTrue(api)
self.assertEqual(api.api_kwargs['base_url'], 'http://localhost:8000/api')


class ApiArgumentsTestCase(unittest.TestCase):

Expand Down

0 comments on commit 14f629c

Please sign in to comment.