Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/django/core/management/commands/check.py: 64%
30 statements
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
1from django.apps import apps
2from django.core import checks
3from django.core.checks.registry import registry
4from django.core.management.base import BaseCommand, CommandError
7class Command(BaseCommand):
8 help = "Checks the entire Django project for potential problems."
10 requires_system_checks = []
12 def add_arguments(self, parser):
13 parser.add_argument("args", metavar="app_label", nargs="*")
14 parser.add_argument(
15 "--tag",
16 "-t",
17 action="append",
18 dest="tags",
19 help="Run only checks labeled with given tag.",
20 )
21 parser.add_argument(
22 "--list-tags",
23 action="store_true",
24 help="List available tags.",
25 )
26 parser.add_argument(
27 "--deploy",
28 action="store_true",
29 help="Check deployment settings.",
30 )
31 parser.add_argument(
32 "--fail-level",
33 default="ERROR",
34 choices=["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG"],
35 help=(
36 "Message level that will cause the command to exit with a "
37 "non-zero status. Default is ERROR."
38 ),
39 )
40 parser.add_argument(
41 "--database",
42 action="append",
43 dest="databases",
44 help="Run database related checks against these aliases.",
45 )
47 def handle(self, *app_labels, **options):
48 include_deployment_checks = options["deploy"]
49 if options["list_tags"]: 49 ↛ 50line 49 didn't jump to line 50, because the condition on line 49 was never true
50 self.stdout.write(
51 "\n".join(sorted(registry.tags_available(include_deployment_checks)))
52 )
53 return
55 if app_labels: 55 ↛ 56line 55 didn't jump to line 56, because the condition on line 55 was never true
56 app_configs = [apps.get_app_config(app_label) for app_label in app_labels]
57 else:
58 app_configs = None
60 tags = options["tags"]
61 if tags: 61 ↛ 62line 61 didn't jump to line 62, because the condition on line 61 was never true
62 try:
63 invalid_tag = next(
64 tag
65 for tag in tags
66 if not checks.tag_exists(tag, include_deployment_checks)
67 )
68 except StopIteration:
69 # no invalid tags
70 pass
71 else:
72 raise CommandError(
73 'There is no system check with the "%s" tag.' % invalid_tag
74 )
76 self.check(
77 app_configs=app_configs,
78 tags=tags,
79 display_num_errors=True,
80 include_deployment_checks=include_deployment_checks,
81 fail_level=getattr(checks, options["fail_level"]),
82 databases=options["databases"],
83 )