File tree Expand file tree Collapse file tree 2 files changed +58
-0
lines changed
Expand file tree Collapse file tree 2 files changed +58
-0
lines changed Original file line number Diff line number Diff line change @@ -78,6 +78,29 @@ def choices(self):
7878
7979 return self ._choices
8080
81+ def custom_choices (self ):
82+ """ Returns _custom_field_choices response from app
83+
84+ :Returns: Raw response from NetBox's _custom_field_choices endpoint.
85+ :Raises: :py:class:`.RequestError` if called for an invalid endpoint.
86+ :Example:
87+
88+ >>> nb.extras.custom_choices()
89+ {'Testfield1': {'Testvalue2': 2, 'Testvalue1': 1},
90+ 'Testfield2': {'Othervalue2': 4, 'Othervalue1': 3}}
91+ """
92+ custom_field_choices = Request (
93+ base = "{}/{}/_custom_field_choices/" .format (
94+ self .api .base_url ,
95+ self .name ,
96+ ),
97+ token = self .api .token ,
98+ private_key = self .api .private_key ,
99+ ssl_verify = self .api .ssl_verify ,
100+ http_session = self .api .http_session ,
101+ ).get ()
102+ return custom_field_choices
103+
81104
82105class Api (object ):
83106 """ The API object is the point of entry to pynetbox.
Original file line number Diff line number Diff line change 1+ import unittest
2+
3+ import six
4+
5+ import pynetbox
6+
7+ if six .PY3 :
8+ from unittest .mock import patch
9+ else :
10+ from mock import patch
11+
12+ host = "http://localhost:8000"
13+
14+ def_kwargs = {
15+ 'token' : 'abc123' ,
16+ }
17+
18+
19+ class AppCustomChoicesTestCase (unittest .TestCase ):
20+
21+ @patch (
22+ 'pynetbox.core.query.Request.get' ,
23+ return_value = {
24+ "Testfield1" : {"TF1_1" : 1 , "TF1_2" : 2 },
25+ "Testfield2" : {"TF2_1" : 3 , "TF2_2" : 4 },
26+ }
27+ )
28+ def test_custom_choices (self , * _ ):
29+ api = pynetbox .api (
30+ host ,
31+ ** def_kwargs
32+ )
33+ choices = api .extras .custom_choices ()
34+ self .assertEqual (len (choices ), 2 )
35+ self .assertEqual (sorted (choices .keys ()), ["Testfield1" , "Testfield2" ])
You can’t perform that action at this time.
0 commit comments