def test_ensure_device_type_strict_missing(self): """Verify ensure_device_type function when DeviceType object is not present.""" PLUGIN_SETTINGS["object_match_strategy"] = "strict" onboarding_kwargs = { "netdev_hostname": "device1", "netdev_nb_role_slug": PLUGIN_SETTINGS["default_device_role"], "netdev_vendor": "Cisco", "netdev_model": "CSR1000v", "netdev_nb_site_slug": self.site1.slug, } nbk = NautobotKeeper(**onboarding_kwargs) nbk.nb_manufacturer = Manufacturer.objects.create(name="Cisco", slug="cisco") with self.assertRaises(OnboardException) as exc_info: nbk.ensure_device_type(create_device_type=False) self.assertEqual(exc_info.exception.message, "ERROR device type not found: CSR1000v") self.assertEqual(exc_info.exception.reason, "fail-config") nbk.ensure_device_type(create_device_type=True) self.assertIsInstance(nbk.nb_device_type, DeviceType) self.assertEqual(nbk.nb_device_type.slug, slugify(onboarding_kwargs["netdev_model"]))
def test_ensure_device_type_loose_present(self): """Verify ensure_device_type function when DeviceType object is already present.""" PLUGIN_SETTINGS["object_match_strategy"] = "loose" manufacturer = Manufacturer.objects.create(name="Juniper", slug="juniper") device_type = DeviceType.objects.create(slug="srx3600", model="SRX3600", manufacturer=manufacturer) onboarding_kwargs = { "netdev_hostname": "device2", "netdev_nb_role_slug": PLUGIN_SETTINGS["default_device_role"], "netdev_vendor": "Juniper", "netdev_nb_device_type_slug": device_type.slug, "netdev_nb_site_slug": self.site1.slug, } nbk = NautobotKeeper(**onboarding_kwargs) nbk.nb_manufacturer = manufacturer nbk.ensure_device_type(create_device_type=False) self.assertEqual(nbk.nb_device_type, device_type)