Improved coverage

This commit is contained in:
Antoine Nguyen
2025-06-19 17:31:04 +02:00
parent 55cb8d984d
commit 0143e4dcaf
2 changed files with 29 additions and 17 deletions
+20 -2
View File
@@ -19,26 +19,44 @@ class ManagementCommandTestCase(ModoAPITestCase):
"""Reset test env."""
shutil.rmtree(self.workdir)
def setUp(self):
super().setUp()
def configure(self):
self.key_map_path = f"{self.workdir}/keys.map"
self.set_global_parameter("key_map_path", self.key_map_path)
self.selector_map_path = f"{self.workdir}/selectors.map"
self.set_global_parameter("selector_map_path", self.selector_map_path)
def unconfigure(self):
self.set_global_parameter("key_map_path", "")
self.set_global_parameter("selector_map_path", "")
def test_command(self):
self.unconfigure()
with self.assertRaises(management.CommandError):
management.call_command("manage_rspamd_maps")
self.configure()
management.call_command("manage_rspamd_maps")
self.assertFalse(os.path.exists(self.key_map_path))
self.assertFalse(os.path.exists(self.selector_map_path))
domain = admin_models.Domain.objects.get(name="test.com")
domain.enable_dkim = True
domain.dkim_private_key_path = "xxx"
domain.save()
management.call_command("manage_rspamd_maps")
self.assertTrue(os.path.exists(self.key_map_path))
self.assertTrue(os.path.exists(self.selector_map_path))
# Now, empty map files
domain.enable_dkim = False
domain.save()
management.call_command("manage_rspamd_maps")
with open(self.key_map_path) as fp:
content = fp.read()
self.assertNotIn(domain.name, content)
def test_command_with_arg(self):
self.configure()
domain = admin_models.Domain.objects.get(name="test.com")
domain.enable_dkim = True
domain.save()
+9 -15
View File
@@ -1,21 +1,15 @@
"""Utilies for modoboa.rspamd plugin."""
from django.core.exceptions import AppRegistryNotReady
def get_rspamd_options():
try:
from modoboa.core import models
from modoboa.core import models
rspamd_options = {}
localconfig = models.LocalConfig.objects.first()
rspamd_location = localconfig.parameters.get_value(
"rspamd_dashboard_location", raise_exception=False
)
if not rspamd_location:
return None
rspamd_options["location"] = rspamd_location
return rspamd_options
except AppRegistryNotReady:
# If the instance is not restarted after rspamd installation
rspamd_options = {}
localconfig = models.LocalConfig.objects.first()
rspamd_location = localconfig.parameters.get_value(
"rspamd_dashboard_location", raise_exception=False
)
if not rspamd_location:
return None
rspamd_options["location"] = rspamd_location
return rspamd_options