Skip to content

Commit c46f768

Browse files
committed
fix tests
1 parent 81db4da commit c46f768

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

netbox_acls/tests/test_models.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def test_alphanumeric_plus_success(self):
9191
type=ACLTypeChoices.TYPE_EXTENDED,
9292
default_action=ACLActionChoices.ACTION_PERMIT,
9393
)
94-
self.assertRaises(ValidationError, acl_good_name.clean)
94+
acl_good_name.full_clean()
9595

9696
def test_duplicate_name_success(self):
9797
"""
@@ -112,7 +112,7 @@ def test_duplicate_name_success(self):
112112
assigned_object_type=ContentType.objects.get_for_model(VirtualMachine),
113113
assigned_object_id=1,
114114
)
115-
self.assertIsNone(new_acl.clean())
115+
new_acl.full_clean()
116116
# TODO: test_duplicate_name_fail - VM & Cluster
117117

118118
def test_alphanumeric_plus_fail(self):
@@ -122,30 +122,33 @@ def test_alphanumeric_plus_fail(self):
122122
non_alphanumeric_plus_chars = " !@#$%^&*()[]{};:,./<>?\|~=+"
123123

124124
for i, char in enumerate(non_alphanumeric_plus_chars, start=1):
125-
bade_acl_name = AccessList(
125+
bad_acl_name = AccessList(
126126
name=f"Testacl-bad_name_{i}_{char}",
127127
assigned_object_type=ContentType.objects.get_for_model(Device),
128128
assigned_object_id=1,
129129
type=ACLTypeChoices.TYPE_EXTENDED,
130130
default_action=ACLActionChoices.ACTION_PERMIT,
131131
comments=f'ACL with "{char}" in name',
132132
)
133-
self.assertIsNone(bade_acl_name.clean)
133+
with self.assertRaises(ValidationError):
134+
bad_acl_name.full_clean()
134135

135136
def test_duplicate_name_fail(self):
136137
"""
137138
Test that AccessList names must be unique per device.
138139
"""
139140
params = {
140141
"name": "FAIL-DUPLICATE-ACL",
141-
"assigned_object_type": "dcim.device",
142+
"assigned_object_type": ContentType.objects.get_for_model(Device),
142143
"assigned_object_id": 1,
143144
"type": ACLTypeChoices.TYPE_STANDARD,
144145
"default_action": ACLActionChoices.ACTION_PERMIT,
145146
}
146-
AccessList.objects.create(**params)
147-
duplicate_acl = AccessList(**params)
148-
self.assertRaises(ValidationError, duplicate_acl.clean())
147+
acl_1 =AccessList.objects.create(**params)
148+
acl_1.save()
149+
acl_2 = AccessList(**params)
150+
with self.assertRaises(ValidationError):
151+
acl_2.full_clean()
149152
# TODO: test_duplicate_name_fail - VM & Cluster
150153

151154
# TODO: Test choices for AccessList Model

0 commit comments

Comments
 (0)