diff --git a/netbox_inventory/tests/asset/test_views_create.py b/netbox_inventory/tests/asset/test_views_create.py index b73a662..ae360b7 100644 --- a/netbox_inventory/tests/asset/test_views_create.py +++ b/netbox_inventory/tests/asset/test_views_create.py @@ -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 @@ -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', @@ -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, @@ -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 @@ -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 @@ -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 + diff --git a/netbox_inventory/tests/asset/test_views_reassign.py b/netbox_inventory/tests/asset/test_views_reassign.py index 013a3cd..5cbc757 100644 --- a/netbox_inventory/tests/asset/test_views_reassign.py +++ b/netbox_inventory/tests/asset/test_views_reassign.py @@ -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 @@ -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', @@ -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', @@ -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', @@ -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 @@ -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 @@ -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