General code optimations and peertube optimation

This commit is contained in:
2025-05-20 07:00:29 +02:00
parent a051fde662
commit 5948d7aa93
19 changed files with 306 additions and 115 deletions

View File

@@ -13,7 +13,7 @@ def get_meta_info(role_path):
if not os.path.isfile(meta_file):
return [], []
meta_data = load_yaml_file(meta_file)
run_order = meta_data.get('applications_run_order', {})
run_order = meta_data.get('role_run_order', {})
before = run_order.get('before', [])
after = run_order.get('after', [])
return before, after

View File

@@ -0,0 +1,57 @@
import os
import sys
import unittest
sys.path.insert(
0,
os.path.abspath(
os.path.join(os.path.dirname(__file__), "../../")
),
)
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()