From 5ad98d334e0b611b18ae3a702d230bc31687b319 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markku=20Leini=C3=B6?= Date: Sat, 16 Nov 2019 17:56:21 +0200 Subject: [PATCH 1/3] Fix .choices() by assigning http_session --- pynetbox/core/endpoint.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pynetbox/core/endpoint.py b/pynetbox/core/endpoint.py index 71017482..aa8d48b2 100644 --- a/pynetbox/core/endpoint.py +++ b/pynetbox/core/endpoint.py @@ -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'] From 48131dbad9baa67d3f0bb812ebdd83766c3c3953 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markku=20Leini=C3=B6?= Date: Sat, 16 Nov 2019 18:30:56 +0200 Subject: [PATCH 2/3] Add unit test for Endpoint.choices() --- tests/unit/test_endpoint.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/unit/test_endpoint.py b/tests/unit/test_endpoint.py index d83c3862..4ce10de9 100644 --- a/tests/unit/test_endpoint.py +++ b/tests/unit/test_endpoint.py @@ -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) From 5fc3bf193983f023aff66add1bf052c5fde44437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markku=20Leini=C3=B6?= Date: Sat, 16 Nov 2019 19:11:54 +0200 Subject: [PATCH 3/3] Change Request to require base and http_session arguments --- pynetbox/api.py | 1 + pynetbox/core/query.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pynetbox/api.py b/pynetbox/api.py index 6de773e9..a9fce2c4 100644 --- a/pynetbox/api.py +++ b/pynetbox/api.py @@ -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 diff --git a/pynetbox/core/query.py b/pynetbox/core/query.py index 934ddd82..3b96b958 100644 --- a/pynetbox/core/query.py +++ b/pynetbox/core/query.py @@ -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