Skip to content

Commit 14f629c

Browse files
author
Zach Moody
authored
Merge pull request #66 from digitalocean/url-sanitization
Fixes #61 - URL with trailing frontslash
2 parents 40dbd68 + fbe152c commit 14f629c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

pynetbox/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def __init__(self, url, token=None, private_key=None,
8989
raise ValueError(
9090
'"private_key" and "private_key_file" cannot be used together.'
9191
)
92-
base_url = "{}/api".format(url)
92+
base_url = "{}/api".format(url if url[-1] != '/' else url[:-1])
9393

9494
self.api_kwargs = {
9595
"token": token,

tests/test_api.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ def test_get(self, mock):
4141
)
4242
self.assertTrue(api)
4343

44+
@patch(
45+
'pynetbox.lib.query.requests.post',
46+
return_value=Response(fixture='api/get_session_key.json')
47+
)
48+
def test_sanitize_url(self, mock):
49+
api = pynetbox.api(
50+
'http://localhost:8000/',
51+
**def_kwargs
52+
)
53+
self.assertTrue(api)
54+
self.assertEqual(api.api_kwargs['base_url'], 'http://localhost:8000/api')
55+
4456

4557
class ApiArgumentsTestCase(unittest.TestCase):
4658

0 commit comments

Comments
 (0)