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

22 statements  

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

1from itertools import chain 

2 

3from django.apps import apps 

4from django.core.checks import Error 

5 

6 

7def check_generic_foreign_keys(app_configs=None, **kwargs): 

8 from .fields import GenericForeignKey 

9 

10 if app_configs is None: 10 ↛ 13line 10 didn't jump to line 13, because the condition on line 10 was never false

11 models = apps.get_models() 

12 else: 

13 models = chain.from_iterable( 

14 app_config.get_models() for app_config in app_configs 

15 ) 

16 errors = [] 

17 fields = ( 

18 obj 

19 for model in models 

20 for obj in vars(model).values() 

21 if isinstance(obj, GenericForeignKey) 

22 ) 

23 for field in fields: 

24 errors.extend(field.check()) 

25 return errors 

26 

27 

28def check_model_name_lengths(app_configs=None, **kwargs): 

29 if app_configs is None: 29 ↛ 32line 29 didn't jump to line 32, because the condition on line 29 was never false

30 models = apps.get_models() 

31 else: 

32 models = chain.from_iterable( 

33 app_config.get_models() for app_config in app_configs 

34 ) 

35 errors = [] 

36 for model in models: 

37 if len(model._meta.model_name) > 100: 37 ↛ 38line 37 didn't jump to line 38, because the condition on line 37 was never true

38 errors.append( 

39 Error( 

40 "Model names must be at most 100 characters (got %d)." 

41 % (len(model._meta.model_name),), 

42 obj=model, 

43 id="contenttypes.E005", 

44 ) 

45 ) 

46 return errors