Coverage for app/venv/lib/python3.14/site-packages/weblate/accounts/apps.py: 74%
32 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 07:15 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 07:15 +0000
1# Copyright © Michal Čihař <michal@weblate.org>
2#
3# SPDX-License-Identifier: GPL-3.0-or-later
5from __future__ import annotations
7from ssl import CertificateError
8from typing import TYPE_CHECKING
10from django.apps import AppConfig
11from django.conf import settings
12from django.core.checks import register
14from weblate.accounts.avatar import download_avatar_image
15from weblate.auth.utils import get_auth_keys
16from weblate.utils.checks import weblate_check
18if TYPE_CHECKING: 18 ↛ 19line 18 didn't jump to line 19 because the condition on line 18 was never true
19 from collections.abc import Iterable, Sequence
21 from django.core.checks import CheckMessage
24@register(deploy=True)
25def check_auth(
26 *,
27 app_configs: Sequence[AppConfig] | None,
28 databases: Sequence[str] | None,
29 **kwargs,
30) -> Iterable[CheckMessage]:
31 result: list[CheckMessage] = []
32 if settings.REGISTRATION_ALLOW_BACKENDS: 32 ↛ 33line 32 didn't jump to line 33 because the condition on line 32 was never true
33 backends = get_auth_keys()
34 result.extend(
35 weblate_check(
36 "weblate.C042",
37 f"REGISTRATION_ALLOW_BACKENDS contains invalid backend: {name}",
38 )
39 for name in settings.REGISTRATION_ALLOW_BACKENDS
40 if name not in backends
41 )
43 return result
46@register(deploy=True)
47def check_avatars(
48 *,
49 app_configs: Sequence[AppConfig] | None,
50 databases: Sequence[str] | None,
51 **kwargs,
52) -> Iterable[CheckMessage]:
53 if not settings.ENABLE_AVATARS: 53 ↛ 54line 53 didn't jump to line 54 because the condition on line 53 was never true
54 return []
55 try:
56 download_avatar_image("noreply@weblate.org", 32)
57 except (OSError, CertificateError) as error:
58 return [weblate_check("weblate.E018", f"Could not download avatar: {error}")]
59 return []
62class AccountsConfig(AppConfig):
63 name = "weblate.accounts"
64 label = "accounts"
65 verbose_name = "User profiles"