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 12, 2024
1 parent c1ddc94 commit 965b379
Showing 1 changed file with 60 additions and 1 deletion.
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 = Module

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 965b379

Please sign in to comment.