@@ -71,26 +71,43 @@ def setUpTestData(cls):
71
71
type = clustertype ,
72
72
)
73
73
virtual_machine = VirtualMachine .objects .create (name = "VirtualMachine 1" )
74
+ prefix = Prefix .objects .create (prefix = "10.0.0.0/8" )
74
75
75
76
76
77
class TestAccessList (BaseTestCase ):
77
78
"""
78
79
Test AccessList model.
79
80
"""
80
81
82
+ common_acl_params = {
83
+ "assigned_object_id" : 1 ,
84
+ "type" : ACLTypeChoices .TYPE_EXTENDED ,
85
+ "default_action" : ACLActionChoices .ACTION_PERMIT ,
86
+ }
87
+
88
+ def test_wrong_assigned_object_type_fail (self ):
89
+ """
90
+ Test that AccessList cannot be assigned to an object type other than Device, VirtualChassis, VirtualMachine, or Cluster.
91
+ """
92
+ acl_bad_gfk = AccessList (
93
+ name = "TestACL_Wrong_GFK" ,
94
+ assigned_object_type = ContentType .objects .get_for_model (Prefix ),
95
+ ** self .common_acl_params ,
96
+ )
97
+ with self .assertRaises (ValidationError ):
98
+ acl_bad_gfk .full_clean ()
99
+
81
100
def test_alphanumeric_plus_success (self ):
82
101
"""
83
102
Test that AccessList names with alphanumeric characters, '_', or '-' pass validation.
84
103
"""
85
104
acl_good_name = AccessList (
86
- name = "Testacl-good_name -1" ,
105
+ name = "Testacl-Good_Name -1" ,
87
106
assigned_object_type = ContentType .objects .get_for_model (Device ),
88
- assigned_object_id = 1 ,
89
- type = ACLTypeChoices .TYPE_EXTENDED ,
90
- default_action = ACLActionChoices .ACTION_PERMIT ,
107
+ ** self .common_acl_params ,
91
108
)
92
109
acl_good_name .full_clean ()
93
- # TODO: test_alphanumeric_plus_success - VirtualChassis & Cluster
110
+ # TODO: test_alphanumeric_plus_success - VirtualChassis, VirtualMachine & Cluster
94
111
95
112
def test_duplicate_name_success (self ):
96
113
"""
@@ -103,23 +120,23 @@ def test_duplicate_name_success(self):
103
120
"default_action" : ACLActionChoices .ACTION_PERMIT ,
104
121
}
105
122
AccessList .objects .create (
106
- ** params ,
123
+ name = "GOOD-DUPLICATE-ACL" ,
107
124
assigned_object_type = ContentType .objects .get_for_model (Device ),
108
- assigned_object_id = 1 ,
125
+ ** self . common_acl_params ,
109
126
)
110
127
vm_acl = AccessList (
111
- ** params ,
128
+ name = "GOOD-DUPLICATE-ACL" ,
112
129
assigned_object_type = ContentType .objects .get_for_model (VirtualMachine ),
113
- assigned_object_id = 1 ,
130
+ ** self . common_acl_params ,
114
131
)
115
132
vm_acl .full_clean ()
116
- # TODO: test_duplicate_name_success - VirtualChassis & Cluster
117
- #vc_acl = AccessList(
118
- # **params ,
133
+ # TODO: test_duplicate_name_success - VirtualChassis, VirtualMachine & Cluster
134
+ # vc_acl = AccessList(
135
+ # "name": "GOOD-DUPLICATE-ACL" ,
119
136
# assigned_object_type=ContentType.objects.get_for_model(VirtualChassis),
120
- # assigned_object_id=1 ,
121
- #)
122
- #vc_acl.full_clean()
137
+ # **self.common_acl_params ,
138
+ # )
139
+ # vc_acl.full_clean()
123
140
124
141
def test_alphanumeric_plus_fail (self ):
125
142
"""
@@ -131,10 +148,8 @@ def test_alphanumeric_plus_fail(self):
131
148
bad_acl_name = AccessList (
132
149
name = f"Testacl-bad_name_{ i } _{ char } " ,
133
150
assigned_object_type = ContentType .objects .get_for_model (Device ),
134
- assigned_object_id = 1 ,
135
- type = ACLTypeChoices .TYPE_EXTENDED ,
136
- default_action = ACLActionChoices .ACTION_PERMIT ,
137
151
comments = f'ACL with "{ char } " in name' ,
152
+ ** self .common_acl_params ,
138
153
)
139
154
with self .assertRaises (ValidationError ):
140
155
bad_acl_name .full_clean ()
@@ -146,9 +161,8 @@ def test_duplicate_name_fail(self):
146
161
params = {
147
162
"name" : "FAIL-DUPLICATE-ACL" ,
148
163
"assigned_object_type" : ContentType .objects .get_for_model (Device ),
164
+ ** self .common_acl_params ,
149
165
"assigned_object_id" : 1 ,
150
- "type" : ACLTypeChoices .TYPE_STANDARD ,
151
- "default_action" : ACLActionChoices .ACTION_PERMIT ,
152
166
}
153
167
acl_1 = AccessList .objects .create (** params )
154
168
acl_1 .save ()
@@ -172,18 +186,18 @@ def setUpTestData(cls):
172
186
"""
173
187
super ().setUpTestData ()
174
188
175
- #interfaces = Interface.objects.bulk_create(
189
+ # interfaces = Interface.objects.bulk_create(
176
190
# (
177
191
# Interface(name="Interface 1", device=device, type="1000baset"),
178
192
# Interface(name="Interface 2", device=device, type="1000baset"),
179
193
# )
180
- #)
181
- #vminterfaces = VMInterface.objects.bulk_create(
194
+ # )
195
+ # vminterfaces = VMInterface.objects.bulk_create(
182
196
# (
183
197
# VMInterface(name="Interface 1", virtual_machine=virtual_machine),
184
198
# VMInterface(name="Interface 2", virtual_machine=virtual_machine),
185
199
# )
186
- #)
200
+ # )
187
201
# prefixes = Prefix.objects.bulk_create(
188
202
# (
189
203
# Prefix(prefix=IPNetwork("10.0.0.0/24")),
@@ -224,15 +238,18 @@ def test_acl_already_assinged_fail(self):
224
238
225
239
# TODO: Investigate a Base model for ACLStandardRule and ACLExtendedRule
226
240
241
+
227
242
class TestACLStandardRule (BaseTestCase ):
228
243
"""
229
244
Test ACLStandardRule model.
230
245
"""
246
+
231
247
# TODO: Develop tests for ACLStandardRule model
232
248
233
249
234
250
class ACLExtendedRule (BaseTestCase ):
235
251
"""
236
252
Test ACLExtendedRule model.
237
253
"""
254
+
238
255
# TODO: Develop tests for ACLExtendedRule model
0 commit comments