Skip to content

Instantly share code, notes, and snippets.

@clay584
Created March 12, 2020 15:10
Show Gist options
  • Save clay584/1c132dae363628bc2ea4430284ac0308 to your computer and use it in GitHub Desktop.
Save clay584/1c132dae363628bc2ea4430284ac0308 to your computer and use it in GitHub Desktop.
nornit-netbox-tests.py
def get_secrets(requests_mock, case, plugin, pagination, **kwargs):
if not pagination:
with open(f"{BASE_PATH}/{case}/mocked/secrets.json", "r") as f:
requests_mock.get(
"http://localhost:8080/api/secrets/secrets/?limit=0",
json=json.load(f),
headers={"Content-type": "application/json"},
)
else:
for offset in range(3):
with open(f"{BASE_PATH}/{case}/mocked/devices-{offset}.json", "r") as f:
url = "http://localhost:8080/api/secrets/secrets/?limit=0"
requests_mock.get(
f"{url}&offset={offset}" if offset else url,
json=json.load(f),
headers={"Content-type": "application/json"},
)
return plugin.deserialize(**kwargs)
class TestNetboxInventory2(TestNBInventory):
plugin = NetboxInventory2
nb_version = "2.7.6"
@staticmethod
def transform_function(host):
vendor_map = {"Cisco": "ios"}
if host["device_type"]["manufacturer"]["name"] == "Cisco":
host.platform = vendor_map[host["device_type"]["manufacturer"]["name"]]
def test_secrets(self, requests_mock):
actual = get_secrets(requests_mock, self.nb_version, self.plugin, False)
with open(
f"{BASE_PATH}/{self.nb_version}/{self.plugin.__name__}/expected_secrets.json", "r"
) as f:
expected = json.load(f)
assert expected == actual
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment