|
2 | 2 |
|
3 | 3 | # ruff: noqa: F403, F405 |
4 | 4 | # pylint: disable=protected-access |
5 | | -from unittest import skip |
| 5 | +import unittest |
6 | 6 | from unittest.mock import patch |
7 | 7 |
|
8 | 8 | from django.core.exceptions import ValidationError |
9 | | -from django.test import TestCase |
| 9 | +from nautobot.apps.testing import TestCase |
10 | 10 | from nautobot.dcim.models import Device, Platform |
11 | 11 | from nautobot.extras.models import Status |
12 | 12 | from nautobot.ipam.models import IPAddress, Namespace |
13 | 13 |
|
14 | 14 | from nautobot_firewall_models.models import * # pylint: disable=unused-wildcard-import, wildcard-import |
15 | | -from nautobot_firewall_models.utils.capirca import DevicePolicyToCapirca, PolicyToCapirca, generate_capirca_config |
| 15 | +from nautobot_firewall_models.utils.capirca import ( |
| 16 | + DevicePolicyToCapirca, |
| 17 | + PolicyToCapirca, |
| 18 | + _slugify, |
| 19 | + generate_capirca_config, |
| 20 | +) |
16 | 21 |
|
17 | 22 | from .fixtures import create_capirca_env |
18 | 23 |
|
@@ -280,6 +285,39 @@ def test_generate_capirca_config(self): |
280 | 285 | self.assertEqual(actual_cfg, CFG) |
281 | 286 |
|
282 | 287 |
|
| 288 | +class TestSlugify(unittest.TestCase): |
| 289 | + """Test models.""" |
| 290 | + |
| 291 | + def test_slugify_removes_accents(self): |
| 292 | + self.assertEqual(_slugify("Café"), "Cafe") |
| 293 | + self.assertEqual(_slugify("mañana"), "manana") |
| 294 | + |
| 295 | + def test_slugify_removes_non_alphanumeric_characters(self): |
| 296 | + self.assertEqual(_slugify("Hello!! World??"), "Hello-World") |
| 297 | + self.assertEqual(_slugify("A*B&C(D)"), "ABCD") |
| 298 | + |
| 299 | + def test_slugify_adds_leading_underscore_if_starts_with_digit(self): |
| 300 | + self.assertEqual(_slugify("123abc"), "_123abc") |
| 301 | + self.assertEqual(_slugify("9-lives"), "_9-lives") |
| 302 | + |
| 303 | + def test_slugify_collapses_spaces_and_hyphens(self): |
| 304 | + self.assertEqual(_slugify("hello world"), "hello-world") |
| 305 | + self.assertEqual(_slugify("hello---world"), "hello-world") |
| 306 | + self.assertEqual(_slugify("hello_ - world"), "hello_-world") |
| 307 | + |
| 308 | + def test_slugify_removes_unicode_symbols(self): |
| 309 | + self.assertEqual(_slugify("★Test☆string★"), "Teststring") |
| 310 | + |
| 311 | + def test_value_is_integer(self): |
| 312 | + self.assertEqual(_slugify(1234), "_1234") |
| 313 | + |
| 314 | + def test_clean_slug(self): |
| 315 | + self.assertEqual(_slugify("Clean-Slug_123"), "Clean-Slug_123") |
| 316 | + |
| 317 | + def test_empty_string(self): |
| 318 | + self.assertEqual(_slugify(""), "") |
| 319 | + |
| 320 | + |
283 | 321 | class TestPolicyToCapirca(TestCase): # pylint: disable=too-many-public-methods,too-many-instance-attributes |
284 | 322 | """Test models.""" |
285 | 323 |
|
@@ -631,7 +669,7 @@ def setUp(self) -> None: |
631 | 669 | create_capirca_env() |
632 | 670 | self.device_obj = Device.objects.get(name="DFW02-WAN00") |
633 | 671 |
|
634 | | - @skip("Not implemented until policy method provided to merge queries provided") |
| 672 | + @unittest.skip("Not implemented until policy method provided to merge queries provided") |
635 | 673 | def test_dynamic_group_and_device(self): |
636 | 674 | """Test that dynamic groups are created and device is added to it, disabled.""" |
637 | 675 |
|
|
0 commit comments