Mocking dcim.devices.get and virtualization.devices.get #611
Replies: 1 comment 1 reply
-
from project.netbox import Netbox
nb = Netbox("http://netbox.url", "1234567890abcdef")
def test_get_device_device(mocker):
mock = mocker.Mock()
mock.dcim.devices.get.return_value = {"id": 1, "name": "device1"}
mock.virtualization.devices.get.return_value = {"id": 2, "name": "device1"}
mocker.patch.object(nb, "netbox", mock)
response = nb.get_device(name="device1")
assert response == {"id": 1, "name": "device1"}
def test_get_device_vm(mocker):
mock = mocker.Mock()
mock.dcim.devices.get.return_value = None
mock.virtualization.devices.get.return_value = {"id": 2, "name": "device1"}
mocker.patch.object(nb, "netbox", mock)
response = nb.get_device(name="device1")
assert response == {"id": 2, "name": "device1"} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
rgruyters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to create a mocking for a class function which uses both dcim.devices.get and virtualization.devices.get, but I can't get it to work.
here is an example of my class:
Basically, i want to test when
self.netbox.dcim.devices.get
is None and test ifself.netbox.virtualization.devices.get
is None.I have tried the following, but that just simulates the respond data from the request.
Anybody got an idea how to do this?
Beta Was this translation helpful? Give feedback.
All reactions