Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/django/core/checks/templates.py: 83%

18 statements  

« prev     ^ index     » next       coverage.py v6.4.4, created at 2023-07-17 14:22 -0600

1import copy 

2 

3from django.conf import settings 

4 

5from . import Error, Tags, register 

6 

7E001 = Error( 

8 "You have 'APP_DIRS': True in your TEMPLATES but also specify 'loaders' " 

9 "in OPTIONS. Either remove APP_DIRS or remove the 'loaders' option.", 

10 id="templates.E001", 

11) 

12E002 = Error( 

13 "'string_if_invalid' in TEMPLATES OPTIONS must be a string but got: {} ({}).", 

14 id="templates.E002", 

15) 

16 

17 

18@register(Tags.templates) 

19def check_setting_app_dirs_loaders(app_configs, **kwargs): 

20 return ( 

21 [E001] 

22 if any( 

23 conf.get("APP_DIRS") and "loaders" in conf.get("OPTIONS", {}) 

24 for conf in settings.TEMPLATES 

25 ) 

26 else [] 

27 ) 

28 

29 

30@register(Tags.templates) 

31def check_string_if_invalid_is_string(app_configs, **kwargs): 

32 errors = [] 

33 for conf in settings.TEMPLATES: 

34 string_if_invalid = conf.get("OPTIONS", {}).get("string_if_invalid", "") 

35 if not isinstance(string_if_invalid, str): 35 ↛ 36line 35 didn't jump to line 36, because the condition on line 35 was never true

36 error = copy.copy(E002) 

37 error.msg = error.msg.format( 

38 string_if_invalid, type(string_if_invalid).__name__ 

39 ) 

40 errors.append(error) 

41 return errors