Skip to content

Commit 6e3d879

Browse files
committed
Fix return object lookup and improve tests
1 parent 1cb5297 commit 6e3d879

File tree

6 files changed

+26
-5
lines changed

6 files changed

+26
-5
lines changed

pynetbox/core/endpoint.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ class Endpoint:
4242
"""
4343

4444
def __init__(self, api, app, name, model=None):
45-
self.return_obj = self._lookup_ret_obj(name, model)
4645
self.name = name.replace("_", "-")
46+
self.return_obj = self._lookup_ret_obj(model)
4747
self.api = api
4848
self.base_url = api.base_url
4949
self.token = api.token
@@ -54,7 +54,7 @@ def __init__(self, api, app, name, model=None):
5454
)
5555
self._choices = None
5656

57-
def _lookup_ret_obj(self, name, model):
57+
def _lookup_ret_obj(self, model):
5858
"""Loads unique Response objects.
5959
6060
This method loads a unique response object for an endpoint if
@@ -67,7 +67,7 @@ def _lookup_ret_obj(self, name, model):
6767
:Returns: Record (obj)
6868
"""
6969
if model:
70-
name = name.title().replace("_", "")
70+
name = self.name.title().replace("-", "")
7171
ret = getattr(model, name, Record)
7272
else:
7373
ret = Record
@@ -636,8 +636,8 @@ def count(self, *args, **kwargs):
636636

637637
if any(i in RESERVED_KWARGS for i in kwargs):
638638
raise ValueError(
639-
"A reserved {} kwarg was passed. Please remove it "
640-
"try again.".format(RESERVED_KWARGS)
639+
"A reserved kwarg was passed ({}). Please remove it "
640+
"and try again.".format(RESERVED_KWARGS)
641641
)
642642

643643
ret = Request(

tests/integration/test_dcim.py

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from packaging import version
33

44
import pynetbox
5+
import pynetbox.models.dcim
56

67

78
@pytest.fixture(scope="module")
@@ -181,6 +182,7 @@ def interface(self, api, device):
181182
ret = api.dcim.interfaces.create(
182183
name="test-interface", type="1000base-t", device=device.id
183184
)
185+
assert isinstance(ret, pynetbox.models.dcim.Interfaces)
184186
yield ret
185187
ret.delete()
186188

@@ -213,12 +215,14 @@ def power_outlet(self, api, device_type, role, site):
213215
site=site.id,
214216
)
215217
outlet = api.dcim.power_outlets.create(name="outlet", device=pdu.id)
218+
assert isinstance(outlet, pynetbox.models.dcim.PowerOutlets)
216219
yield outlet
217220
pdu.delete()
218221

219222
@pytest.fixture(scope="class")
220223
def power_port(self, api, device):
221224
ret = api.dcim.power_ports.create(name="PSU1", device=device.id)
225+
assert isinstance(ret, pynetbox.models.dcim.PowerPorts)
222226
yield ret
223227

224228
@pytest.fixture(scope="class")
@@ -231,6 +235,7 @@ def power_cable(self, api, power_outlet, power_port):
231235
{"object_type": "dcim.poweroutlet", "object_id": power_outlet.id},
232236
],
233237
)
238+
assert isinstance(cable, pynetbox.models.dcim.Cables)
234239
yield cable
235240
cable.delete()
236241

@@ -263,12 +268,14 @@ def console_server_port(self, api, device_type, role, site):
263268
site=site.id,
264269
)
265270
ret = api.dcim.console_server_ports.create(name="Port 1", device=device.id)
271+
assert isinstance(ret, pynetbox.models.dcim.ConsoleServerPorts)
266272
yield ret
267273
device.delete()
268274

269275
@pytest.fixture(scope="class")
270276
def console_port(self, api, device):
271277
ret = api.dcim.console_ports.create(name="Console", device=device.id)
278+
assert isinstance(ret, pynetbox.models.dcim.ConsolePorts)
272279
yield ret
273280

274281
@pytest.fixture(scope="class")
@@ -284,6 +291,7 @@ def console_cable(self, api, console_port, console_server_port):
284291
},
285292
],
286293
)
294+
assert isinstance(ret, pynetbox.models.dcim.Cables)
287295
yield ret
288296
ret.delete()
289297

@@ -318,6 +326,7 @@ def interface_b(self, api, device_type, role, site):
318326
ret = api.dcim.interfaces.create(
319327
name="Ethernet1", type="1000base-t", device=device.id
320328
)
329+
assert isinstance(ret, pynetbox.models.dcim.Interfaces)
321330
yield ret
322331
device.delete()
323332

@@ -338,6 +347,7 @@ def interface_cable(self, api, interface_a, interface_b):
338347
{"object_type": "dcim.interface", "object_id": interface_b.id},
339348
],
340349
)
350+
assert isinstance(ret, pynetbox.models.dcim.Cables)
341351
yield ret
342352
ret.delete()
343353

tests/test_circuits.py

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from unittest.mock import patch
33

44
import pynetbox
5+
import pynetbox.models.circuits
56

67
from .util import Response
78

@@ -76,6 +77,7 @@ def test_get(self):
7677

7778
class CircuitsTestCase(Generic.Tests):
7879
name = "circuits"
80+
ret = pynetbox.models.circuits.Circuits
7981

8082
@patch(
8183
"requests.sessions.Session.get",
@@ -96,6 +98,7 @@ class CircuitTypeTestCase(Generic.Tests):
9698

9799
class CircuitTerminationsTestCase(Generic.Tests):
98100
name = "circuit_terminations"
101+
ret = pynetbox.models.circuits.CircuitTerminations
99102

100103
@patch(
101104
"requests.sessions.Session.get",

tests/test_users.py

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from unittest.mock import patch
33

44
import pynetbox
5+
import pynetbox.models.users
56

67
from .util import Response
78

@@ -76,6 +77,7 @@ def test_get(self):
7677

7778
class UsersTestCase(Generic.Tests):
7879
name = "users"
80+
ret = pynetbox.models.users.Users
7981

8082
@patch(
8183
"requests.sessions.Session.get",
@@ -93,6 +95,7 @@ class GroupsTestCase(Generic.Tests):
9395

9496
class PermissionsTestCase(Generic.Tests):
9597
name = "permissions"
98+
ret = pynetbox.models.users.Permissions
9699

97100
@patch(
98101
"requests.sessions.Session.get",

tests/test_virtualization.py

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from unittest.mock import patch
33

44
import pynetbox
5+
import pynetbox.models
6+
import pynetbox.models.virtualization
57

68
from .util import Response
79

@@ -88,6 +90,7 @@ class ClustersTestCase(Generic.Tests):
8890

8991
class VirtualMachinesTestCase(Generic.Tests):
9092
name = "virtual_machines"
93+
ret = pynetbox.models.virtualization.VirtualMachines
9194

9295

9396
class InterfacesTestCase(Generic.Tests):

tests/test_wireless.py

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from unittest.mock import patch
33

44
import pynetbox
5+
import pynetbox.models.wireless
56

67
from .util import Response
78

@@ -74,6 +75,7 @@ def test_get(self):
7475

7576
class WirelessLansTestCase(Generic.Tests):
7677
name = "wireless_lans"
78+
ret = pynetbox.models.wireless.WirelessLans
7779

7880
@patch(
7981
"requests.sessions.Session.get",

0 commit comments

Comments
 (0)