mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
Merge pull request #1068 from modoboa/fix/cleanlog
Fixed cleanlogs command.
This commit is contained in:
@@ -50,3 +50,14 @@ class UserFactory(PermissionFactory):
|
||||
if extracted:
|
||||
for group in extracted:
|
||||
self.groups.add(Group.objects.get(name=group))
|
||||
|
||||
|
||||
class LogFactory(factory.DjangoModelFactory):
|
||||
"""Factory for Log."""
|
||||
|
||||
class Meta:
|
||||
model = models.Log
|
||||
|
||||
logger = "modoboa.admin"
|
||||
message = "A message"
|
||||
level = "info"
|
||||
|
||||
@@ -7,12 +7,12 @@ from django.core.management.base import BaseCommand
|
||||
from django.utils import timezone
|
||||
|
||||
from modoboa.core.models import Log
|
||||
|
||||
from ... import parameters
|
||||
from modoboa.parameters import tools as param_tools
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
args = ""
|
||||
"""Command class."""
|
||||
|
||||
help = "Log table cleanup"
|
||||
|
||||
def add_arguments(self, parser):
|
||||
@@ -36,7 +36,7 @@ class Command(BaseCommand):
|
||||
l.addHandler(logging.StreamHandler())
|
||||
self.verbose = options["verbose"]
|
||||
|
||||
log_maximum_age = parameters.get_global_parameter("log_maximum_age")
|
||||
log_maximum_age = param_tools.get_global_parameter("log_maximum_age")
|
||||
self.__vprint("Deleting logs older than %d days..." % log_maximum_age)
|
||||
limit = timezone.now() - datetime.timedelta(log_maximum_age)
|
||||
Log.objects.filter(date_created__lt=limit).delete()
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
import httmock
|
||||
|
||||
from dateutil.relativedelta import relativedelta
|
||||
|
||||
from django.core import management
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.test import TestCase
|
||||
@@ -42,8 +44,8 @@ class AuthenticationTestCase(ModoTestCase):
|
||||
self.assertTrue(response.url.endswith(reverse("core:dashboard")))
|
||||
|
||||
|
||||
class LoadInitialDataTestCase(TestCase):
|
||||
"""Try to change the default username."""
|
||||
class ManagementCommandsTestCase(TestCase):
|
||||
"""Test management commands."""
|
||||
|
||||
def test_change_default_admin(self):
|
||||
"""Use dedicated option."""
|
||||
@@ -59,6 +61,15 @@ class LoadInitialDataTestCase(TestCase):
|
||||
self.assertIn("core", lc._parameters)
|
||||
self.assertIn("secret_key", lc._parameters["core"])
|
||||
|
||||
def test_clean_logs(self):
|
||||
"""Run cleanlogs command."""
|
||||
log1 = factories.LogFactory()
|
||||
factories.LogFactory()
|
||||
log1.date_created -= relativedelta(years=2)
|
||||
log1.save(update_fields=["date_created"])
|
||||
management.call_command("cleanlogs")
|
||||
self.assertEqual(models.Log.objects.count(), 1)
|
||||
|
||||
|
||||
class ProfileTestCase(ModoTestCase):
|
||||
"""Profile related tests."""
|
||||
|
||||
Reference in New Issue
Block a user