Skip to content

Mocking dcim.devices.get and virtualization.devices.get #611

Answered by markkuleinio
rgruyters asked this question in Q&A
Discussion options

You must be logged in to vote
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

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@rgruyters
Comment options

Answer selected by rgruyters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants