Improved coverage

This commit is contained in:
Antoine Nguyen
2025-06-11 14:35:58 +02:00
parent e62e4e1386
commit ca46b9ee8c
4 changed files with 83 additions and 34 deletions
+48
View File
@@ -148,6 +148,54 @@ Rebuild Virtual Environment
Specific instructions
*********************
Version 2.4.0
=============
Legacy web interface has been removed and all extensions have been
integrated to the core Modoboa package.
Pre update
----------
- If you are using Postegresql (default option with the installer),
run as a root user:
.. sourcecode:: bash
> sudo -u postgres -i psql -d "modoboa" -c "UPDATE django_content_type SET app_label='autoreply' WHERE app_label='postfix_autoreply'"
> sudo -u postgres -i psql -d "modoboa" -c "UPDATE django_migrations SET app='autoreply' WHERE app='postfix_autoreply'"
- If you are using Mysql, run as a root user:
.. sourcecode:: bash
> echo "UPDATE django_content_type SET app_label='autoreply' WHERE app_label='postfix_autoreply'" | mysql -u root -p modoboa
> echo "UPDATE django_migrations SET app='autoreply' WHERE app='postfix_autoreply'" | mysql -u root -p modoboa
Required changes to :file:`settings.py`
---------------------------------------
- Remove ``AjaxLoginRedirect`` from ``MIDDLEWARE`` variable:
.. sourcecode:: python
MIDDLEWARE = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'x_forwarded_for.middleware.XForwardedForMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'modoboa.core.middleware.LocalConfigMiddleware',
'modoboa.lib.middleware.CommonExceptionCatcher',
'modoboa.lib.middleware.RequestCatcherMiddleware',
)
Version 2.3.3
=============
@@ -4,8 +4,6 @@ from django.conf import settings
from django.core.management.base import BaseCommand
from django.utils.encoding import smart_str
from django.contrib.auth.models import Permission
from django.contrib.contenttypes.models import ContentType
from modoboa.admin import models
from modoboa.core.models import User
@@ -90,15 +88,6 @@ def sometimes_mailbox_have_no_alias(**options):
)
@known_problem
def postfix_autoreply_old_contenttypes(**options):
"""Sometime old postfix autoreply contenttypes might be present."""
for ct in ContentType.objects.filter(app_label="postfix_autoreply"):
result = Permission.objects.filter(content_type=ct).delete()
ct.delete()
log(f"Removed content type {ct.name} and {result[0]} associated permssions")
class Repair(BaseCommand):
"""Command class."""
+17
View File
@@ -22,6 +22,23 @@ class ARMessageViewSetTestCase(PatcherMixin, ModoAPITestCase):
cls.arm = factories.ARmessageFactory(mbox=cls.account.mailbox)
cls.arm2 = factories.ARmessageFactory(mbox=cls.account2.mailbox)
def test_update_global_settings(self):
data = {
"tracking_period": 7,
"default_subject": "Je suis parti",
"default_content": "Je reviendrai peut-être",
}
url = reverse("v2:parameter-global-detail", args=["autoreply"])
resp = self.client.put(url, data, format="json")
self.assertEqual(resp.status_code, 200)
data["tracking_period"] = 0
resp = self.client.put(url, data, format="json")
self.assertEqual(resp.status_code, 400)
self.assertEqual(
resp.json()["tracking_period"][0], "Value can't be less than 1 day"
)
def test_retrieve_armessage(self):
url = reverse("api:armessage-list")
response = self.client.get(url)
+18 -23
View File
@@ -35,30 +35,25 @@ class ARmessage(models.Model):
def update_sieve_rule(self, request, fset):
context = {"name": self.mbox.user.fullname}
if not self.fromdate:
condition = [("Subject", ":matches", "*")]
else:
days = request.localconfig.parameters.get_value("tracking_period")
context["fromdate"] = localize(self.fromdate)
fromdate = self.fromdate.isoformat()
fromdate, tz = fromdate.split("+")
tz = f"+{tz.replace(':', '')}"
condition = [
("currentdate", ":zone", tz, ":value", "ge", "iso8601", fromdate)
]
if self.untildate:
context["untildate"] = localize(self.untildate)
condition.append(
(
"currentdate",
":zone",
tz,
":value",
"lt",
"iso8601",
self.untildate.isoformat().split("+")[0],
)
days = request.localconfig.parameters.get_value("tracking_period")
context["fromdate"] = localize(self.fromdate)
fromdate = self.fromdate.isoformat()
fromdate, tz = fromdate.split("+")
tz = f"+{tz.replace(':', '')}"
condition = [("currentdate", ":zone", tz, ":value", "ge", "iso8601", fromdate)]
if self.untildate:
context["untildate"] = localize(self.untildate)
condition.append(
(
"currentdate",
":zone",
tz,
":value",
"lt",
"iso8601",
self.untildate.isoformat().split("+")[0],
)
)
content = self.content % context
name = "autoreply"
action = [("vacation", ":subject", self.subject, ":days", days, content)]