🚨(pytest) fix or suppress warnings during backend tests
Avoid unnecessary noise from testing processes
This commit is contained in:
committed by
Laurent Bossavit
parent
0f290df24a
commit
fbb4797f29
@@ -7,6 +7,7 @@ from functools import reduce
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db.models import OuterRef, Q, Subquery, Value
|
from django.db.models import OuterRef, Q, Subquery, Value
|
||||||
from django.db.models.functions import Coalesce
|
from django.db.models.functions import Coalesce
|
||||||
|
from django.utils import timezone
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
from django.views.decorators.cache import cache_page
|
from django.views.decorators.cache import cache_page
|
||||||
|
|
||||||
@@ -605,7 +606,7 @@ class StatView(views.APIView):
|
|||||||
context = {
|
context = {
|
||||||
"total_users": models.User.objects.count(),
|
"total_users": models.User.objects.count(),
|
||||||
"mau": models.User.objects.filter(
|
"mau": models.User.objects.filter(
|
||||||
last_login__gte=datetime.datetime.now() - datetime.timedelta(30)
|
last_login__gte=timezone.now() - datetime.timedelta(30)
|
||||||
).count(),
|
).count(),
|
||||||
"teams": models.Team.objects.count(),
|
"teams": models.Team.objects.count(),
|
||||||
"domains": domains_models.MailDomain.objects.count(),
|
"domains": domains_models.MailDomain.objects.count(),
|
||||||
|
|||||||
@@ -240,7 +240,7 @@ class TeamWebhookFactory(factory.django.DjangoModelFactory):
|
|||||||
model = models.TeamWebhook
|
model = models.TeamWebhook
|
||||||
|
|
||||||
team = factory.SubFactory(TeamFactory)
|
team = factory.SubFactory(TeamFactory)
|
||||||
url = factory.Sequence(lambda n: f"https://example.com/Groups/{n!s}")
|
url = factory.Sequence(lambda n: f"https://nosuchdomain.xyz/Groups/{n!s}")
|
||||||
|
|
||||||
|
|
||||||
class InvitationFactory(factory.django.DjangoModelFactory):
|
class InvitationFactory(factory.django.DjangoModelFactory):
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
"""Admin classes and registrations for People's mailbox manager app."""
|
"""Admin classes and registrations for People's mailbox manager app."""
|
||||||
|
|
||||||
from django.contrib import admin, messages
|
from django.contrib import admin, messages
|
||||||
from django.utils.html import format_html
|
from django.utils.html import format_html_join, mark_safe
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from requests import exceptions
|
from requests import exceptions
|
||||||
@@ -9,6 +9,9 @@ from requests import exceptions
|
|||||||
from mailbox_manager import enums, models
|
from mailbox_manager import enums, models
|
||||||
from mailbox_manager.utils.dimail import DimailAPIClient
|
from mailbox_manager.utils.dimail import DimailAPIClient
|
||||||
|
|
||||||
|
# Prevent Ruff complaining about mark_safe below
|
||||||
|
# ruff: noqa: S308
|
||||||
|
|
||||||
|
|
||||||
@admin.action(description=_("Synchronise from dimail"))
|
@admin.action(description=_("Synchronise from dimail"))
|
||||||
def sync_mailboxes_from_dimail(modeladmin, request, queryset): # pylint: disable=unused-argument
|
def sync_mailboxes_from_dimail(modeladmin, request, queryset): # pylint: disable=unused-argument
|
||||||
@@ -79,10 +82,16 @@ def fetch_domain_status_from_dimail(modeladmin, request, queryset): # pylint: d
|
|||||||
if domains_updated
|
if domains_updated
|
||||||
else _("No domain updated."),
|
else _("No domain updated."),
|
||||||
]
|
]
|
||||||
messages.success(request, format_html("<br> ".join(map(str, msg_success))))
|
messages.success(
|
||||||
|
request,
|
||||||
|
format_html_join(mark_safe("<br> "), "{}", ([str(m)] for m in msg_success)),
|
||||||
|
)
|
||||||
if msg_error:
|
if msg_error:
|
||||||
msg_error.insert(0, _("Check domain failed for:"))
|
msg_error.insert(0, _("Check domain failed for:"))
|
||||||
messages.error(request, format_html("<br> ".join(map(str, msg_error))))
|
messages.error(
|
||||||
|
request,
|
||||||
|
format_html_join(mark_safe("<br> "), "{}", ([str(m)] for m in msg_error)),
|
||||||
|
)
|
||||||
if excluded_domains:
|
if excluded_domains:
|
||||||
messages.warning(
|
messages.warning(
|
||||||
request,
|
request,
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ class Command(BaseCommand):
|
|||||||
# protected behind admin rights but dimail allows to create a first user
|
# protected behind admin rights but dimail allows to create a first user
|
||||||
# when database is empty
|
# when database is empty
|
||||||
self.create_user(
|
self.create_user(
|
||||||
auth=(None, None),
|
auth=("", ""),
|
||||||
name=admin["username"],
|
name=admin["username"],
|
||||||
password=admin["password"],
|
password=admin["password"],
|
||||||
perms=[],
|
perms=[],
|
||||||
|
|||||||
@@ -140,6 +140,12 @@ python_files = [
|
|||||||
"test_*.py",
|
"test_*.py",
|
||||||
"tests.py",
|
"tests.py",
|
||||||
]
|
]
|
||||||
|
filterwarnings = [
|
||||||
|
# This one can be removed when upgrading to Django 6.0
|
||||||
|
'ignore:The FORMS_URLFIELD_ASSUME_HTTPS transitional setting is deprecated.',
|
||||||
|
# This one can be removed after upgrading DRF to 3.16
|
||||||
|
"ignore:Converter 'drf_format_suffix'"
|
||||||
|
]
|
||||||
|
|
||||||
[tool.coverage.run]
|
[tool.coverage.run]
|
||||||
branch = true
|
branch = true
|
||||||
|
|||||||
Reference in New Issue
Block a user