Fixtures were created in setUpClass, so a test that changed the shared license instance affected later tests. Use setUpTestData, which rolls back after the class and gives each test its own copy. All 20 tests pass on NetBox 4.7.2. Co-Authored-By: Claude Opus 5.5 <[email protected]>
49 lines
2.5 KiB
Python
49 lines
2.5 KiB
Python
from django.test import TestCase
|
|
|
|
from dcim.models import Device, DeviceRole, DeviceType, Manufacturer, Site
|
|
from netbox_slm.models import SoftwareProduct, SoftwareProductVersion, SoftwareProductInstallation, SoftwareLicense
|
|
from tenancy.models import Tenant, TenantGroup
|
|
from virtualization.models import Cluster, ClusterType, VirtualMachine
|
|
|
|
|
|
class SlmBaseTestCase(TestCase):
|
|
p_name: str = "test product"
|
|
v_name: str = "test version"
|
|
l_name: str = "test license"
|
|
test_url: str = "https://github.com/ICTU/netbox_slm"
|
|
vm: VirtualMachine
|
|
software_product: SoftwareProduct
|
|
software_product_version: SoftwareProductVersion
|
|
software_product_installation: SoftwareProductInstallation
|
|
|
|
@classmethod
|
|
def setUpTestData(cls):
|
|
# setUpTestData rolls back after the class and gives every test its own copy of these objects.
|
|
manufacturer = Manufacturer.objects.create(name="test manufacturer")
|
|
device_type = DeviceType.objects.create(model="test device type", manufacturer=manufacturer)
|
|
device_role = DeviceRole.objects.create(name="test device role")
|
|
site = Site.objects.create(name="test site")
|
|
cls.device = Device.objects.create(name="test device", device_type=device_type, role=device_role, site=site)
|
|
cls.vm = VirtualMachine.objects.create(name="test VM")
|
|
cluster_type = ClusterType.objects.create(name="test cluster type")
|
|
cls.cluster = Cluster.objects.create(name="test cluster", type=cluster_type)
|
|
cls.tenant_group = TenantGroup.objects.create(name="test tenant group", slug="test-tenant-group")
|
|
cls.tenant = Tenant.objects.create(name="test tenant", slug="test-tenant", group=cls.tenant_group)
|
|
|
|
cls.software_product = SoftwareProduct.objects.create(name=cls.p_name)
|
|
cls.software_product_version = SoftwareProductVersion.objects.create(
|
|
name=cls.v_name, software_product=cls.software_product
|
|
)
|
|
cls.software_product_installation = SoftwareProductInstallation.objects.create(
|
|
virtualmachine=cls.vm, software_product=cls.software_product, version=cls.software_product_version
|
|
)
|
|
cls.software_license = SoftwareLicense.objects.create(
|
|
name=cls.l_name,
|
|
software_product=cls.software_product,
|
|
version=cls.software_product_version,
|
|
installation=cls.software_product_installation,
|
|
stored_location_url=cls.test_url,
|
|
tenant_group=cls.tenant_group,
|
|
tenant=cls.tenant,
|
|
)
|