@@ -16,76 +16,23 @@ class AccessListAPIViewTestCase(APIViewTestCases.APIViewTestCase):
1616 model = AccessList
1717 view_namespace = "plugins-api:netbox_acls"
1818 brief_fields = ["display" , "id" , "name" , "url" ]
19- user_permissions = (
20- "dcim.view_site" ,
21- "dcim.view_devicetype" ,
22- "dcim.view_device" ,
23- "virtualization.view_cluster" ,
24- "virtualization.view_clustergroup" ,
25- "virtualization.view_clustertype" ,
26- "virtualization.view_virtualmachine" ,
27- )
2819
2920 @classmethod
3021 def setUpTestData (cls ):
3122 """Set up Access List for API view testing."""
32- site = Site .objects .create (
33- name = "Site 1" ,
34- slug = "site-1" ,
35- )
36-
37- # Device
38- manufacturer = Manufacturer .objects .create (
39- name = "Manufacturer 1" ,
40- slug = "manufacturer-1" ,
41- )
42- device_type = DeviceType .objects .create (
43- manufacturer = manufacturer ,
44- model = "Device Type 1" ,
45- )
46- device_role = DeviceRole .objects .create (
47- name = "Device Role 1" ,
48- slug = "device-role-1" ,
49- )
50- device = Device .objects .create (
51- name = "Device 1" ,
52- site = site ,
53- device_type = device_type ,
54- role = device_role ,
55- )
56-
57- # Virtual Machine
58- cluster_type = ClusterType .objects .create (
59- name = "Cluster Type 1" ,
60- slug = "cluster-type-1" ,
61- )
62- cluster = Cluster .objects .create (
63- name = "Cluster 1" ,
64- type = cluster_type ,
65- )
66- virtual_machine = VirtualMachine .objects .create (
67- name = "VM 1" ,
68- cluster = cluster ,
69- )
70-
7123 access_lists = (
7224 AccessList (
7325 name = "testacl1" ,
74- assigned_object_type = ContentType .objects .get_for_model (Device ),
75- assigned_object_id = device .id ,
7626 type = ACLTypeChoices .TYPE_STANDARD ,
7727 default_action = ACLActionChoices .ACTION_DENY ,
7828 ),
7929 AccessList (
8030 name = "testacl2" ,
81- assigned_object = device ,
8231 type = ACLTypeChoices .TYPE_EXTENDED ,
8332 default_action = ACLActionChoices .ACTION_PERMIT ,
8433 ),
8534 AccessList (
8635 name = "testacl3" ,
87- assigned_object_type = ContentType .objects .get_for_model (VirtualMachine ),
88- assigned_object_id = virtual_machine .id ,
8936 type = ACLTypeChoices .TYPE_EXTENDED ,
9037 default_action = ACLActionChoices .ACTION_DENY ,
9138 ),
@@ -95,22 +42,16 @@ def setUpTestData(cls):
9542 cls .create_data = [
9643 {
9744 "name" : "testacl4" ,
98- "assigned_object_type" : "dcim.device" ,
99- "assigned_object_id" : device .id ,
10045 "type" : ACLTypeChoices .TYPE_STANDARD ,
10146 "default_action" : ACLActionChoices .ACTION_DENY ,
10247 },
10348 {
10449 "name" : "testacl5" ,
105- "assigned_object_type" : "dcim.device" ,
106- "assigned_object_id" : device .id ,
10750 "type" : ACLTypeChoices .TYPE_EXTENDED ,
10851 "default_action" : ACLActionChoices .ACTION_DENY ,
10952 },
11053 {
11154 "name" : "testacl6" ,
112- "assigned_object_type" : "virtualization.virtualmachine" ,
113- "assigned_object_id" : virtual_machine .id ,
11455 "type" : ACLTypeChoices .TYPE_STANDARD ,
11556 "default_action" : ACLActionChoices .ACTION_PERMIT ,
11657 },
@@ -120,12 +61,12 @@ def setUpTestData(cls):
12061 }
12162
12263
123- class ACLInterfaceAssignmentAPIViewTestCase (APIViewTestCases .APIViewTestCase ):
64+ class ACLAssignmentAPIViewTestCase (APIViewTestCases .APIViewTestCase ):
12465 """
125- API view test case for ACLInterfaceAssignment .
66+ API view test case for ACLAssignment .
12667 """
12768
128- model = ACLInterfaceAssignment
69+ model = ACLAssignment
12970 view_namespace = "plugins-api:netbox_acls"
13071 brief_fields = ["access_list" , "display" , "id" , "url" ]
13172 user_permissions = (
@@ -211,55 +152,53 @@ def setUpTestData(cls):
211152 )
212153
213154 # AccessList
214- access_list_device = AccessList .objects .create (
155+ acl1 = AccessList .objects .create (
215156 name = "testacl1" ,
216- assigned_object = device ,
217157 type = ACLTypeChoices .TYPE_STANDARD ,
218158 default_action = ACLActionChoices .ACTION_DENY ,
219159 )
220- access_list_vm = AccessList .objects .create (
160+ acl2 = AccessList .objects .create (
221161 name = "testacl2" ,
222- assigned_object = virtual_machine ,
223162 type = ACLTypeChoices .TYPE_EXTENDED ,
224163 default_action = ACLActionChoices .ACTION_PERMIT ,
225164 )
226165
227- acl_interface_assignments = (
228- ACLInterfaceAssignment (
229- access_list = access_list_device ,
166+ acl_assignments = (
167+ ACLAssignment (
168+ access_list = acl1 ,
230169 direction = ACLAssignmentDirectionChoices .DIRECTION_INGRESS ,
231170 assigned_object_type = ContentType .objects .get_for_model (Interface ),
232171 assigned_object_id = device_interface1 .id ,
233172 ),
234- ACLInterfaceAssignment (
235- access_list = access_list_device ,
173+ ACLAssignment (
174+ access_list = acl1 ,
236175 direction = ACLAssignmentDirectionChoices .DIRECTION_EGRESS ,
237176 assigned_object = device_interface2 ,
238177 ),
239- ACLInterfaceAssignment (
240- access_list = access_list_vm ,
178+ ACLAssignment (
179+ access_list = acl2 ,
241180 direction = ACLAssignmentDirectionChoices .DIRECTION_EGRESS ,
242181 assigned_object_type = ContentType .objects .get_for_model (VMInterface ),
243182 assigned_object_id = virtual_machine_interface1 .id ,
244183 ),
245184 )
246- ACLInterfaceAssignment .objects .bulk_create (acl_interface_assignments )
185+ ACLAssignment .objects .bulk_create (acl_assignments )
247186
248187 cls .create_data = [
249188 {
250- "access_list" : access_list_device .id ,
189+ "access_list" : acl1 .id ,
251190 "assigned_object_type" : "dcim.interface" ,
252191 "assigned_object_id" : device_interface3 .id ,
253192 "direction" : ACLAssignmentDirectionChoices .DIRECTION_EGRESS ,
254193 },
255194 {
256- "access_list" : access_list_vm .id ,
195+ "access_list" : acl2 .id ,
257196 "assigned_object_type" : "virtualization.vminterface" ,
258197 "assigned_object_id" : virtual_machine_interface2 .id ,
259198 "direction" : ACLAssignmentDirectionChoices .DIRECTION_INGRESS ,
260199 },
261200 {
262- "access_list" : access_list_vm .id ,
201+ "access_list" : acl2 .id ,
263202 "assigned_object_type" : "virtualization.vminterface" ,
264203 "assigned_object_id" : virtual_machine_interface3 .id ,
265204 "direction" : ACLAssignmentDirectionChoices .DIRECTION_EGRESS ,
0 commit comments