diff --git a/pynautobot/core/endpoint.py b/pynautobot/core/endpoint.py index 8f3869c..d3d3229 100644 --- a/pynautobot/core/endpoint.py +++ b/pynautobot/core/endpoint.py @@ -393,11 +393,11 @@ def choices(self, api_version=None): post_data = req["schema"]["properties"] except (KeyError, TypeError): raise ValueError(f"Unexpected format in the OPTIONS response at {self.url}") - self._choices = {} - for prop in post_data: - if "choices" in post_data[prop]: - self._choices[prop] = post_data[prop]["choices"] - + self._choices = { + prop: [{"value": x, "display": y} for x, y in zip(post_data[prop]["enum"], post_data[prop]["enumNames"])] + for prop in post_data + if "enum" in post_data[prop] + } return self._choices def count(self, *args, api_version=None, **kwargs): diff --git a/tests/unit/test_api_version.py b/tests/unit/test_api_version.py index ac3433f..20f08eb 100644 --- a/tests/unit/test_api_version.py +++ b/tests/unit/test_api_version.py @@ -42,7 +42,7 @@ def test_api_versioning_at_api_level(self, ResponseLoader): ) # Test choices request includes version=1.3 in its headers - self.api.http_session.options.return_value.json.return_value = {"actions": {"POST": []}} + self.api.http_session.options.return_value.json.return_value = {"schema": {"properties": {}}} self.test_obj.choices() self.api.http_session.options.assert_called_with( "http://localhost:8000/api/test/test/", @@ -80,7 +80,7 @@ def test_api_versioning_at_per_request_level(self, ResponseLoader): ) # Test choices request overrides Api level versioning - self.api.http_session.options.return_value.json.return_value = {"actions": {"POST": []}} + self.api.http_session.options.return_value.json.return_value = {"schema": {"properties": {}}} self.test_obj.choices(api_version=1.2) self.api.http_session.options.assert_called_with( "http://localhost:8000/api/test/test/", diff --git a/tests/unit/test_endpoint.py b/tests/unit/test_endpoint.py index e43997d..4a0c631 100644 --- a/tests/unit/test_endpoint.py +++ b/tests/unit/test_endpoint.py @@ -37,21 +37,18 @@ def test_choices(self): api = Mock(base_url="http://localhost:8000/api") app = Mock(name="test") mock.return_value = { - "actions": { - "POST": { + "schema": { + "properties": { "letter": { - "choices": [ - {"display_name": "A", "value": 1}, - {"display_name": "B", "value": 2}, - {"display_name": "C", "value": 3}, - ] + "enum": [1, 2, 3], + "enumNames": ["A", "B", "C"], } } } } test_obj = Endpoint(api, app, "test") choices = test_obj.choices() - self.assertEqual(choices["letter"][1]["display_name"], "B") + self.assertEqual(choices["letter"][1]["display"], "B") self.assertEqual(choices["letter"][1]["value"], 2)