mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-08-29 15:06:26 +02:00
Optimized defaults_redirect_domain_mappings for dynamic creating by roles
This commit is contained in:
53
tests/unit/test_redirect_filters.py
Normal file
53
tests/unit/test_redirect_filters.py
Normal file
@@ -0,0 +1,53 @@
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../.."))
|
||||
sys.path.insert(0, PROJECT_ROOT)
|
||||
|
||||
from filter_plugins.redirect_filters import FilterModule
|
||||
|
||||
|
||||
class TestAddRedirectIfGroup(unittest.TestCase):
|
||||
"""Unit-tests for the add_redirect_if_group filter."""
|
||||
|
||||
def setUp(self):
|
||||
# Obtain the callable once for reuse
|
||||
self.add_redirect = FilterModule().filters()["add_redirect_if_group"]
|
||||
|
||||
def test_appends_redirect_when_group_present(self):
|
||||
original = [{"source": "a", "target": "b"}]
|
||||
result = self.add_redirect(
|
||||
original,
|
||||
group="lam",
|
||||
source="ldap.example.com",
|
||||
target="lam.example.com",
|
||||
group_names=["lam", "other"],
|
||||
)
|
||||
|
||||
# Original list must stay unchanged
|
||||
self.assertEqual(len(original), 1)
|
||||
# Result list must contain the extra entry
|
||||
self.assertEqual(len(result), 2)
|
||||
self.assertIn(
|
||||
{"source": "ldap.example.com", "target": "lam.example.com"}, result
|
||||
)
|
||||
|
||||
def test_keeps_list_unchanged_when_group_absent(self):
|
||||
original = [{"source": "a", "target": "b"}]
|
||||
result = self.add_redirect(
|
||||
original,
|
||||
group="lam",
|
||||
source="ldap.example.com",
|
||||
target="lam.example.com",
|
||||
group_names=["unrelated"],
|
||||
)
|
||||
|
||||
# No new entries
|
||||
self.assertEqual(result, original)
|
||||
# But ensure a new list object was returned (no in-place mutation)
|
||||
self.assertIsNot(result, original)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
Reference in New Issue
Block a user