Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_api_version(self, *_):
api = pynetbox.api(
host,
)
self.assertEqual(api.version, "1.999")
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)
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)
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))
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)
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(
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(
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;"},
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(
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(