From c66f89764cf91bead8e7905a421ef2279bf6d324 Mon Sep 17 00:00:00 2001 From: Antoine Nguyen Date: Thu, 14 Apr 2016 14:37:18 +0200 Subject: [PATCH] Fix unit tests. see #860 --- modoboa/lib/middleware.py | 11 ++++++++--- modoboa/limits/handlers.py | 2 +- modoboa/limits/tests.py | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/modoboa/lib/middleware.py b/modoboa/lib/middleware.py index aa971bd1a..55fdcd078 100644 --- a/modoboa/lib/middleware.py +++ b/modoboa/lib/middleware.py @@ -10,6 +10,8 @@ from modoboa.lib.web_utils import ( _render_error, ajax_response, render_to_json_response ) +from . import singleton + class AjaxLoginRedirect(object): @@ -41,10 +43,13 @@ class CommonExceptionCatcher(object): ) -class RequestCatcherMiddleware(object): +class RequestCatcherMiddleware(singleton.Singleton): + """Simple middleware to store the current request. - """ - Simple middleware to store the current request. + FIXME: the Singleton hack is used to make tests work. I don't know + why but middlewares are not dropped between test case runs so more + than one instance can be listening to the request_accessor signal + and we don't want that! """ def __init__(self): diff --git a/modoboa/limits/handlers.py b/modoboa/limits/handlers.py index 6eeddc6d4..1588fecbb 100644 --- a/modoboa/limits/handlers.py +++ b/modoboa/limits/handlers.py @@ -37,7 +37,7 @@ def create_user_limits(sender, instance, **kwargs): ct = ContentType.objects.get_by_natural_key( *definition["content_type"].split(".")) max_value = 0 - if not creator or creator.is_superuser: + if creator and creator.is_superuser: max_value = int( parameters.get_admin("DEFLT_{}_LIMIT".format(name.upper()))) models.ObjectLimit.objects.create( diff --git a/modoboa/limits/tests.py b/modoboa/limits/tests.py index c235ef1ef..253c48880 100644 --- a/modoboa/limits/tests.py +++ b/modoboa/limits/tests.py @@ -180,7 +180,6 @@ class ResellerTestCase(ResourceTestCase): cls.user = UserFactory( username='reseller', groups=('Resellers',) ) - cls.user.objectlimit_set.update(max_value=2) def setUp(self): """Test initialization.""" @@ -329,6 +328,7 @@ class ResellerTestCase(ResourceTestCase): self._check_limit('mailbox_aliases', 0, 2) def test_restore_resources(self): + """Give resource to a domain admin and restore them.""" self._create_domain('domain.tld') dom = Domain.objects.get(name='domain.tld') self._create_account('admin1@domain.tld', role='DomainAdmins')