Optimized Docker Matrix Role in Preparation for use on CyMaIS.Cloud Server

This commit is contained in:
2025-05-15 21:11:21 +02:00
parent 9c65c320f9
commit 76aef5949b
20 changed files with 219 additions and 84 deletions

View File

@@ -0,0 +1,64 @@
import os
import sys
import unittest
# Add the filter_plugins directory from the docker-matrix role to the import path
sys.path.insert(
0,
os.path.abspath(
os.path.join(os.path.dirname(__file__), "../../roles/docker-matrix")
),
)
from filter_plugins.bridge_filters import filter_enabled_bridges
class TestBridgeFilters(unittest.TestCase):
def test_no_bridges_returns_empty_list(self):
# When there are no bridges defined, result should be an empty list
self.assertEqual(filter_enabled_bridges([], {}), [])
def test_all_bridges_disabled(self):
# Define two bridges, but plugins dict has them disabled or missing
bridges = [
{'bridge_name': 'whatsapp', 'config': {}},
{'bridge_name': 'telegram', 'config': {}},
]
plugins = {
'whatsapp': False,
'telegram': False,
}
result = filter_enabled_bridges(bridges, plugins)
self.assertEqual(result, [])
def test_some_bridges_enabled(self):
# Only bridges with True in plugins should be returned
bridges = [
{'bridge_name': 'whatsapp', 'version': '1.0'},
{'bridge_name': 'telegram', 'version': '1.0'},
{'bridge_name': 'signal', 'version': '1.0'},
]
plugins = {
'whatsapp': True,
'telegram': False,
'signal': True,
}
result = filter_enabled_bridges(bridges, plugins)
expected = [
{'bridge_name': 'whatsapp', 'version': '1.0'},
{'bridge_name': 'signal', 'version': '1.0'},
]
self.assertEqual(result, expected)
def test_bridge_without_plugin_entry_defaults_to_disabled(self):
# If a bridge_name is not present in plugins, it should be treated as disabled
bridges = [
{'bridge_name': 'facebook', 'enabled': True},
]
plugins = {} # no entries
result = filter_enabled_bridges(bridges, plugins)
self.assertEqual(result, [])
if __name__ == "__main__":
unittest.main()

View File

@@ -1,6 +1,16 @@
# tests/unit/test_configuration_filters.py
import unittest
import sys
import os
sys.path.insert(
0,
os.path.abspath(
os.path.join(os.path.dirname(__file__), "../../")
),
)
from filter_plugins.configuration_filters import (
is_feature_enabled,
)

View File

@@ -1,6 +1,16 @@
import unittest
import hashlib
import base64
import sys
import os
sys.path.insert(
0,
os.path.abspath(
os.path.join(os.path.dirname(__file__), "../../")
),
)
from filter_plugins.csp_filters import FilterModule, AnsibleFilterError
class TestCspFilters(unittest.TestCase):

View File

@@ -2,8 +2,12 @@ import os
import sys
import unittest
PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../.."))
sys.path.insert(0, PROJECT_ROOT)
sys.path.insert(
0,
os.path.abspath(
os.path.join(os.path.dirname(__file__), "../../")
),
)
from filter_plugins.redirect_filters import FilterModule