How to use pynetbox - 10 common examples

To help you get started, we’ve selected a few pynetbox examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github digitalocean / pynetbox / tests / test_api.py View on Github external
def test_api_version(self, *_):
        api = pynetbox.api(
            host,
        )
        self.assertEqual(api.version, "1.999")
github digitalocean / pynetbox / tests / test_api.py View on Github external
def common_arguments(self, kwargs, arg, expect, *_):
        '''
        Ensures the api and endpoint instances have ssl_verify set
        as expected
        '''
        api = pynetbox.api(
            host,
            **kwargs
        )
        self.assertIs(getattr(api, arg, "fail"), expect)
        for app, endpoint in endpoints.items():
            ep = getattr(getattr(api, app), endpoint)
            self.assertIs(getattr(ep, arg), expect)
github digitalocean / pynetbox / tests / unit / test_response.py View on Github external
def test_diff_append_records_list(self):
        test_values = {
            "id": 123,
            "tagged_vlans": [
                {
                    "id": 1,
                    "url": "http://localhost:8000/api/ipam/vlans/1/",
                    "vid": 1,
                    "name": "test1",
                    "display_name": "test1",
                }
            ],
        }
        test_obj = Record(test_values, None, None)
        test_obj.tagged_vlans.append(1)
        test = test_obj._diff()
        self.assertFalse(test)
github digitalocean / pynetbox / tests / unit / test_response.py View on Github external
def test_hash_diff(self):
        endpoint1 = Mock()
        endpoint1.name = "test-endpoint"
        endpoint2 = Mock()
        endpoint2.name = "test-endpoint"
        test1 = Record({}, None, endpoint1)
        test1.id = 1
        test2 = Record({}, None, endpoint2)
        test2.id = 2
        self.assertNotEqual(hash(test1), hash(test2))
github digitalocean / pynetbox / tests / unit / test_response.py View on Github external
def test_serialize_tag_set(self):
        test_values = {"id": 123, "tags": ["foo", "bar", "foo"]}
        test = Record(test_values, None, None).serialize()
        self.assertEqual(len(test["tags"]), 2)
github digitalocean / pynetbox / tests / test_dcim.py View on Github external
nb = api.dcim

HEADERS = {
    'accept': 'application/json;',
}

AUTH_HEADERS = {
    'accept': 'application/json;',
    'authorization': 'Token None',
}


class Generic(object):
    class Tests(unittest.TestCase):
        name = ''
        ret = pynetbox.core.response.Record
        app = 'dcim'

        def test_get_all(self):
            with patch(
                'pynetbox.core.query.requests.sessions.Session.get',
                return_value=Response(fixture='{}/{}.json'.format(
                    self.app,
                    self.name
                ))
            ) as mock:
                ret = getattr(nb, self.name).all()
                self.assertTrue(ret)
                self.assertTrue(isinstance(ret, list))
                self.assertTrue(isinstance(ret[0], self.ret))
                mock.assert_called_with(
                    'http://localhost:8000/api/{}/{}/'.format(
github digitalocean / pynetbox / tests / test_tenancy.py View on Github external
api = pynetbox.api(
    "http://localhost:8000",
)

nb = api.tenancy

HEADERS = {
    'accept': 'application/json;'
}


class Generic(object):
    class Tests(unittest.TestCase):
        name = ''
        ret = pynetbox.core.response.Record
        app = 'tenancy'

        def test_get_all(self):
            with patch(
                'pynetbox.core.query.requests.sessions.Session.get',
                return_value=Response(fixture='{}/{}.json'.format(
                    self.app,
                    self.name
                ))
            ) as mock:
                ret = getattr(nb, self.name).all()
                self.assertTrue(ret)
                self.assertTrue(isinstance(ret, list))
                self.assertTrue(isinstance(ret[0], self.ret))
                mock.assert_called_with(
                    'http://localhost:8000/api/{}/{}/'.format(
github digitalocean / pynetbox / tests / unit / test_query.py View on Github external
def test_get_count_no_filters(self):
        test_obj = Request(
            http_session=Mock(),
            base="http://localhost:8001/api/dcim/devices",
        )
        test_obj.http_session.get.return_value.json.return_value = {
            "count": 42,
            "next": "http://localhost:8001/api/dcim/devices?limit=1&offset=1",
            "previous": False,
            "results": [],
        }
        test_obj.http_session.get.ok = True
        test = test_obj.get_count()
        self.assertEqual(test, 42)
        test_obj.http_session.get.assert_called_with(
            "http://localhost:8001/api/dcim/devices/",
            params={"limit": 1},
            headers={"accept": "application/json;"},
github digitalocean / pynetbox / tests / test_virtualization.py View on Github external
api = pynetbox.api(
    "http://localhost:8000",
)

nb = api.virtualization

HEADERS = {
    'accept': 'application/json;'
}


class Generic(object):
    class Tests(unittest.TestCase):
        name = ''
        ret = pynetbox.core.response.Record
        app = 'virtualization'

        def test_get_all(self):
            with patch(
                'pynetbox.core.query.requests.sessions.Session.get',
                return_value=Response(fixture='{}/{}.json'.format(
                    self.app,
                    self.name
                ))
            ) as mock:
                ret = getattr(nb, self.name).all()
                self.assertTrue(ret)
                self.assertTrue(isinstance(ret, list))
                self.assertTrue(isinstance(ret[0], self.ret))
                mock.assert_called_with(
                    'http://localhost:8000/api/{}/{}/'.format(
github digitalocean / pynetbox / tests / test_circuits.py View on Github external
api = pynetbox.api(
    "http://localhost:8000",
)

nb = api.circuits

HEADERS = {
    'accept': 'application/json;'
}


class Generic(object):
    class Tests(unittest.TestCase):
        name = ''
        ret = pynetbox.core.response.Record
        app = 'circuits'

        def test_get_all(self):
            with patch(
                'pynetbox.core.query.requests.sessions.Session.get',
                return_value=Response(fixture='{}/{}.json'.format(
                    self.app,
                    self.name
                ))
            ) as mock:
                ret = getattr(nb, self.name).all()
                self.assertTrue(ret)
                self.assertTrue(isinstance(ret, list))
                self.assertTrue(isinstance(ret[0], self.ret))
                mock.assert_called_with(
                    'http://localhost:8000/api/{}/{}/'.format(