pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/pheus/netbox-aci-plugin/commit/cc97b2f19f9bdfce42bf2eb24eb1ea0bb9a08856

/> test(models): Add field-specific validation for ACIPod · pheus/netbox-aci-plugin@cc97b2f · GitHub
Skip to content

Commit cc97b2f

Browse files
committed
test(models): Add field-specific validation for ACIPod
Enhances test cases by adding checks for field-level validation errors in `ACIPod`. Includes tests for `name`, `description`, `name_alias`, `pod_id`, and `tep_pool` to ensure detailed error reporting. Adds `pod_id` to all relevant test cases for consistency.
1 parent abf26b0 commit cc97b2f

File tree

1 file changed

+58
-9
lines changed

1 file changed

+58
-9
lines changed

netbox_aci_plugin/tests/models/fabric/test_pods.py

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,69 +84,118 @@ def test_aci_pod_tep_pool(self) -> None:
8484

8585
def test_invalid_aci_pod_name(self) -> None:
8686
"""Test validation of ACI Pod naming."""
87-
pod = ACIPod(name="ACI Test Pod 1")
88-
with self.assertRaises(ValidationError):
87+
pod = ACIPod(
88+
name="ACI Test Pod 1",
89+
aci_fabric=self.aci_fabric,
90+
pod_id=20,
91+
)
92+
with self.assertRaises(ValidationError) as cm:
8993
pod.full_clean()
9094

95+
# Check the specific field that failed
96+
self.assertIn("name", cm.exception.error_dict)
97+
9198
def test_invalid_aci_pod_name_length(self) -> None:
9299
"""Test validation of ACI Pod name length."""
93100
pod = ACIPod(
94101
name="T" * 65, # Exceeding the maximum length of 64
95102
aci_fabric=self.aci_fabric,
103+
pod_id=20,
96104
)
97-
with self.assertRaises(ValidationError):
105+
with self.assertRaises(ValidationError) as cm:
98106
pod.full_clean()
99107

108+
# Check the specific field that failed
109+
self.assertIn("name", cm.exception.error_dict)
110+
100111
def test_invalid_aci_pod_name_alias(self) -> None:
101112
"""Test validation of ACI pod aliasing."""
102113
pod = ACIPod(
103114
name="ACIPodTest1",
104115
name_alias="Invalid Alias",
105116
aci_fabric=self.aci_fabric,
117+
pod_id=20,
106118
)
107-
with self.assertRaises(ValidationError):
119+
with self.assertRaises(ValidationError) as cm:
108120
pod.full_clean()
109121

122+
# Check the specific field that failed
123+
self.assertIn("name_alias", cm.exception.error_dict)
124+
110125
def test_invalid_aci_pod_description(self) -> None:
111126
"""Test validation of ACI Pod description."""
112127
pod = ACIPod(
113128
name="ACITestPod1",
114129
description="Invalid Description: ö",
115130
aci_fabric=self.aci_fabric,
131+
pod_id=20,
116132
)
117-
with self.assertRaises(ValidationError):
133+
with self.assertRaises(ValidationError) as cm:
118134
pod.full_clean()
119135

136+
# Check the specific field that failed
137+
self.assertIn("description", cm.exception.error_dict)
138+
120139
def test_invalid_aci_pod_description_length(self) -> None:
121140
"""Test validation of ACI Pod description length."""
122141
pod = ACIPod(
123142
name="ACITestPod1",
124143
description="T" * 129, # Exceeding the maximum length of 128
125144
aci_fabric=self.aci_fabric,
145+
pod_id=20,
126146
)
127-
with self.assertRaises(ValidationError):
147+
with self.assertRaises(ValidationError) as cm:
128148
pod.full_clean()
129149

150+
# Check the specific field that failed
151+
self.assertIn("description", cm.exception.error_dict)
152+
130153
def test_invalid_aci_pod_id(self) -> None:
131154
"""Test validation of ACI Pod ID value."""
132155
pod = ACIPod(
133156
name="ACITestPod1",
134157
aci_fabric=self.aci_fabric,
135158
pod_id=5000,
136159
)
137-
with self.assertRaises(ValidationError):
160+
with self.assertRaises(ValidationError) as cm:
138161
pod.full_clean()
139162

163+
# Check the specific field that failed
164+
self.assertIn("pod_id", cm.exception.error_dict)
165+
166+
def test_invalid_aci_pod_tep_pool(self) -> None:
167+
"""Test validation of the ACI Pod TEP pool prefix."""
168+
invalid_tep_pool = Prefix(prefix="10.0.0.0/27")
169+
invalid_tep_pool.full_clean()
170+
invalid_tep_pool.save()
171+
pod = ACIPod(
172+
name="ACITestPod1",
173+
aci_fabric=self.aci_fabric,
174+
pod_id=20,
175+
tep_pool=invalid_tep_pool,
176+
)
177+
with self.assertRaises(ValidationError) as cm:
178+
pod.full_clean()
179+
180+
# Check the specific field that failed
181+
self.assertIn("tep_pool", cm.exception.error_dict)
182+
140183
def test_constraint_unique_aci_pod_name(self) -> None:
141184
"""Test unique constraint of ACI Pod name."""
142-
duplicate_pod = ACIPod(name=self.aci_pod_name, aci_fabric=self.aci_fabric)
185+
duplicate_pod = ACIPod(
186+
name=self.aci_pod_name,
187+
aci_fabric=self.aci_fabric,
188+
pod_id=100,
189+
)
143190
with self.assertRaises(IntegrityError):
144191
duplicate_pod.save()
145192

146193
def test_constraint_unique_aci_pod_id(self) -> None:
147194
"""Test unique constraint of ACI Pod ID."""
148195
duplicate_pod = ACIPod(
149-
name="ACITestPod1", aci_fabric=self.aci_fabric, pod_id=self.aci_pod_id
196+
name="ACITestPod1",
197+
aci_fabric=self.aci_fabric,
198+
pod_id=self.aci_pod_id,
150199
)
151200
with self.assertRaises(IntegrityError):
152201
duplicate_pod.save()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy