mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
Improved coverage
This commit is contained in:
+20
-2
@@ -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
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user