Skip to content

Commit

Permalink
Merge pull request #199 from markkuleinio/options-fix
Browse files Browse the repository at this point in the history
Fix Endpoint.choices() by assigning http_session (to fix #198)
  • Loading branch information
Zach Moody authored Nov 18, 2019
2 parents 30b88f8 + 5fc3bf1 commit 4cf4e9a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions pynetbox/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,5 +189,6 @@ def version(self):
version = Request(
base=self.base_url,
ssl_verify=self.ssl_verify,
http_session=self.http_session,
).get_version()
return version
1 change: 1 addition & 0 deletions pynetbox/core/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ def choices(self):
token=self.api.token,
private_key=self.api.private_key,
ssl_verify=self.api.ssl_verify,
http_session=self.api.http_session,
).options()
try:
post_data = req['actions']['POST']
Expand Down
4 changes: 2 additions & 2 deletions pynetbox/core/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,14 @@ class Request(object):

def __init__(
self,
base=None,
base,
http_session,
filters=None,
key=None,
token=None,
private_key=None,
session_key=None,
ssl_verify=True,
http_session=None,
):
"""
Instantiates a new Request object
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/test_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,27 @@ def test_filter_reserved_kwargs(self):
test_obj = Endpoint(api, app, "test")
with self.assertRaises(ValueError) as _:
test_obj.filter(id=1)

def test_choices(self):
with patch(
"pynetbox.core.query.Request.options", return_value=Mock()
) as mock:
api = Mock(base_url="http://localhost:8000/api")
app = Mock(name="test")
mock.return_value = {
"actions": {
"POST": {
"letter": {
"choices": [
{"display_name": "A", "value": 1},
{"display_name": "B", "value": 2},
{"display_name": "C", "value": 3},
]
}
}
}
}
test_obj = Endpoint(api, app, "test")
choices = test_obj.choices()
self.assertEqual(choices["letter"][1]["display_name"], "B")
self.assertEqual(choices["letter"][1]["value"], 2)

0 comments on commit 4cf4e9a

Please sign in to comment.