mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
pep8 fixes
- B007 Loop control variable not used within the loop body. If this is intended, start the name with an underscore.
* modoboa/admin/lib.py
* modoboa/admin/templatetags/admin_tags.py
* modoboa/admin/tests/test_account.py
* modoboa/admin/views/domain.py
* modoboa/admin/views/identity.py
* modoboa/core/views/dashboard.py
* modoboa/limits/forms.py
* modoboa/limits/handlers.py
* modoboa/limits/tests/test_api.py
* modoboa/limits/tests/test_domain_limits.py
* modoboa/limits/tests/test_import.py
* modoboa/limits/tests/test_user_limits.py
* modoboa/limits/utils.py
* modoboa/parameters/tools.py
* modoboa/relaydomains/tests.py
- C402 Unnecessary generator - rewrite as a dict comprehension.
* modoboa/admin/models/domain.py
* modoboa/admin/views/domain.py
* modoboa/admin/views/identity.py
* modoboa/limits/searializers.py
- C407 Unnecessary list comprehension - can take a generator.
* modoboa/core/password_validation.py
* modoboa/parameters/tools.py
* modoboa/transport/backends.py
- C408 Unnecessary dict call - rewrite as a literal.
* modoboa/admin/tests/test_account.py
* modoboa/admin/tests/test_alias.py
* modoboa/admin/tests/test_password_schemes.py
* modoboa/admin/views/domain.py
* modoboa/admin/views/identity.py
* modoboa/core/extensions.py
* modoboa/lib/middleware.py
* modoboa/lib/templatetags/form_tags.py
* modoboa/lib/templatetags/lib_tags.py
* modoboa/lib/web_utils.py
* modoboa/limits/handlers.py
* modoboa/limits/tests/test_user_limits.py
- E741 ambiguous variable name
* modoboa/core/management/commands/cleanlogs.py
* modoboa/limits/forms.py
* modoboa/limits/tests/test_user_limits.py
* modoboa/limits/utils.py
* modoboa/relaydomains/tests.py
- F401 imported but unused
* doc/conf.py
* modoboa/admin/views/domain.py
* modoboa/core/app_settings.py
* modoboa/core/management/commands/load_initial_data.py
- F821 undefined name 'raw_input'
* modoboa/core/commands/deploy.py
- F841 local variable 'test' is assigned to but never used
* modoboa/core/app_settings.py
- N802 function name 'setUpTestData' should be lowercase xxx
* modoboa/lib/email_utils.py - __ for name mangeling, _ for internal
- N805 first argument of a method should be named 'self'
* modoboa/lib/connections.py
* modoboa/lib/singleton.py
Ignore the following
- A001 "copyright" is a python builtin and is being shadowed, consider renaming the variable
* doc/conf.py
- A003 is a python builtin, consider renaming the class attribute
* modoboa/admin/factories.py
* modoboa/admin/forms/domain.py
* modoboa/admin/management/commands/handle_mailbox_operations.py
* modoboa/admin/management/commands/modo.py
* modoboa/admin/management/commands/subcommands/_repair.py
* modoboa/admin/models/domain.py
* modoboa/admin/models/mailbox.py
* modoboa/core/commands/__init__.py
* modoboa/core/commands/deploy.py
* modoboa/core/commands/help.py
* modoboa/core/management/commands/clean_inactive_accounts.py
* modoboa/core/management/commands/cleanlogs.py
* modoboa/core/management/commands/communicate_with_public_api.py
* modoboa/core/management/commands/generate_postfix_maps.py
* modoboa/core/management/commands/load_initial_data.py
* modoboa/core/management/commands/set_default_site.py
- F401 imported but unused
* modoboa/admin/apps.py - used to load handlers
* modoboa/core/password_hashers/__init__.py - dynamically loaded
* modoboa/limits/apps.py - used to load handlers
* modoboa/relaydomains/apps.py - used to load handlers
* modoboa/transport/apps.py - used to load handlers
- N802 function name should be lowercase xxx
* modoboa/admin/tests/test_account.py
* modoboa/admin/tests/test_alias.py
* modoboa/admin/tests/test_domain_alias.py
* modoboa/admin/tests/test_export.py
* modoboa/admin/tests/test_mailbox_operations.py
* modoboa/admin/tests/test_password_schemas.py
* modoboa/admin/tests/test_repair.py
* modoboa/core/tests/test_authentication.py
* modoboa/core/tests/test_core.py
* modoboa/core/tests/test_ldap.py
* modoboa/core/tests/test_views.py
* modoboa/lib/imap_utf7.py
* modoboa/limits/tests/test_api.py
* modoboa/limits/tests/test_domain_limits.py
* modoboa/limits/tests/test_import.py
* modoboa/limits/tests/test_user_limits.py
* modoboa/relaydomains/tests.py
other fixes:
- use isinstance() instead of type() == Class
This commit is contained in:
+2
-2
@@ -12,7 +12,7 @@
|
||||
# serve to show the default.
|
||||
|
||||
import os
|
||||
import sys
|
||||
# import sys
|
||||
|
||||
# If extensions (or modules to document with autodoc) are in another directory,
|
||||
# add these directories to sys.path here. If the directory is relative to the
|
||||
@@ -44,7 +44,7 @@ master_doc = "index"
|
||||
|
||||
# General information about the project.
|
||||
project = u'Modoboa'
|
||||
copyright = u'2018, Antoine Nguyen'
|
||||
copyright = u'2018, Antoine Nguyen' # NOQA:A001
|
||||
|
||||
# The version info for the project you're documenting, acts as replacement for
|
||||
# |version| and |release|, also used in various other places throughout the
|
||||
|
||||
@@ -17,4 +17,4 @@ class AdminConfig(AppConfig):
|
||||
def ready(self):
|
||||
load_admin_settings()
|
||||
|
||||
from . import handlers
|
||||
from . import handlers # NOQA:F401
|
||||
|
||||
@@ -18,7 +18,7 @@ class DomainFactory(PermissionFactory):
|
||||
model = models.Domain
|
||||
django_get_or_create = ("name", )
|
||||
|
||||
type = "domain"
|
||||
type = "domain" # NOQA:A003
|
||||
quota = 0
|
||||
default_mailbox_quota = 10
|
||||
enabled = True
|
||||
|
||||
@@ -26,7 +26,7 @@ from ..models import Alias, Domain, DomainAlias, Mailbox
|
||||
class DomainFormGeneral(forms.ModelForm, DynamicForm):
|
||||
"""A form to create/edit a domain."""
|
||||
|
||||
type = forms.ChoiceField(
|
||||
type = forms.ChoiceField( # NOQA:A003
|
||||
label=ugettext_lazy("Type"),
|
||||
)
|
||||
aliases = DomainNameField(
|
||||
|
||||
@@ -223,7 +223,7 @@ def domain_has_authorized_mx(name):
|
||||
valid_mxs = [ipaddress.ip_network(smart_text(v.strip()))
|
||||
for v in valid_mxs.split() if v.strip()]
|
||||
domain_mxs = get_domain_mx_list(name)
|
||||
for mx_addr, mx_ip_addr in domain_mxs: # noqa:B007
|
||||
for _mx_addr, mx_ip_addr in domain_mxs:
|
||||
for subnet in valid_mxs:
|
||||
if mx_ip_addr in subnet:
|
||||
return True
|
||||
|
||||
@@ -24,7 +24,7 @@ class OperationError(Exception):
|
||||
class Command(BaseCommand):
|
||||
"""Command definition"""
|
||||
|
||||
help = "Handles rename and delete operations on mailboxes"
|
||||
help = "Handles rename and delete operations on mailboxes" # NOQA:A003
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(Command, self).__init__(*args, **kwargs)
|
||||
|
||||
@@ -17,7 +17,7 @@ class Command(SubcommandCommand):
|
||||
$ python manage.py modo
|
||||
"""
|
||||
|
||||
help = "Modoboa top management command."
|
||||
help = "Modoboa top management command." # NOQA:A003
|
||||
|
||||
subcommands = {
|
||||
"export": ExportCommand,
|
||||
|
||||
@@ -16,7 +16,7 @@ from .... import models
|
||||
class ExportCommand(BaseCommand):
|
||||
"""Command class."""
|
||||
|
||||
help = "Export domains or identities using CSV format" # noqa:A003
|
||||
help = "Export domains or identities using CSV format" # NOQA:A003
|
||||
|
||||
def add_arguments(self, parser):
|
||||
"""Add arguments to command."""
|
||||
|
||||
@@ -20,7 +20,7 @@ class ImportCommand(BaseCommand):
|
||||
"""Command class."""
|
||||
|
||||
args = "csvfile"
|
||||
help = "Import identities from a csv file" # noqa:A003
|
||||
help = "Import identities from a csv file" # NOQA:A003
|
||||
|
||||
def add_arguments(self, parser):
|
||||
"""Add extra arguments to command."""
|
||||
|
||||
@@ -25,7 +25,7 @@ from modoboa.parameters import tools as param_tools
|
||||
class CheckMXRecords(BaseCommand):
|
||||
"""Command class."""
|
||||
|
||||
help = "Check defined domains." # noqa:A003
|
||||
help = "Check defined domains." # NOQA:A003
|
||||
|
||||
@cached_property
|
||||
def providers(self):
|
||||
|
||||
@@ -95,7 +95,7 @@ def sometimes_mailbox_have_no_alias(**options):
|
||||
class Repair(BaseCommand):
|
||||
"""Command class."""
|
||||
|
||||
help = "Check and fix known problems."
|
||||
help = "Check and fix known problems." # NOQA:A003
|
||||
|
||||
def add_arguments(self, parser):
|
||||
"""Add extra arguments to command."""
|
||||
|
||||
@@ -48,7 +48,7 @@ class Domain(AdminObject):
|
||||
help_text=ugettext_lazy("Check to activate this domain"),
|
||||
default=True
|
||||
)
|
||||
type = models.CharField(default="domain", max_length=20)
|
||||
type = models.CharField(default="domain", max_length=20) # NOQA:A003
|
||||
enable_dns_checks = models.BooleanField(
|
||||
ugettext_lazy("Enable DNS checks"), default=True,
|
||||
help_text=ugettext_lazy("Check to enable DNS checks for this domain")
|
||||
@@ -244,9 +244,9 @@ class Domain(AdminObject):
|
||||
def save(self, *args, **kwargs):
|
||||
"""Store current data if domain is renamed."""
|
||||
if self.oldname != self.name:
|
||||
self.old_mail_homes = (
|
||||
dict((mb.id, mb.mail_home) for mb in self.mailbox_set.all())
|
||||
)
|
||||
self.old_mail_homes = {
|
||||
mb.id: mb.mail_home for mb in self.mailbox_set.all()
|
||||
}
|
||||
super(Domain, self).save(*args, **kwargs)
|
||||
|
||||
def delete(self, fromuser, keepdir=False):
|
||||
|
||||
@@ -41,7 +41,7 @@ class Quota(models.Model):
|
||||
"""Keeps track of Mailbox current quota."""
|
||||
|
||||
username = models.EmailField(primary_key=True, max_length=254)
|
||||
bytes = models.BigIntegerField(default=0)
|
||||
bytes = models.BigIntegerField(default=0) # NOQA:A003
|
||||
messages = models.IntegerField(default=0)
|
||||
|
||||
objects = QuotaManager()
|
||||
@@ -374,7 +374,7 @@ class MailboxOperation(models.Model):
|
||||
|
||||
mailbox = models.ForeignKey(Mailbox, blank=True, null=True,
|
||||
on_delete=models.CASCADE)
|
||||
type = models.CharField(
|
||||
type = models.CharField( # NOQA:A003
|
||||
max_length=20, choices=(("rename", "rename"), ("delete", "delete"))
|
||||
)
|
||||
argument = models.TextField()
|
||||
|
||||
@@ -156,7 +156,7 @@ def domain_actions(user, domain):
|
||||
|
||||
responses = signals.extra_domain_actions.send(
|
||||
sender=None, user=user, domain=domain)
|
||||
for receiver, response in responses:
|
||||
for _receiver, response in responses:
|
||||
if response:
|
||||
actions += response
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ class AuthenticationTestCase(ModoTestCase):
|
||||
"""Check authentication."""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Create test data."""
|
||||
super(AuthenticationTestCase, cls).setUpTestData()
|
||||
cls.mb = factories.MailboxFactory(
|
||||
@@ -43,18 +43,18 @@ class AuthenticationTestCase(ModoTestCase):
|
||||
class AccountTestCase(ModoTestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Create test data."""
|
||||
super(AccountTestCase, cls).setUpTestData()
|
||||
factories.populate_database()
|
||||
|
||||
def test_crud(self):
|
||||
values = dict(
|
||||
username="tester@test.com", first_name="Tester", last_name="Toto",
|
||||
password1="Toto1234", password2="Toto1234", role="SimpleUsers",
|
||||
quota_act=True,
|
||||
is_active=True, email="tester@test.com", stepid="step2"
|
||||
)
|
||||
values = {
|
||||
"username": "tester@test.com", "first_name": "Tester",
|
||||
"last_name": "Toto", "password1": "Toto1234",
|
||||
"password2": "Toto1234", "role": "SimpleUsers", "quota_act": True,
|
||||
"is_active": True, "email": "tester@test.com", "stepid": "step2"
|
||||
}
|
||||
self.ajax_post(reverse("admin:account_add"), values)
|
||||
|
||||
account = User.objects.get(username="tester@test.com")
|
||||
@@ -341,12 +341,12 @@ class AccountTestCase(ModoTestCase):
|
||||
|
||||
def test_utf8_username(self):
|
||||
"""Create an account with non-ASCII characters."""
|
||||
values = dict(
|
||||
username="téster@test.com", first_name="Tester", last_name="Toto",
|
||||
password1="Toto1234", password2="Toto1234", role="SimpleUsers",
|
||||
quota_act=True,
|
||||
is_active=True, email="téster@test.com", stepid="step2"
|
||||
)
|
||||
values = {
|
||||
"username": "téster@test.com", "first_name": "Tester",
|
||||
"last_name": "Toto", "password1": "Toto1234",
|
||||
"password2": "Toto1234", "role": "SimpleUsers", "quota_act": True,
|
||||
"is_active": True, "email": "téster@test.com", "stepid": "step2"
|
||||
}
|
||||
self.ajax_post(reverse("admin:account_add"), values)
|
||||
|
||||
def _set_quota(self, email, value, expected_status=200):
|
||||
@@ -478,11 +478,11 @@ class LDAPAccountTestCase(test_ldap.LDAPTestCaseMixin, ModoTestCase):
|
||||
class PermissionsTestCase(ModoTestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Create test data."""
|
||||
super(PermissionsTestCase, cls).setUpTestData()
|
||||
parameters = {}
|
||||
for name, tpl in limits_utils.get_user_limit_templates():
|
||||
for name, _definition in limits_utils.get_user_limit_templates():
|
||||
parameters["deflt_user_{0}_limit".format(name)] = 2
|
||||
cls.localconfig.parameters.set_values(parameters, app="limits")
|
||||
cls.localconfig.save()
|
||||
@@ -604,12 +604,12 @@ class PermissionsTestCase(ModoTestCase):
|
||||
for the associated domain, this domain admin must not be able
|
||||
to access the super admin.
|
||||
"""
|
||||
values = dict(
|
||||
username="superadmin2@test.com", first_name="Super",
|
||||
last_name="Admin", password1="Toto1234", password2="Toto1234",
|
||||
role="SuperAdmins", is_active=True,
|
||||
email="superadmin2@test.com", stepid="step2"
|
||||
)
|
||||
values = {
|
||||
"username": "superadmin2@test.com", "first_name": "Super",
|
||||
"last_name": "Admin", "password1": "Toto1234",
|
||||
"password2": "Toto1234", "role": "SuperAdmins", "is_active": True,
|
||||
"email": "superadmin2@test.com", "stepid": "step2"
|
||||
}
|
||||
self.ajax_post(
|
||||
reverse("admin:account_add"),
|
||||
values
|
||||
@@ -624,22 +624,22 @@ class PermissionsTestCase(ModoTestCase):
|
||||
def test_domainadmin_dlist_local_domain_not_owned(self):
|
||||
"""Check if a domain admin can use a local mailbox he can't
|
||||
access as a recipient in a distribution list"""
|
||||
values = dict(
|
||||
address="all@test.com",
|
||||
recipients="user@test.com",
|
||||
recipients_1="user@test2.com",
|
||||
enabled=True
|
||||
)
|
||||
values = {
|
||||
"address": "all@test.com",
|
||||
"recipients": "user@test.com",
|
||||
"recipients_1": "user@test2.com",
|
||||
"enabled": True
|
||||
}
|
||||
self.ajax_post(reverse("admin:alias_add"), values)
|
||||
|
||||
def test_domainadmin_master_user(self):
|
||||
"""Check domain administrator is not allowed to access this feature."""
|
||||
values = dict(
|
||||
username="user10@test.com", first_name="Test",
|
||||
last_name="Test", password1="Toto1234", password2="Toto1234",
|
||||
role="SimpleUsers", is_active=True, master_user=True,
|
||||
email="user10@test.com", stepid="step2"
|
||||
)
|
||||
values = {
|
||||
"username": "user10@test.com", "first_name": "Test",
|
||||
"last_name": "Test", "password1": "Toto1234",
|
||||
"password2": "Toto1234", "role": "SimpleUsers", "is_active": True,
|
||||
"master_user": True, "email": "user10@test.com", "stepid": "step2"
|
||||
}
|
||||
self.ajax_post(
|
||||
reverse("admin:account_add"),
|
||||
values, status=400
|
||||
|
||||
@@ -18,19 +18,19 @@ from ..models import Alias, AliasRecipient, Domain
|
||||
class AliasTestCase(ModoTestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Create test data."""
|
||||
super(AliasTestCase, cls).setUpTestData()
|
||||
factories.populate_database()
|
||||
|
||||
def test_alias(self):
|
||||
user = User.objects.get(username="user@test.com")
|
||||
values = dict(
|
||||
username="user@test.com", role=user.role,
|
||||
is_active=user.is_active, email="user@test.com",
|
||||
aliases="toto@test.com", aliases_1="titi@test.com",
|
||||
language="en"
|
||||
)
|
||||
values = {
|
||||
"username": "user@test.com", "role": user.role,
|
||||
"is_active": user.is_active, "email": "user@test.com",
|
||||
"aliases": "toto@test.com", "aliases_1": "titi@test.com",
|
||||
"language": "en"
|
||||
}
|
||||
self.ajax_post(
|
||||
reverse("admin:account_change", args=[user.id]),
|
||||
values
|
||||
@@ -68,11 +68,11 @@ class AliasTestCase(ModoTestCase):
|
||||
def test_upper_case_alias(self):
|
||||
"""Try to create an upper case alias."""
|
||||
user = User.objects.get(username="user@test.com")
|
||||
values = dict(
|
||||
username="user@test.com", role=user.role,
|
||||
is_active=user.is_active, email="user@test.com",
|
||||
aliases="Toto@test.com", language="en"
|
||||
)
|
||||
values = {
|
||||
"username": "user@test.com", "role": user.role,
|
||||
"is_active": user.is_active, "email": "user@test.com",
|
||||
"aliases": "Toto@test.com", "language": "en"
|
||||
}
|
||||
self.ajax_post(
|
||||
reverse("admin:account_change", args=[user.id]),
|
||||
values
|
||||
@@ -98,11 +98,11 @@ class AliasTestCase(ModoTestCase):
|
||||
def test_append_alias_with_tag(self):
|
||||
"""Try to create a alias with tag in recipient address"""
|
||||
user = User.objects.get(username="user@test.com")
|
||||
values = dict(
|
||||
username="user@test.com", role=user.role,
|
||||
is_active=user.is_active, email="user@test.com",
|
||||
language="en"
|
||||
)
|
||||
values = {
|
||||
"username": "user@test.com", "role": user.role,
|
||||
"is_active": user.is_active, "email": "user@test.com",
|
||||
"language": "en"
|
||||
}
|
||||
self.ajax_post(
|
||||
reverse("admin:account_change", args=[user.id]),
|
||||
values
|
||||
@@ -122,11 +122,13 @@ class AliasTestCase(ModoTestCase):
|
||||
|
||||
def test_utf8_alias(self):
|
||||
"""Test alias with non-ASCII characters."""
|
||||
values = dict(address="testé@test.com",
|
||||
recipients="user@test.com",
|
||||
recipients_1="admin@test.com",
|
||||
recipients_2="ext@titi.com",
|
||||
enabled=True)
|
||||
values = {
|
||||
"address": "testé@test.com",
|
||||
"recipients": "user@test.com",
|
||||
"recipients_1": "admin@test.com",
|
||||
"recipients_2": "ext@titi.com",
|
||||
"enabled": True
|
||||
}
|
||||
self.ajax_post(
|
||||
reverse("admin:alias_add"), values
|
||||
)
|
||||
@@ -170,7 +172,7 @@ class AliasTestCase(ModoTestCase):
|
||||
Alias.DoesNotExist, Alias.objects.get, address="all@test.com")
|
||||
|
||||
def test_forward(self):
|
||||
values = dict(address="forward2@test.com", recipients="rcpt@dest.com")
|
||||
values = {"address": "forward2@test.com", "recipients": "rcpt@dest.com"}
|
||||
self.ajax_post(
|
||||
reverse("admin:alias_add"), values
|
||||
)
|
||||
@@ -193,7 +195,7 @@ class AliasTestCase(ModoTestCase):
|
||||
Alias.DoesNotExist, Alias.objects.get, address="forward2@test.com")
|
||||
|
||||
def test_forward_and_local_copies(self):
|
||||
values = dict(address="user@test.com", recipients="rcpt@dest.com")
|
||||
values = {"address": "user@test.com", "recipients": "rcpt@dest.com"}
|
||||
self.ajax_post(
|
||||
reverse("admin:alias_add"), values
|
||||
)
|
||||
@@ -244,21 +246,23 @@ class AliasTestCase(ModoTestCase):
|
||||
changed.
|
||||
|
||||
"""
|
||||
values = dict(address="list@test.com",
|
||||
recipients="user@test.com",
|
||||
recipients_1="admin@test.com",
|
||||
enabled=True)
|
||||
values = {
|
||||
"address": "list@test.com",
|
||||
"recipients": "user@test.com",
|
||||
"recipients_1": "admin@test.com",
|
||||
"enabled": True
|
||||
}
|
||||
self.ajax_post(
|
||||
reverse("admin:alias_add"), values
|
||||
)
|
||||
|
||||
user = User.objects.get(username="user@test.com")
|
||||
values = dict(
|
||||
username=user.username, first_name="Tester", last_name="Toto",
|
||||
password1="Toto1234", password2="Toto1234", role="SimpleUsers",
|
||||
quota_act=True, is_active=True, email=user.email,
|
||||
language="en"
|
||||
)
|
||||
values = {
|
||||
"username": user.username, "first_name": "Tester",
|
||||
"last_name": "Toto", "password1": "Toto1234",
|
||||
"password2": "Toto1234", "role": "SimpleUsers", "quota_act": True,
|
||||
"is_active": True, "email": user.email, "language": "en"
|
||||
}
|
||||
self.ajax_post(reverse("admin:account_change", args=[user.id]), values)
|
||||
|
||||
self.assertEqual(
|
||||
@@ -279,12 +283,12 @@ class AliasTestCase(ModoTestCase):
|
||||
self.client.force_login(admin)
|
||||
|
||||
user = User.objects.get(username="user@test.com")
|
||||
values = dict(
|
||||
username="user@test.com", role=user.role,
|
||||
is_active=user.is_active, email="user@test.com",
|
||||
aliases="toto@test.com", aliases_1="titi@test2.com",
|
||||
language="en"
|
||||
)
|
||||
values = {
|
||||
"username": "user@test.com", "role": user.role,
|
||||
"is_active": user.is_active, "email": "user@test.com",
|
||||
"aliases": "toto@test.com", "aliases_1": "titi@test2.com",
|
||||
"language": "en"
|
||||
}
|
||||
response = self.ajax_post(
|
||||
reverse("admin:account_change", args=[user.id]),
|
||||
values, 400
|
||||
|
||||
@@ -26,7 +26,7 @@ class DomainAPITestCase(ModoAPITestCase):
|
||||
"""Check API."""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls): # noqa: N802
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Create test data."""
|
||||
super(DomainAPITestCase, cls).setUpTestData()
|
||||
factories.populate_database()
|
||||
@@ -137,7 +137,7 @@ class DomainAliasAPITestCase(ModoAPITestCase):
|
||||
"""Check DomainAlias API."""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls): # noqa: N802
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Create test data."""
|
||||
super(DomainAliasAPITestCase, cls).setUpTestData()
|
||||
factories.populate_database()
|
||||
@@ -231,7 +231,7 @@ class AccountAPITestCase(ModoAPITestCase):
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls): # noqa: N802
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Create test data."""
|
||||
super(AccountAPITestCase, cls).setUpTestData()
|
||||
factories.populate_database()
|
||||
@@ -563,7 +563,7 @@ class AliasAPITestCase(ModoAPITestCase):
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls): # noqa: N802
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Create test data."""
|
||||
super(AliasAPITestCase, cls).setUpTestData()
|
||||
cls.localconfig.parameters.set_value(
|
||||
@@ -686,7 +686,7 @@ class SenderAddressAPITestCase(ModoAPITestCase):
|
||||
"""Check SenderAddress API."""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls): # noqa: N802
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Create test data."""
|
||||
super(SenderAddressAPITestCase, cls).setUpTestData()
|
||||
cls.localconfig.parameters.set_value(
|
||||
|
||||
@@ -29,7 +29,7 @@ class DomainTestCase(ModoTestCase):
|
||||
"""Test case for Domain."""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls): # noqa: N802
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Create test data."""
|
||||
super(DomainTestCase, cls).setUpTestData()
|
||||
factories.populate_database()
|
||||
@@ -361,7 +361,7 @@ class DKIMTestCase(ModoTestCase):
|
||||
"""Test case for DKIM."""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls): # noqa: N802
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Create test data."""
|
||||
super(DKIMTestCase, cls).setUpTestData()
|
||||
factories.populate_database()
|
||||
|
||||
@@ -12,7 +12,7 @@ from ..models import Alias, Domain, DomainAlias
|
||||
class DomainAliasTestCase(ModoTestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Create test data."""
|
||||
super(DomainAliasTestCase, cls).setUpTestData()
|
||||
factories.populate_database()
|
||||
|
||||
@@ -15,7 +15,7 @@ class ExportTestCase(ModoTestCase):
|
||||
"""Test case for export operations."""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Create test data."""
|
||||
super(ExportTestCase, cls).setUpTestData()
|
||||
factories.populate_database()
|
||||
@@ -38,7 +38,7 @@ class ExportTestCase(ModoTestCase):
|
||||
{"filename": "test.csv"}
|
||||
)
|
||||
|
||||
def assertListEqual(self, list1, list2):
|
||||
def assertListEqual(self, list1, list2): # NOQA:N802
|
||||
list1 = force_text(list1).split("\r\n")
|
||||
list2 = force_text(list2).split("\r\n")
|
||||
self.assertEqual(len(list1), len(list2))
|
||||
|
||||
@@ -19,7 +19,7 @@ from ..models import Alias, Domain, DomainAlias
|
||||
class ImportTestCase(ModoTestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls): # noqa:N802
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Create test data."""
|
||||
super(ImportTestCase, cls).setUpTestData()
|
||||
cls.localconfig.parameters.set_value(
|
||||
|
||||
@@ -22,7 +22,7 @@ class MailboxOperationTestCase(ModoTestCase):
|
||||
"""Test management command."""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Create test data."""
|
||||
super(MailboxOperationTestCase, cls).setUpTestData()
|
||||
factories.populate_database()
|
||||
|
||||
@@ -24,7 +24,7 @@ class MXTestCase(ModoTestCase):
|
||||
"""TestCase for DNSBL related features."""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls): # noqa:N802
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Create some data."""
|
||||
super(MXTestCase, cls).setUpTestData()
|
||||
cls.domain = factories.DomainFactory(name="modoboa.org")
|
||||
@@ -138,7 +138,7 @@ class DNSBLTestCase(ModoTestCase):
|
||||
"""TestCase for DNSBL related features."""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls): # noqa:N802
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Create some data."""
|
||||
super(DNSBLTestCase, cls).setUpTestData()
|
||||
cls.domain = factories.DomainFactory(name="modoboa.org")
|
||||
|
||||
@@ -10,18 +10,18 @@ from .. import factories
|
||||
class PasswordSchemesTestCase(ModoTestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Create test data."""
|
||||
super(PasswordSchemesTestCase, cls).setUpTestData()
|
||||
factories.populate_database()
|
||||
|
||||
def _create_account(self):
|
||||
values = dict(
|
||||
username="tester@test.com", first_name="Tester", last_name="Toto",
|
||||
password1="Toto1234", password2="Toto1234", role="SimpleUsers",
|
||||
quota_act=True,
|
||||
is_active=True, email="tester@test.com", stepid="step2"
|
||||
)
|
||||
values = {
|
||||
"username": "tester@test.com", "first_name": "Tester",
|
||||
"last_name": "Toto", "password1": "Toto1234",
|
||||
"password2": "Toto1234", "role": "SimpleUsers", "quota_act": True,
|
||||
"is_active": True, "email": "tester@test.com", "stepid": "step2"
|
||||
}
|
||||
self.ajax_post(
|
||||
reverse("admin:account_add"),
|
||||
values
|
||||
|
||||
@@ -13,7 +13,7 @@ class RepairTestCase(ModoTestCase):
|
||||
"""TestCase for repair command."""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Create some data."""
|
||||
super(RepairTestCase, cls).setUpTestData()
|
||||
factories.populate_database()
|
||||
|
||||
@@ -45,10 +45,10 @@ def _domains(request):
|
||||
if extra_filters:
|
||||
extra_filters = reduce(
|
||||
lambda a, b: a + b, [result[1] for result in extra_filters])
|
||||
filters = dict(
|
||||
(flt, request.GET.get(flt, None))
|
||||
filters = {
|
||||
flt: request.GET.get(flt, None)
|
||||
for flt in ["domfilter", "searchquery"] + extra_filters
|
||||
)
|
||||
}
|
||||
request.session["domains_filters"] = filters
|
||||
domainlist = get_domains(request.user, **filters)
|
||||
if sort_order == "name":
|
||||
@@ -116,8 +116,6 @@ def domains_list(request):
|
||||
@login_required
|
||||
@permission_required("admin.add_domain")
|
||||
def list_quotas(request):
|
||||
from modoboa.lib.db_utils import db_type
|
||||
|
||||
sort_order, sort_dir = get_sort_order(request.GET, "name")
|
||||
domains = Domain.objects.get_for_admin(request.user)
|
||||
domains = domains.exclude(quota=0)
|
||||
@@ -162,7 +160,7 @@ def editdomain(request, dom_id):
|
||||
if not request.user.can_access(domain):
|
||||
raise PermDeniedException
|
||||
|
||||
instances = dict(general=domain)
|
||||
instances = {"general": domain}
|
||||
results = signals.get_domain_form_instances.send(
|
||||
sender="editdomain", user=request.user, domain=domain)
|
||||
for result in results:
|
||||
@@ -215,7 +213,7 @@ class DomainDetailView(
|
||||
"enable_mx_checks": parameters.get_value("enable_mx_checks"),
|
||||
"enable_dnsbl_checks": parameters.get_value("enable_dnsbl_checks"),
|
||||
})
|
||||
for receiver, widgets in result:
|
||||
for _receiver, widgets in result:
|
||||
for widget in widgets:
|
||||
context["templates"][widget["column"]].append(
|
||||
widget["template"])
|
||||
|
||||
@@ -30,8 +30,10 @@ from ..models import Domain, Mailbox
|
||||
u.has_perm("admin.add_alias")
|
||||
)
|
||||
def _identities(request):
|
||||
filters = dict((fname, request.GET.get(fname, None))
|
||||
for fname in ["searchquery", "idtfilter", "grpfilter"])
|
||||
filters = {
|
||||
fname: request.GET.get(fname, None)
|
||||
for fname in ["searchquery", "idtfilter", "grpfilter"]
|
||||
}
|
||||
request.session["identities_filters"] = filters
|
||||
idents_list = get_identities(request.user, **filters)
|
||||
sort_order, sort_dir = get_sort_order(request.GET, "identity",
|
||||
@@ -173,8 +175,9 @@ def editaccount(request, pk):
|
||||
raise PermDeniedException
|
||||
mb = account.mailbox if hasattr(account, "mailbox") else None
|
||||
|
||||
instances = dict(
|
||||
general=account, profile=account, mail=mb, perms=account)
|
||||
instances = {
|
||||
"general": account, "profile": account, "mail": mb, "perms": account
|
||||
}
|
||||
results = signals.get_account_form_instances.send(
|
||||
sender="editaccount", user=request.user, account=account)
|
||||
for result in results:
|
||||
@@ -232,7 +235,7 @@ class AccountDetailView(
|
||||
result = signals.extra_account_dashboard_widgets.send(
|
||||
self.__class__, user=self.request.user, account=self.object)
|
||||
context["templates"] = {"left": [], "right": []}
|
||||
for receiver, widgets in result:
|
||||
for _receiver, widgets in result:
|
||||
for widget in widgets:
|
||||
context["templates"][widget["column"]].append(
|
||||
widget["template"])
|
||||
|
||||
@@ -8,7 +8,6 @@ from django.contrib.auth import password_validation
|
||||
from django.utils.translation import ugettext as _, ugettext_lazy
|
||||
|
||||
from modoboa.lib import fields as lib_fields
|
||||
from modoboa.lib.cryptutils import random_key
|
||||
from modoboa.lib.form_utils import (
|
||||
HorizontalRadioSelect, SeparatorField, YesNoField
|
||||
)
|
||||
@@ -341,7 +340,7 @@ class GeneralParametersForm(param_forms.AdminParametersForm):
|
||||
def clean_ldap_user_dn_template(self):
|
||||
tpl = self.cleaned_data["ldap_user_dn_template"]
|
||||
try:
|
||||
test = tpl % {"user": "toto"}
|
||||
tpl % {"user": "toto"}
|
||||
except (KeyError, ValueError):
|
||||
raise forms.ValidationError(_("Invalid syntax"))
|
||||
return tpl
|
||||
|
||||
@@ -30,7 +30,7 @@ class CoreConfig(AppConfig):
|
||||
load_core_settings()
|
||||
|
||||
# Import these to force registration of checks and signals
|
||||
from . import checks # noqa:F401
|
||||
from . import checks # NOQA:F401
|
||||
from . import handlers
|
||||
|
||||
signals.post_migrate.connect(handlers.create_local_config, sender=self)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Import these to force registration of checks
|
||||
from . import settings_checks # noqa:F401
|
||||
from . import settings_checks # NOQA:F401
|
||||
|
||||
@@ -17,7 +17,7 @@ class Command(object):
|
||||
A valid administrative command must inherit from this class.
|
||||
"""
|
||||
|
||||
help = "No help available."
|
||||
help = "No help available." # NOQA:A003
|
||||
|
||||
def __init__(self, commands, verbose=False):
|
||||
self._commands = commands
|
||||
|
||||
@@ -18,6 +18,7 @@ import django
|
||||
from django.core import management
|
||||
from django.template import Context, Template
|
||||
from django.utils.encoding import smart_str
|
||||
from django.utils.six.moves import input
|
||||
|
||||
from modoboa.core.commands import Command
|
||||
from modoboa.lib.api_client import ModoAPIClient
|
||||
@@ -29,10 +30,6 @@ except ImportError:
|
||||
sys.exit(2)
|
||||
|
||||
|
||||
|
||||
if sys.version_info < (3, 0, 0):
|
||||
input = raw_input
|
||||
|
||||
DBCONN_TPL = """
|
||||
'{{ conn_name }}': {
|
||||
'ENGINE': '{{ ENGINE }}',
|
||||
@@ -53,7 +50,7 @@ class DeployCommand(Command):
|
||||
|
||||
"""The ``deploy`` command."""
|
||||
|
||||
help = (
|
||||
help = ( # NOQA:A003
|
||||
"Create a fresh django project (calling startproject)"
|
||||
" and apply Modoboa specific settings."
|
||||
)
|
||||
|
||||
@@ -9,7 +9,7 @@ from . import Command
|
||||
|
||||
class HelpCommand(Command):
|
||||
|
||||
help = "Display the help message associated to a specific command"
|
||||
help = "Display the help message associated to a specific command" # NOQA:A003
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(HelpCommand, self).__init__(*args, **kwargs)
|
||||
|
||||
@@ -60,7 +60,7 @@ class ExtensionsPool(object):
|
||||
:param ext: a class inheriting from ``Extension``
|
||||
:param show: list the extension or not
|
||||
"""
|
||||
self.extensions[ext.name] = dict(cls=ext, show=show)
|
||||
self.extensions[ext.name] = {"cls": ext, "show": show}
|
||||
|
||||
def get_extension(self, name):
|
||||
"""Retrieve the current instance of an extension."""
|
||||
|
||||
@@ -15,7 +15,7 @@ from ... import models
|
||||
class Command(BaseCommand):
|
||||
"""Management command to clean inactive accounts."""
|
||||
|
||||
help = "Inactive accounts cleanup"
|
||||
help = "Inactive accounts cleanup" # NOQA:A003
|
||||
|
||||
def add_arguments(self, parser):
|
||||
"""Add extra arguments to command line."""
|
||||
|
||||
@@ -15,7 +15,7 @@ from modoboa.parameters import tools as param_tools
|
||||
class Command(BaseCommand):
|
||||
"""Command class."""
|
||||
|
||||
help = "Log table cleanup"
|
||||
help = "Log table cleanup" # NOQA:A003
|
||||
|
||||
def add_arguments(self, parser):
|
||||
"""Add extra arguments to command line."""
|
||||
@@ -33,9 +33,9 @@ class Command(BaseCommand):
|
||||
|
||||
def handle(self, *args, **options):
|
||||
if options["debug"]:
|
||||
l = logging.getLogger("django.db.backends")
|
||||
l.setLevel(logging.DEBUG)
|
||||
l.addHandler(logging.StreamHandler())
|
||||
log = logging.getLogger("django.db.backends")
|
||||
log.setLevel(logging.DEBUG)
|
||||
log.addHandler(logging.StreamHandler())
|
||||
self.verbose = options["verbose"]
|
||||
|
||||
log_maximum_age = param_tools.get_global_parameter("log_maximum_age")
|
||||
|
||||
@@ -13,7 +13,7 @@ from ... import models
|
||||
class Command(BaseCommand):
|
||||
"""Command class."""
|
||||
|
||||
help = "Communicate with Modoboa public API."
|
||||
help = "Communicate with Modoboa public API." # NOQA:A003
|
||||
|
||||
def handle(self, *args, **options):
|
||||
"""Command entry point."""
|
||||
|
||||
@@ -25,7 +25,7 @@ MAP_FILE_TEMPLATE = """# This file was generated on {{ date }} by running:
|
||||
class Command(BaseCommand):
|
||||
"""Command class."""
|
||||
|
||||
help = "Generate/update postfix map files."
|
||||
help = "Generate/update postfix map files." # NOQA:A003
|
||||
|
||||
def add_arguments(self, parser):
|
||||
"""Add extra arguments."""
|
||||
|
||||
@@ -12,7 +12,6 @@ from functools import reduce
|
||||
from django.contrib.auth.models import Group
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from modoboa.lib.cryptutils import random_key
|
||||
from modoboa.lib.permissions import add_permissions_to_group
|
||||
from ... import constants, extensions, models, signals
|
||||
|
||||
@@ -20,7 +19,7 @@ from ... import constants, extensions, models, signals
|
||||
class Command(BaseCommand):
|
||||
"""Command definition."""
|
||||
|
||||
help = "Load Modoboa initial data"
|
||||
help = "Load Modoboa initial data" # NOQA:A003
|
||||
|
||||
def add_arguments(self, parser):
|
||||
"""Add extra arguments to command."""
|
||||
|
||||
@@ -15,7 +15,7 @@ class Command(BaseCommand):
|
||||
|
||||
"""Management command to set the default site."""
|
||||
|
||||
help = "Set default site (see django.contrib.sites)"
|
||||
help = "Set default site (see django.contrib.sites)" # NOQA:A003
|
||||
|
||||
def add_arguments(self, parser):
|
||||
"""Define command arguments."""
|
||||
|
||||
@@ -4,10 +4,10 @@ Password hashers for Modoboa.
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from modoboa.core.password_hashers.advanced import (
|
||||
from modoboa.core.password_hashers.advanced import ( # NOQA:F401
|
||||
BLFCRYPTHasher, MD5CRYPTHasher, SHA256CRYPTHasher, SHA512CRYPTHasher
|
||||
)
|
||||
from modoboa.core.password_hashers.base import (
|
||||
from modoboa.core.password_hashers.base import ( # NOQA:F401
|
||||
CRYPTHasher, MD5Hasher, PLAINHasher, SHA256Hasher
|
||||
)
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ class ComplexityValidator(object):
|
||||
special_characters = "~!@#$%^&*()_+{}\":;,'[]"
|
||||
condition = (
|
||||
self.digits > 0 and
|
||||
sum([1 for char in password if char.isdigit()]) < self.digits)
|
||||
sum(1 for char in password if char.isdigit()) < self.digits)
|
||||
if condition:
|
||||
raise ValidationError(
|
||||
ungettext(
|
||||
@@ -29,7 +29,7 @@ class ComplexityValidator(object):
|
||||
).format(self.digits))
|
||||
condition = (
|
||||
self.lower > 0 and
|
||||
sum([1 for char in password if char.islower()]) < self.lower)
|
||||
sum(1 for char in password if char.islower()) < self.lower)
|
||||
if condition:
|
||||
raise ValidationError(
|
||||
ungettext(
|
||||
@@ -40,7 +40,7 @@ class ComplexityValidator(object):
|
||||
.format(self.lower))
|
||||
condition = (
|
||||
self.upper > 0 and
|
||||
sum([1 for char in password if char.isupper()]) < self.upper)
|
||||
sum(1 for char in password if char.isupper()) < self.upper)
|
||||
if condition:
|
||||
raise ValidationError(
|
||||
ungettext(
|
||||
@@ -51,7 +51,7 @@ class ComplexityValidator(object):
|
||||
.format(self.upper))
|
||||
condition = (
|
||||
self.specials > 0 and
|
||||
sum([1 for char in password if char in special_characters]) <
|
||||
sum(1 for char in password if char in special_characters) <
|
||||
self.specials)
|
||||
if condition:
|
||||
raise ValidationError(
|
||||
|
||||
@@ -21,7 +21,7 @@ class AuthenticationTestCase(ModoTestCase):
|
||||
"""Validate authentication scenarios."""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Create test data."""
|
||||
super(AuthenticationTestCase, cls).setUpTestData()
|
||||
cls.account = factories.UserFactory(
|
||||
@@ -67,7 +67,7 @@ class PasswordResetTestCase(ModoTestCase):
|
||||
"""Test password reset service."""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Create test data."""
|
||||
super(PasswordResetTestCase, cls).setUpTestData()
|
||||
cls.account_ok = factories.UserFactory(
|
||||
|
||||
@@ -20,7 +20,7 @@ class AuthenticationTestCase(ModoTestCase):
|
||||
"""Validate authentication scenarios."""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Create test data."""
|
||||
super(AuthenticationTestCase, cls).setUpTestData()
|
||||
cls.account = factories.UserFactory(
|
||||
@@ -101,7 +101,7 @@ class ProfileTestCase(ModoTestCase):
|
||||
"""Profile related tests."""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Create test data."""
|
||||
super(ProfileTestCase, cls).setUpTestData()
|
||||
cls.account = factories.UserFactory(
|
||||
@@ -160,7 +160,7 @@ class APIAccessFormTestCase(ModoTestCase):
|
||||
"""Check form access."""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Create test data."""
|
||||
super(APIAccessFormTestCase, cls).setUpTestData()
|
||||
cls.account = factories.UserFactory(
|
||||
|
||||
@@ -130,7 +130,7 @@ class ProfileTestCase(LDAPTestCaseMixin, ModoTestCase):
|
||||
"""Profile related tests."""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Create test data."""
|
||||
super(ProfileTestCase, cls).setUpTestData()
|
||||
cls.account = factories.UserFactory(
|
||||
|
||||
@@ -89,7 +89,7 @@ class DashboardTestCase(ModoTestCase):
|
||||
"""Dashboard tests."""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Create some data."""
|
||||
super(DashboardTestCase, cls).setUpTestData()
|
||||
cls.dadmin = factories.UserFactory(
|
||||
|
||||
@@ -72,7 +72,7 @@ class DashboardView(auth_mixins.AccessMixin, generic.TemplateView):
|
||||
# Extra widgets
|
||||
result = signals.extra_admin_dashboard_widgets.send(
|
||||
sender=self.__class__, user=self.request.user)
|
||||
for receiver, widgets in result:
|
||||
for _receiver, widgets in result:
|
||||
for widget in widgets:
|
||||
context["widgets"][widget["column"]].append(
|
||||
widget["template"])
|
||||
|
||||
+11
-11
@@ -11,27 +11,27 @@ class ConnectionsManager(type):
|
||||
This class is specialized in connection management.
|
||||
"""
|
||||
|
||||
def __init__(cls, name, bases, ctx):
|
||||
super(ConnectionsManager, cls).__init__(name, bases, ctx)
|
||||
cls.instances = {}
|
||||
def __init__(self, name, bases, ctx):
|
||||
super(ConnectionsManager, self).__init__(name, bases, ctx)
|
||||
self.instances = {}
|
||||
|
||||
def __call__(cls, **kwargs):
|
||||
def __call__(self, **kwargs):
|
||||
key = None
|
||||
if "user" in kwargs:
|
||||
key = kwargs["user"]
|
||||
else:
|
||||
return None
|
||||
if key not in cls.instances:
|
||||
cls.instances[key] = None
|
||||
if key not in self.instances:
|
||||
self.instances[key] = None
|
||||
if "password" in kwargs:
|
||||
kwargs["password"] = decrypt(kwargs["password"])
|
||||
|
||||
if cls.instances[key] is None:
|
||||
cls.instances[key] = \
|
||||
super(ConnectionsManager, cls).__call__(**kwargs)
|
||||
if self.instances[key] is None:
|
||||
self.instances[key] = \
|
||||
super(ConnectionsManager, self).__call__(**kwargs)
|
||||
else:
|
||||
cls.instances[key].refresh(key, kwargs["password"])
|
||||
return cls.instances[key]
|
||||
self.instances[key].refresh(key, kwargs["password"])
|
||||
return self.instances[key]
|
||||
|
||||
|
||||
class ConnectionError(Exception):
|
||||
|
||||
@@ -387,7 +387,7 @@ def set_email_headers(msg, subject, sender, rcpt):
|
||||
msg["Date"] = formatdate(time.time(), True)
|
||||
|
||||
|
||||
def __sendmail(sender, rcpt, msgstring, server="localhost", port=25):
|
||||
def _sendmail(sender, rcpt, msgstring, server="localhost", port=25):
|
||||
"""Message sending
|
||||
|
||||
Return a tuple (True, None) on success, (False, error message)
|
||||
@@ -426,7 +426,7 @@ def sendmail_simple(
|
||||
"""
|
||||
msg = MIMEText(content, _charset="utf-8")
|
||||
set_email_headers(msg, subject, sender, rcpt)
|
||||
return __sendmail(sender, rcpt, msg.as_string(), **kwargs)
|
||||
return _sendmail(sender, rcpt, msg.as_string(), **kwargs)
|
||||
|
||||
|
||||
def sendmail_fromfile(sender, rcpt, fname):
|
||||
@@ -452,4 +452,4 @@ To: %s
|
||||
content += fp.read()
|
||||
fp.close()
|
||||
|
||||
return __sendmail(sender, rcpt, content)
|
||||
return _sendmail(sender, rcpt, content)
|
||||
|
||||
+19
-19
@@ -65,7 +65,7 @@ def modified_utf7(s):
|
||||
return s_utf7[1:-1].replace(b"/", b",")
|
||||
|
||||
|
||||
def doB64(_in, r):
|
||||
def doB64(_in, r): # NOQA:N802
|
||||
if _in:
|
||||
r.extend([b"&", modified_utf7("".join(_in)), b"-"])
|
||||
del _in[:]
|
||||
@@ -137,32 +137,32 @@ codecs.register(imap4_utf_7)
|
||||
|
||||
# testing methods
|
||||
|
||||
def imapUTF7Encode(ust):
|
||||
def imapUTF7Encode(ust): # NOQA:N802
|
||||
"Returns imap utf-7 encoded version of string"
|
||||
return ust.encode("imap4-utf-7")
|
||||
|
||||
|
||||
def imapUTF7EncodeSequence(seq):
|
||||
def imapUTF7EncodeSequence(seq): # NOQA:N802
|
||||
"Returns imap utf-7 encoded version of strings in sequence"
|
||||
return [imapUTF7Encode(itm) for itm in seq]
|
||||
|
||||
|
||||
def imapUTF7Decode(st):
|
||||
def imapUTF7Decode(st): # NOQA:N802
|
||||
"Returns utf7 encoded version of imap utf-7 string"
|
||||
return st.decode("imap4-utf-7")
|
||||
|
||||
|
||||
def imapUTF7DecodeSequence(seq):
|
||||
def imapUTF7DecodeSequence(seq): # NOQA:N802
|
||||
"Returns utf7 encoded version of imap utf-7 strings in sequence"
|
||||
return [imapUTF7Decode(itm) for itm in seq]
|
||||
|
||||
|
||||
def utf8Decode(st):
|
||||
def utf8Decode(st): # NOQA:N802
|
||||
"Returns utf7 encoded version of imap utf-7 string"
|
||||
return st.decode("utf-8")
|
||||
|
||||
|
||||
def utf7SequenceToUTF8(seq):
|
||||
def utf7SequenceToUTF8(seq): # NOQA:N802
|
||||
"Returns utf7 encoded version of imap utf-7 strings in sequence"
|
||||
return [itm.decode("imap4-utf-7").encode("utf-8") for itm in seq]
|
||||
|
||||
@@ -171,33 +171,33 @@ __all__ = ["imapUTF7Encode", "imapUTF7Decode", ]
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
# print u'bøx'.encode('imap4-utf-7')
|
||||
# print u'bøx'.encode('imap4-utf-7')
|
||||
# print 'expected b&APg-x'
|
||||
|
||||
# print u'båx'.encode('imap4-utf-7')
|
||||
# print u'båx'.encode('imap4-utf-7')
|
||||
# print 'expected b&AOU-x'
|
||||
|
||||
print("#######")
|
||||
print("bøx")
|
||||
e = imapUTF7Encode(u'bøx')
|
||||
print("bøx")
|
||||
e = imapUTF7Encode(u'bøx')
|
||||
print(e)
|
||||
print(imapUTF7Decode(e).encode("latin-1"))
|
||||
|
||||
print("#######")
|
||||
print("båx")
|
||||
e = imapUTF7Encode(u'båx')
|
||||
print("båx")
|
||||
e = imapUTF7Encode(u'båx')
|
||||
print(e)
|
||||
print(imapUTF7Decode(e).encode("latin-1"))
|
||||
|
||||
print("#######")
|
||||
print("~/bågø")
|
||||
e = imapUTF7Encode(u'~/bågø')
|
||||
print("~/bågø")
|
||||
e = imapUTF7Encode(u'~/bågø')
|
||||
print(e)
|
||||
print(imapUTF7Decode(e).encode("latin-1"))
|
||||
|
||||
print("#######")
|
||||
print("Ting & Såger")
|
||||
e = imapUTF7Encode(u'Ting & Såger')
|
||||
print("Ting & Såger")
|
||||
e = imapUTF7Encode(u'Ting & Såger')
|
||||
print(e)
|
||||
print(imapUTF7Decode(e).encode("latin-1"))
|
||||
|
||||
@@ -208,8 +208,8 @@ if __name__ == "__main__":
|
||||
# print e.encode('latin-1')
|
||||
|
||||
print("#######")
|
||||
print("~/Følder/mailbåx & stuff + more")
|
||||
n = u'~/Følder/mailbåx & stuff + more'
|
||||
print("~/Følder/mailbåx & stuff + more")
|
||||
n = u'~/Følder/mailbåx & stuff + more'
|
||||
e = imapUTF7Encode(n)
|
||||
print(e)
|
||||
print(imapUTF7Decode(e).encode("latin-1"))
|
||||
|
||||
@@ -19,7 +19,7 @@ class AjaxLoginRedirect(MiddlewareMixin):
|
||||
|
||||
def process_response(self, request, response):
|
||||
if request.is_ajax():
|
||||
if type(response) == HttpResponseRedirect:
|
||||
if isinstance(response, HttpResponseRedirect):
|
||||
response.status_code = 278
|
||||
return response
|
||||
|
||||
@@ -41,7 +41,7 @@ class CommonExceptionCatcher(MiddlewareMixin):
|
||||
smart_text(exception), status=exception.http_code
|
||||
)
|
||||
return _render_error(
|
||||
request, user_context=dict(error=smart_text(exception))
|
||||
request, user_context={"error": smart_text(exception)}
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -5,11 +5,11 @@ from __future__ import unicode_literals
|
||||
class _Singleton(type):
|
||||
_instances = {}
|
||||
|
||||
def __call__(cls, *args, **kwargs):
|
||||
if cls not in cls._instances:
|
||||
cls._instances[cls] = \
|
||||
super(_Singleton, cls).__call__(*args, **kwargs)
|
||||
return cls._instances[cls]
|
||||
def __call__(self, *args, **kwargs):
|
||||
if self not in self._instances:
|
||||
self._instances[self] = \
|
||||
super(_Singleton, self).__call__(*args, **kwargs)
|
||||
return self._instances[self]
|
||||
|
||||
|
||||
class Singleton(_Singleton("SingletonMeta", (object,), {})):
|
||||
|
||||
@@ -18,7 +18,7 @@ register = template.Library()
|
||||
def render_form(form, tpl=None):
|
||||
"""Render a form."""
|
||||
if tpl is not None:
|
||||
return render_to_string(tpl, dict(form=form))
|
||||
return render_to_string(tpl, {"form": form})
|
||||
|
||||
ret = ""
|
||||
for field in form:
|
||||
@@ -44,7 +44,7 @@ def render_field(
|
||||
"""Render a field."""
|
||||
from modoboa.core.templatetags.core_tags import visirule
|
||||
|
||||
if type(field.field) is SeparatorField:
|
||||
if isinstance(field.field, SeparatorField):
|
||||
return "<h5%s>%s</h5>" % (visirule(field), smart_text(field.label))
|
||||
configure_field_classes(field)
|
||||
context = {
|
||||
@@ -75,10 +75,11 @@ def render_fields_group(form, pattern):
|
||||
group += [bfield]
|
||||
cpt += 1
|
||||
|
||||
return render_to_string("common/generic_fields_group.html", dict(
|
||||
label=label, help_text=first.help_text, group=group, haserror=haserror,
|
||||
pattern=pattern
|
||||
))
|
||||
return render_to_string(
|
||||
"common/generic_fields_group.html",
|
||||
{"label": label, "help_text": first.help_text, "group": group,
|
||||
"haserror": haserror, "pattern": pattern}
|
||||
)
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
|
||||
@@ -36,7 +36,7 @@ def alert(msg, typ):
|
||||
<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
|
||||
{{ msg }}
|
||||
</div>""")
|
||||
return t.render(Context(dict(type=typ, msg=msg)))
|
||||
return t.render(Context({"type": typ, "msg": msg}))
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
@@ -51,7 +51,7 @@ class="{{ mdclass }}{% if link.class %} {{ link.class }}{% endif %}"
|
||||
>
|
||||
{% if link.img %}<i class="{{ link.img }}"></i>{% endif %}
|
||||
{{ link.label }}</a>""")
|
||||
return t.render(Context(dict(link=linkdef, mdclass=mdclass)))
|
||||
return t.render(Context({"link": linkdef, "mdclass": mdclass}))
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
|
||||
@@ -29,7 +29,7 @@ def render_actions(actions):
|
||||
t = template.Template("""{% load lib_tags %}
|
||||
{% for a in actions %}{% render_link a %}{% endfor %}
|
||||
""")
|
||||
return t.render(template.Context(dict(actions=actions)))
|
||||
return t.render(template.Context({"actions": actions}))
|
||||
|
||||
|
||||
def getctx(status, level=1, callback=None, **kwargs):
|
||||
|
||||
@@ -24,4 +24,4 @@ class LimitsConfig(AppConfig):
|
||||
def ready(self):
|
||||
load_limits_settings()
|
||||
|
||||
from . import handlers
|
||||
from . import handlers # NOQA:F401
|
||||
|
||||
@@ -51,16 +51,16 @@ class ResourcePoolForm(forms.Form):
|
||||
|
||||
def save(self):
|
||||
owner = get_object_owner(self.account)
|
||||
for name, ltpl in utils.get_user_limit_templates():
|
||||
for name, _definition in utils.get_user_limit_templates():
|
||||
fieldname = "{}_limit".format(name)
|
||||
if fieldname not in self.cleaned_data:
|
||||
continue
|
||||
l = self.account.userobjectlimit_set.get(name=name)
|
||||
limit = self.account.userobjectlimit_set.get(name=name)
|
||||
if not owner.is_superuser:
|
||||
allocate_resources_from_user(
|
||||
l, owner, self.cleaned_data[fieldname])
|
||||
l.max_value = self.cleaned_data[fieldname]
|
||||
l.save(update_fields=["max_value"])
|
||||
limit, owner, self.cleaned_data[fieldname])
|
||||
limit.max_value = self.cleaned_data[fieldname]
|
||||
limit.save(update_fields=["max_value"])
|
||||
|
||||
|
||||
class DomainLimitsForm(forms.Form):
|
||||
@@ -93,10 +93,10 @@ class DomainLimitsForm(forms.Form):
|
||||
|
||||
def save(self, user, **kwargs):
|
||||
"""Set limits."""
|
||||
for name, ltpl in utils.get_domain_limit_templates():
|
||||
for name, _definition in utils.get_domain_limit_templates():
|
||||
fieldname = "{}_limit".format(name)
|
||||
if fieldname not in self.cleaned_data:
|
||||
continue
|
||||
l = self.domain.domainobjectlimit_set.get(name=name)
|
||||
l.max_value = self.cleaned_data[fieldname]
|
||||
l.save()
|
||||
limit = self.domain.domainobjectlimit_set.get(name=name)
|
||||
limit.max_value = self.cleaned_data[fieldname]
|
||||
limit.save()
|
||||
|
||||
@@ -62,7 +62,7 @@ def create_domain_limits(sender, instance, **kwargs):
|
||||
if not kwargs.get("created"):
|
||||
return
|
||||
global_params = dict(param_tools.get_global_parameters("limits"))
|
||||
for name, definition in utils.get_domain_limit_templates():
|
||||
for name, _definition in utils.get_domain_limit_templates():
|
||||
max_value = global_params["deflt_domain_{0}_limit".format(name)]
|
||||
models.DomainObjectLimit.objects.create(
|
||||
domain=instance, name=name, max_value=max_value)
|
||||
@@ -267,7 +267,7 @@ def display_pool_usage(sender, user, location, currentpage, **kwargs):
|
||||
return []
|
||||
return [
|
||||
render_to_string("limits/poolusage.html",
|
||||
dict(limits=limits))
|
||||
{"limits": limits})
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -19,9 +19,10 @@ class ResourcesSerializer(serializers.Serializer):
|
||||
|
||||
def to_representation(self, instance):
|
||||
"""Return limits."""
|
||||
return dict(
|
||||
return [
|
||||
(limit.name, limit.max_value)
|
||||
for limit in instance.userobjectlimit_set.all())
|
||||
for limit in instance.userobjectlimit_set.all()
|
||||
]
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
"""Update limits."""
|
||||
|
||||
@@ -21,10 +21,10 @@ class APIAdminLimitsTestCase(lib_tests.ModoAPITestCase):
|
||||
"""Check that limits are used also by the API."""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Create test data."""
|
||||
super(APIAdminLimitsTestCase, cls).setUpTestData()
|
||||
for name, tpl in utils.get_user_limit_templates():
|
||||
for name, _definition in utils.get_user_limit_templates():
|
||||
cls.localconfig.parameters.set_value(
|
||||
"deflt_user_{0}_limit".format(name), 2)
|
||||
cls.localconfig.save()
|
||||
@@ -199,12 +199,12 @@ class APIDomainLimitsTestCase(lib_tests.ModoAPITestCase):
|
||||
"""Check that limits are used also by the API."""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Create test data."""
|
||||
super(APIDomainLimitsTestCase, cls).setUpTestData()
|
||||
cls.localconfig.parameters.set_value(
|
||||
"enable_domain_limits", True)
|
||||
for name, tpl in utils.get_domain_limit_templates():
|
||||
for name, _definition in utils.get_domain_limit_templates():
|
||||
cls.localconfig.parameters.set_value(
|
||||
"deflt_domain_{0}_limit".format(name), 2)
|
||||
cls.localconfig.save()
|
||||
@@ -264,10 +264,10 @@ class ResourcesAPITestCase(lib_tests.ModoAPITestCase):
|
||||
"""Check resources API."""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Create test data."""
|
||||
super(ResourcesAPITestCase, cls).setUpTestData()
|
||||
for name, tpl in utils.get_user_limit_templates():
|
||||
for name, _definition in utils.get_user_limit_templates():
|
||||
cls.localconfig.parameters.set_value(
|
||||
"deflt_user_{0}_limit".format(name), 2)
|
||||
cls.localconfig.save()
|
||||
|
||||
@@ -17,14 +17,14 @@ class DomainLimitsTestCase(lib_tests.ModoTestCase):
|
||||
"""Per-domain limits tests."""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Create test data."""
|
||||
super(DomainLimitsTestCase, cls).setUpTestData()
|
||||
cls.localconfig.parameters.set_values({
|
||||
"enable_admin_limits": False,
|
||||
"enable_domain_limits": True
|
||||
})
|
||||
for name, tpl in utils.get_domain_limit_templates():
|
||||
for name, _definition in utils.get_domain_limit_templates():
|
||||
cls.localconfig.parameters.set_value(
|
||||
"deflt_domain_{0}_limit".format(name), 2)
|
||||
cls.localconfig.save()
|
||||
|
||||
@@ -15,7 +15,7 @@ class LimitImportTestCase(ModoTestCase):
|
||||
"""Base class to test limits."""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Create test data."""
|
||||
super(LimitImportTestCase, cls).setUpTestData()
|
||||
admin_factories.populate_database()
|
||||
@@ -132,10 +132,10 @@ alias; alias3@{domain}; True; user@{domain}
|
||||
class UserLimitImportTestCase(LimitImportTestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Create test data."""
|
||||
localconfig = core_models.LocalConfig.objects.first()
|
||||
for name, tpl in utils.get_user_limit_templates():
|
||||
for name, _definition in utils.get_user_limit_templates():
|
||||
localconfig.parameters.set_value(
|
||||
"deflt_user_{0}_limit".format(name), 2)
|
||||
localconfig.save()
|
||||
@@ -198,14 +198,14 @@ domain; domain3.com; 1000; 100; True
|
||||
class DomainLimitImportTestCase(LimitImportTestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Create test data."""
|
||||
localconfig = core_models.LocalConfig.objects.first()
|
||||
localconfig.parameters.set_values({
|
||||
"enable_domain_limits": True,
|
||||
"enable_admin_limits": False
|
||||
})
|
||||
for name, tpl in utils.get_domain_limit_templates():
|
||||
for name, _definition in utils.get_domain_limit_templates():
|
||||
localconfig.parameters.set_value(
|
||||
"deflt_domain_{0}_limit".format(name), 2)
|
||||
localconfig.save()
|
||||
|
||||
@@ -16,7 +16,7 @@ from .. import utils
|
||||
class PermissionsTestCase(lib_tests.ModoTestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Create test data."""
|
||||
super(PermissionsTestCase, cls).setUpTestData()
|
||||
populate_database()
|
||||
@@ -26,11 +26,12 @@ class PermissionsTestCase(lib_tests.ModoTestCase):
|
||||
|
||||
Expected result: no.
|
||||
"""
|
||||
values = dict(
|
||||
username="reseller@test.com", first_name="Reseller", last_name="",
|
||||
password1="Toto1234", password2="Toto1234", role="Resellers",
|
||||
is_active=True, email="reseller@test.com", stepid="step2"
|
||||
)
|
||||
values = {
|
||||
"username": "reseller@test.com", "first_name": "Reseller",
|
||||
"last_name": "", "password1": "Toto1234", "password2": "Toto1234",
|
||||
"role": "Resellers", "is_active": True,
|
||||
"email": "reseller@test.com", "stepid": "step2"
|
||||
}
|
||||
self.ajax_post(reverse("admin:account_add"), values)
|
||||
account = User.objects.get(username="reseller@test.com")
|
||||
self.client.logout()
|
||||
@@ -45,14 +46,14 @@ class PermissionsTestCase(lib_tests.ModoTestCase):
|
||||
class ResourceTestCase(lib_tests.ModoTestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Custom setUpTestData method."""
|
||||
super(ResourceTestCase, cls).setUpTestData()
|
||||
cls.localconfig.parameters.set_values({
|
||||
"enable_admin_limits": True,
|
||||
"enable_domain_limits": False
|
||||
})
|
||||
for name, tpl in utils.get_user_limit_templates():
|
||||
for name, _definition in utils.get_user_limit_templates():
|
||||
cls.localconfig.parameters.set_value(
|
||||
"deflt_user_{0}_limit".format(name), 2)
|
||||
cls.localconfig.save()
|
||||
@@ -60,21 +61,21 @@ class ResourceTestCase(lib_tests.ModoTestCase):
|
||||
|
||||
def _create_account(
|
||||
self, username, role="SimpleUsers", status=200, **kwargs):
|
||||
values = dict(
|
||||
username=username, first_name="Tester", last_name="Toto",
|
||||
password1="Toto1234", password2="Toto1234", role=role,
|
||||
quota_act=True,
|
||||
is_active=True, email=username, stepid="step2",
|
||||
)
|
||||
values = {
|
||||
"username": username, "first_name": "Tester", "last_name": "Toto",
|
||||
"password1": "Toto1234", "password2": "Toto1234", "role": role,
|
||||
"quota_act": True, "is_active": True, "email": username,
|
||||
"stepid": "step2"
|
||||
}
|
||||
values.update(kwargs)
|
||||
return self.ajax_post(
|
||||
reverse("admin:account_add"), values, status
|
||||
)
|
||||
|
||||
def _create_alias(self, email, rcpt="user@test.com", status=200):
|
||||
values = dict(
|
||||
address=email, recipients=rcpt, enabled=True
|
||||
)
|
||||
values = {
|
||||
"address": email, "recipients": rcpt, "enabled": True
|
||||
}
|
||||
return self.ajax_post(
|
||||
reverse("admin:alias_add"), values, status
|
||||
)
|
||||
@@ -118,15 +119,15 @@ class ResourceTestCase(lib_tests.ModoTestCase):
|
||||
)
|
||||
|
||||
def _check_limit(self, name, curvalue, maxvalue):
|
||||
l = self.user.userobjectlimit_set.get(name=name)
|
||||
self.assertEqual(l.current_value, curvalue)
|
||||
self.assertEqual(l.max_value, maxvalue)
|
||||
limit = self.user.userobjectlimit_set.get(name=name)
|
||||
self.assertEqual(limit.current_value, curvalue)
|
||||
self.assertEqual(limit.max_value, maxvalue)
|
||||
|
||||
|
||||
class DomainAdminTestCase(ResourceTestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Create test data."""
|
||||
super(DomainAdminTestCase, cls).setUpTestData()
|
||||
cls.user = User.objects.get(username="admin@test.com")
|
||||
@@ -173,12 +174,12 @@ class DomainAdminTestCase(ResourceTestCase):
|
||||
|
||||
def test_aliases_limit_through_account_form(self):
|
||||
user = User.objects.get(username="user@test.com")
|
||||
values = dict(
|
||||
username=user.username, role=user.role,
|
||||
is_active=user.is_active, email=user.email, quota_act=True,
|
||||
aliases="alias1@test.com", aliases_1="alias2@test.com",
|
||||
language="en"
|
||||
)
|
||||
values = {
|
||||
"username": user.username, "role": user.role,
|
||||
"is_active": user.is_active, "email": user.email, "quota_act": True,
|
||||
"aliases": "alias1@test.com", "aliases_1": "alias2@test.com",
|
||||
"language": "en"
|
||||
}
|
||||
self.ajax_post(
|
||||
reverse("admin:account_change", args=[user.id]),
|
||||
values
|
||||
@@ -190,7 +191,7 @@ class DomainAdminTestCase(ResourceTestCase):
|
||||
class ResellerTestCase(ResourceTestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Create test data."""
|
||||
super(ResellerTestCase, cls).setUpTestData()
|
||||
cls.localconfig.parameters.set_value("deflt_user_quota_limit", 1000)
|
||||
|
||||
@@ -21,10 +21,10 @@ def move_pool_resource(owner, user):
|
||||
When an account doesn't need a pool anymore, we move the
|
||||
associated resource to the pool of its owner.
|
||||
"""
|
||||
for name, ltpl in get_user_limit_templates():
|
||||
l = user.userobjectlimit_set.get(name=name)
|
||||
if l.max_value < 0:
|
||||
for name, _definition in get_user_limit_templates():
|
||||
user_limit = user.userobjectlimit_set.get(name=name)
|
||||
if user_limit.max_value < 0:
|
||||
continue
|
||||
ol = owner.userobjectlimit_set.get(name=name)
|
||||
ol.max_value += l.max_value
|
||||
ol.save()
|
||||
owner_limit = owner.userobjectlimit_set.get(name=name)
|
||||
owner_limit.max_value += user_limit.max_value
|
||||
owner_limit.save()
|
||||
|
||||
@@ -70,7 +70,7 @@ class AdminParametersForm(GenericParametersForm):
|
||||
"""Save parameters to database."""
|
||||
parameters = {}
|
||||
for name, value in list(self.cleaned_data.items()):
|
||||
if type(self.fields[name]) is form_utils.SeparatorField:
|
||||
if isinstance(self.fields[name], form_utils.SeparatorField):
|
||||
continue
|
||||
parameters[name] = value
|
||||
self.localconfig.parameters.set_values(parameters, app=self.app)
|
||||
@@ -101,7 +101,7 @@ class UserParametersForm(GenericParametersForm):
|
||||
"""Save new values."""
|
||||
parameters = {}
|
||||
for name, value in list(self.cleaned_data.items()):
|
||||
if type(self.fields[name]) is form_utils.SeparatorField:
|
||||
if isinstance(self.fields[name], form_utils.SeparatorField):
|
||||
continue
|
||||
parameters[name] = value
|
||||
self.user.parameters.set_values(parameters, app=self.app)
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
@@ -42,10 +42,10 @@ class Registry(object):
|
||||
|
||||
def _load_default_values(self, level):
|
||||
"""Load default values."""
|
||||
for app, data in list(self._registry[level].items()):
|
||||
for _app, data in list(self._registry[level].items()):
|
||||
form = data["formclass"](load_values_from_db=False)
|
||||
for name, field in list(form.fields.items()):
|
||||
if type(field) is form_utils.SeparatorField:
|
||||
if isinstance(field, form_utils.SeparatorField):
|
||||
continue
|
||||
data["defaults"][name] = field.initial
|
||||
|
||||
@@ -56,8 +56,10 @@ class Registry(object):
|
||||
if first_app in self._registry[level]:
|
||||
sorted_apps.append(first_app)
|
||||
sorted_apps += sorted(
|
||||
[a for a in list(self._registry[level].keys())
|
||||
if a != first_app],
|
||||
(
|
||||
a for a in self._registry[level]
|
||||
if a != first_app
|
||||
),
|
||||
key=lambda a: self._registry[level][a]["label"]
|
||||
)
|
||||
result = []
|
||||
|
||||
@@ -13,5 +13,5 @@ class RelayDomainsConfig(AppConfig):
|
||||
verbose_name = "Modoboa relay domains"
|
||||
|
||||
def ready(self):
|
||||
from . import handlers
|
||||
from . import transport
|
||||
from . import handlers # NOQA:F401
|
||||
from . import transport # NOQA:F401
|
||||
|
||||
@@ -64,15 +64,15 @@ class Operations(object):
|
||||
)
|
||||
|
||||
def _check_limit(self, name, curvalue, maxvalue):
|
||||
l = self.user.userobjectlimit_set.get(name=name)
|
||||
self.assertEqual(l.current_value, curvalue)
|
||||
self.assertEqual(l.max_value, maxvalue)
|
||||
limit = self.user.userobjectlimit_set.get(name=name)
|
||||
self.assertEqual(limit.current_value, curvalue)
|
||||
self.assertEqual(limit.max_value, maxvalue)
|
||||
|
||||
|
||||
class RelayDomainsTestCase(ModoTestCase, Operations):
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Create test data."""
|
||||
super(RelayDomainsTestCase, cls).setUpTestData()
|
||||
admin_factories.populate_database()
|
||||
@@ -305,10 +305,10 @@ class ImportTestCase(ModoTestCase):
|
||||
class LimitsTestCase(ModoTestCase, Operations):
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Create test data."""
|
||||
super(LimitsTestCase, cls).setUpTestData()
|
||||
for name, tpl in limits_utils.get_user_limit_templates():
|
||||
for name, _definition in limits_utils.get_user_limit_templates():
|
||||
cls.localconfig.parameters.set_value(
|
||||
"deflt_user_{0}_limit".format(name), 2, app="limits")
|
||||
cls.localconfig.save()
|
||||
@@ -371,7 +371,7 @@ class DataMixin(object):
|
||||
"""A mixin to provide test data."""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
super(DataMixin, cls).setUpTestData()
|
||||
transport = tr_factories.TransportFactory(
|
||||
pattern="test.com", _settings={
|
||||
|
||||
@@ -7,4 +7,4 @@ class TransportConfig(AppConfig):
|
||||
name = "modoboa.transport"
|
||||
|
||||
def ready(self):
|
||||
from . import handlers
|
||||
from . import handlers # NOQA:F401
|
||||
|
||||
@@ -76,10 +76,13 @@ class TransportBackendManager(object):
|
||||
|
||||
def get_backend_list(self):
|
||||
"""Return known backend list."""
|
||||
return sorted([
|
||||
(key, key)
|
||||
for key, backend in self.backends.items()
|
||||
], key=lambda i: i[1])
|
||||
return sorted(
|
||||
(
|
||||
(key, key)
|
||||
for key, backend in self.backends.items()
|
||||
),
|
||||
key=lambda i: i[1]
|
||||
)
|
||||
|
||||
def get_backend_settings(self, name):
|
||||
"""Return backend settings."""
|
||||
|
||||
Reference in New Issue
Block a user