1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
import unittest
from unittest.mock import patch
import pynetbox
host = "http://localhost:8000"
def_kwargs = {
"token": "abc123",
}
class AppConfigTestCase(unittest.TestCase):
@patch(
"pynetbox.core.query.Request.get",
return_value={
"tables": {
"DeviceTable": {
"columns": [
"name",
"status",
"tenant",
"tags",
],
},
},
},
)
def test_config(self, *_):
api = pynetbox.api(host, **def_kwargs)
config = api.users.config()
self.assertEqual(sorted(config.keys()), ["tables"])
self.assertEqual(
sorted(config["tables"]["DeviceTable"]["columns"]),
["name", "status", "tags", "tenant"],
)
class PluginAppTestCase(unittest.TestCase):
@patch(
"pynetbox.core.query.Request.get",
return_value=[
{
"name": "test_plugin",
"package": "netbox_test_plugin",
}
],
)
def test_installed_plugins(self, *_):
api = pynetbox.api(host, **def_kwargs)
plugins = api.plugins.installed_plugins()
self.assertEqual(len(plugins), 1)
self.assertEqual(plugins[0]["name"], "test_plugin")
def test_plugin_app_name(self, *_):
api = pynetbox.api(host, **def_kwargs)
test_plugin = api.plugins.test_plugin
self.assertEqual(test_plugin.name, "plugins/test-plugin")
|