From 8df5a8a8b6db79b623b4458681d19f20202cc193 Mon Sep 17 00:00:00 2001 From: zmoody Date: Wed, 18 Jul 2018 13:55:22 -0500 Subject: [PATCH 1/2] Create test for Circuit string representation. --- tests/test_circuits.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/test_circuits.py b/tests/test_circuits.py index 6d036924..b95cc714 100644 --- a/tests/test_circuits.py +++ b/tests/test_circuits.py @@ -92,6 +92,14 @@ def test_get(self): class CircuitsTestCase(unittest.TestCase, GenericTest): name = 'circuits' + @patch( + 'pynetbox.lib.query.requests.get', + return_value=Response(fixture='circuits/circuit.json') + ) + def test_repr(self, _): + test = nb.circuits.get(1) + self.assertEqual(str(test), '123456') + class ProviderTestCase(unittest.TestCase, GenericTest): name = 'providers' From ec9d5825be3ddd1c279b487dffe0f53bd9956af7 Mon Sep 17 00:00:00 2001 From: zmoody Date: Wed, 18 Jul 2018 13:56:43 -0500 Subject: [PATCH 2/2] Fixes Circuit string and repr Adds custom __str__ method for Record from Circuits endpoint so that .cid is returned. --- pynetbox/api.py | 4 ++-- pynetbox/circuits.py | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 pynetbox/circuits.py diff --git a/pynetbox/api.py b/pynetbox/api.py index fceff1e5..44d554ee 100644 --- a/pynetbox/api.py +++ b/pynetbox/api.py @@ -14,7 +14,7 @@ limitations under the License. ''' from pynetbox.lib import Endpoint, Request -from pynetbox import dcim, ipam, virtualization +from pynetbox import dcim, ipam, virtualization, circuits class App(object): @@ -119,7 +119,7 @@ def __init__(self, url, token=None, private_key=None, self.dcim = App(dcim, api_kwargs=self.api_kwargs) self.ipam = App(ipam, api_kwargs=self.api_kwargs) - self.circuits = App('circuits', api_kwargs=self.api_kwargs) + self.circuits = App(circuits, api_kwargs=self.api_kwargs) self.secrets = App('secrets', api_kwargs=self.api_kwargs) self.tenancy = App('tenancy', api_kwargs=self.api_kwargs) self.extras = App('extras', api_kwargs=self.api_kwargs) diff --git a/pynetbox/circuits.py b/pynetbox/circuits.py new file mode 100644 index 00000000..7785cadd --- /dev/null +++ b/pynetbox/circuits.py @@ -0,0 +1,22 @@ +''' +(c) 2017 DigitalOcean + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +''' +from pynetbox.lib.response import Record + + +class Circuits(Record): + + def __str__(self): + return self.cid