mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
Merge branch '1.6.x'
This commit is contained in:
@@ -42,8 +42,9 @@ class Repair(BaseCommand):
|
||||
if not quiet:
|
||||
print(message)
|
||||
|
||||
def fix_owner(self, model, dry_run=False, **options):
|
||||
for obj in model.objects.all():
|
||||
def fix_owner(self, qs, dry_run=False, **options):
|
||||
model = qs.model
|
||||
for obj in qs:
|
||||
kw = dict(
|
||||
cls=model.__name__,
|
||||
obj=obj
|
||||
@@ -76,11 +77,11 @@ class Repair(BaseCommand):
|
||||
@known_problem
|
||||
def sometimes_objects_have_no_owner(self, **options):
|
||||
owned_models = (
|
||||
User,
|
||||
models.Domain,
|
||||
models.Mailbox,
|
||||
models.Alias,
|
||||
models.DomainAlias
|
||||
User.objects.all(),
|
||||
models.Domain.objects.all(),
|
||||
models.DomainAlias.objects.all(),
|
||||
models.Alias.objects.filter(domain__isnull=False),
|
||||
models.Mailbox.objects.filter(domain__isnull=False),
|
||||
)
|
||||
for model in owned_models:
|
||||
self.fix_owner(model, **options)
|
||||
for qs in owned_models:
|
||||
self.fix_owner(qs, **options)
|
||||
|
||||
@@ -21,21 +21,31 @@ class RepairTestCase(ModoTestCase):
|
||||
def test_management_command(self):
|
||||
"""Check that command works fine."""
|
||||
ObjectAccess.objects.all().delete()
|
||||
mbox = models.Mailbox.objects.all()[0]
|
||||
mbox = models.Mailbox.objects.first()
|
||||
alias = models.Alias.objects.first()
|
||||
# assert mbox has no owner
|
||||
self.assertIs(get_object_owner(mbox), None)
|
||||
# fix it. run in quiet mode because we dont want output in tests
|
||||
management.call_command("modo", "repair", "--quiet")
|
||||
ret = management.call_command("modo", "repair", "--quiet")
|
||||
assert ret is None
|
||||
# assert its fixed
|
||||
self.assertIsNot(get_object_owner(mbox), None)
|
||||
self.assertIsNot(get_object_owner(alias), None)
|
||||
|
||||
def test_management_command_with_dry_run(self):
|
||||
"""Check that command works fine."""
|
||||
ObjectAccess.objects.all().delete()
|
||||
mbox = models.Mailbox.objects.all()[0]
|
||||
mbox = models.Mailbox.objects.first()
|
||||
# assert mbox has no owner
|
||||
self.assertIs(get_object_owner(mbox), None)
|
||||
# show problems. run in quiet mode because we dont want output in tests
|
||||
management.call_command("modo", "repair", "--quiet", "--dry-run")
|
||||
ret = management.call_command("modo", "repair", "--quiet", "--dry-run")
|
||||
assert ret is None
|
||||
# assert its not fixed
|
||||
self.assertIs(get_object_owner(mbox), None)
|
||||
|
||||
def test_management_command_with_nul_domain(self):
|
||||
""" Just assume nothing raise when an alias has no domain"""
|
||||
models.Alias.objects.create(address='@modoboa.xxx')
|
||||
ret = management.call_command("modo", "repair", "--quiet")
|
||||
assert ret is None
|
||||
|
||||
@@ -5,11 +5,13 @@ envlist = py27
|
||||
changedir=test_project
|
||||
commands =
|
||||
python ../tests.py
|
||||
coverage run --source ../modoboa manage.py test modoboa.core modoboa.lib modoboa.admin.tests modoboa.limits modoboa.relaydomains
|
||||
coverage run --source modoboa manage.py test modoboa.core modoboa.lib modoboa.admin.tests modoboa.limits modoboa.relaydomains
|
||||
coverage report --show-missing
|
||||
deps =
|
||||
-r{toxinidir}/test-requirements.txt
|
||||
coverage
|
||||
setenv =
|
||||
COVERAGE_FILE={envdir}/.coverage
|
||||
DB=SQLITE
|
||||
|
||||
[testenv:serve]
|
||||
|
||||
Reference in New Issue
Block a user