Skip to content

Commit

Permalink
tests support for racks
Browse files Browse the repository at this point in the history
  • Loading branch information
matejv committed Dec 13, 2024
1 parent c1ddc94 commit dde1cea
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 2 deletions.
52 changes: 51 additions & 1 deletion netbox_inventory/tests/asset/test_views_create.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.test import override_settings

from dcim.models import Manufacturer, DeviceType, DeviceRole, Device, InventoryItem, Module, ModuleBay, ModuleType, Site
from dcim.models import Manufacturer, DeviceType, DeviceRole, Device, InventoryItem, Module, ModuleBay, ModuleType, Rack, RackType, Site
from utilities.testing import ViewTestCases

from netbox_inventory.tests.custom import ModelViewTestCase
Expand Down Expand Up @@ -43,6 +43,11 @@ def setUp(self):
model='inventoryitem_type1',
slug='inventoryitem_type1'
)
self.rack_type1 = RackType.objects.create(
manufacturer=self.manufacturer1,
model='rack_type1',
slug='rack_type1'
)
self.device1 = Device.objects.create(
site=self.site1,
status='active',
Expand Down Expand Up @@ -72,6 +77,12 @@ def setUp(self):
status='stored',
inventoryitem_type=self.inventoryitem_type1,
)
self.asset_rack_sn = Asset.objects.create(
asset_tag='asset_rack',
serial='asset_rack',
status='stored',
device_type=self.rack_type1,
)
self.asset_device_no = Asset.objects.create(
status='stored',
device_type=self.device_type1,
Expand All @@ -84,6 +95,10 @@ def setUp(self):
status='stored',
inventoryitem_type=self.inventoryitem_type1,
)
self.asset_rack_no = Asset.objects.create(
status='stored',
rack_type=self.rack_type1,
)

def _get_url(self, _):
hardware_kind = self.tested_asset.kind
Expand Down Expand Up @@ -170,6 +185,23 @@ def setUp(self):
self.tested_asset = self.asset_inventoryitem_sn


class SerialRackAssetCreateHwTestCase(AssetCreateHwBase, ModelViewTestCase, ViewTestCases.CreateObjectViewTestCase):
"""
Test creating new Rack from Asset with serial
"""
model = Rack

def setUp(self):
super().setUp()
self.form_data = {
'site': self.site1.pk,
'rack_type': self.rack_type1.pk,
'status': 'active',
'name': 'tested_rack',
}
self.tested_asset = self.asset_rack_sn


class NoSerialDeviceAssetCreateHwTestCase(AssetCreateHwBase, ModelViewTestCase, ViewTestCases.CreateObjectViewTestCase):
"""
Test creating new Device from Asset with blank serial
Expand Down Expand Up @@ -218,3 +250,21 @@ def setUp(self):
'name': 'inventoryitem1',
}
self.tested_asset = self.asset_inventoryitem_no


class NoSerialRackAssetCreateHwTestCase(AssetCreateHwBase, ModelViewTestCase, ViewTestCases.CreateObjectViewTestCase):
"""
Test creating new Rack from Asset with blank serial
"""
model = Rack

def setUp(self):
super().setUp()
self.form_data = {
'site': self.site1.pk,
'rack_type': self.rack_type1.pk,
'status': 'active',
'name': 'tested_rack',
}
self.tested_asset = self.asset_rack_no

61 changes: 60 additions & 1 deletion netbox_inventory/tests/asset/test_views_reassign.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.test import override_settings

from core.models import ObjectType
from dcim.models import Manufacturer, DeviceType, DeviceRole, Device, InventoryItem, Module, ModuleBay, ModuleType, Site
from dcim.models import Manufacturer, DeviceType, DeviceRole, Device, InventoryItem, Module, ModuleBay, ModuleType, Rack, RackType, Site
from core.choices import ObjectChangeActionChoices
from core.models import ObjectChange
from users.models import ObjectPermission
Expand Down Expand Up @@ -61,6 +61,11 @@ def setUp(self):
part_number='partnumber2',
slug='inventoryitem_type2'
)
self.rack_type1 = RackType.objects.create(
manufacturer=self.manufacturer1,
model='rack_type1',
slug='rack_type1'
)
self.device1 = Device.objects.create(
site=self.site1,
status='active',
Expand All @@ -81,6 +86,12 @@ def setUp(self):
device=self.device1,
name='inventoryitem1',
)
self.rack1 = Rack.objects.create(
site=self.site1,
status='active',
rack_type=self.rack_type1,
name='rack1',
)
self.asset_device_old = Asset.objects.create(
asset_tag='asset_device',
serial='asset_device',
Expand All @@ -102,6 +113,13 @@ def setUp(self):
inventoryitem_type=self.inventoryitem_type1,
inventoryitem=self.inventoryitem1,
)
self.asset_rack_old = Asset.objects.create(
asset_tag='asset_rack',
serial='asset_rack',
status='used',
rack_type=self.rack_type1,
rack=self.rack1,
)
self.asset_device_new = Asset.objects.create(
asset_tag='asset_device2',
serial='asset_device2',
Expand All @@ -120,6 +138,12 @@ def setUp(self):
status='stored',
inventoryitem_type=self.inventoryitem_type2,
)
self.asset_rack_new = Asset.objects.create(
asset_tag='asset_rack2',
serial='asset_rack2',
status='stored',
rack_type=self.rack_type1,
)

def _get_url(self, _, instance):
hardware_kind = self.model._meta.model_name
Expand Down Expand Up @@ -252,6 +276,24 @@ def test_edit_object_with_permission(self):
self.assertEqual(self.tested_hardware.part_id, self.asset_new.inventoryitem_type.part_number)


class RackReassignAssetTestCase(AssetReassignBase, ModelViewTestCase):
"""
Test assigning different Asset to Module
"""
model = Rack

def setUp(self):
super().setUp()
self.form_data = {
'rack_type': self.rack1.rack_type.pk,
'assigned_asset': self.asset_rack_new.pk,
'asset_status': 'stored',
}
self.tested_hardware = self.rack1
self.asset_new = self.asset_rack_new
self.asset_old = self.asset_rack_old


class DeviceUnassignAssetTestCase(AssetReassignBase, ModelViewTestCase):
"""
Test assigning no Asset to Device
Expand Down Expand Up @@ -309,3 +351,20 @@ def test_edit_object_with_permission(self):
self.tested_hardware.refresh_from_db()
self.assertEqual(self.tested_hardware.manufacturer, self.asset_old.inventoryitem_type.manufacturer)
self.assertEqual(self.tested_hardware.part_id, self.asset_old.inventoryitem_type.part_number)


class RackUnassignAssetTestCase(AssetReassignBase, ModelViewTestCase):
"""
Test assigning no Asset to Rack
"""
model = Rack

def setUp(self):
super().setUp()
self.form_data = {
'rack_type': self.rack1.rack_type.pk,
'asset_status': 'stored',
}
self.tested_hardware = self.rack1
self.asset_new = None
self.asset_old = self.asset_rack_old

0 comments on commit dde1cea

Please sign in to comment.