Python django.core.checks.Critical() Examples
The following are 6
code examples of django.core.checks.Critical().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.core.checks
, or try the search function
.
Example #1
Source File: checks.py From zing with GNU General Public License v3.0 | 6 votes |
def check_revision(app_configs=None, **kwargs): from pootle.core.models import Revision from pootle_store.models import Unit errors = [] revision = Revision.get() try: max_revision = Unit.max_revision() except (OperationalError, ProgrammingError): return errors if revision is None or revision < max_revision: errors.append( checks.Critical( _("Revision is missing or has an incorrect value."), hint=_("Run `revision --restore` to reset the revision counter."), id="pootle.C016", ) ) return errors
Example #2
Source File: checks.py From django-pgschemas with MIT License | 6 votes |
def check_schema_names(app_configs, **kwargs): errors = [] static_names = set(settings.TENANTS.keys()) clone_reference = get_clone_reference() if clone_reference: static_names.add(clone_reference) try: dynamic_names = set(get_tenant_model().objects.values_list("schema_name", flat=True)) except ProgrammingError: # This happens on the first run of migrate, with empty database. # It can also happen when the tenant model contains unapplied migrations that break. dynamic_names = set() intersection = static_names & dynamic_names if intersection: errors.append( checks.Critical( "Name clash found between static and dynamic tenants: %s" % intersection, id="pgschemas.W004", ) ) return errors
Example #3
Source File: checks.py From zing with GNU General Public License v3.0 | 5 votes |
def check_redis(app_configs=None, **kwargs): from django_rq.queues import get_queue from django_rq.workers import Worker errors = [] try: queue = get_queue() Worker.all(queue.connection) except Exception as e: conn_settings = queue.connection.connection_pool.connection_kwargs errors.append( checks.Critical( _("Could not connect to Redis (%s)" % e), hint=_( "Make sure Redis is running on %(host)s:%(port)s" % conn_settings ), id="pootle.C001", ) ) else: if len(queue.connection.smembers(Worker.redis_workers_keys)) == 0: # We need to check we're not running manage.py rqworker right now.. import sys if len(sys.argv) > 1 and sys.argv[1] in RQWORKER_WHITELIST: errors.append( checks.Warning( _("No RQ Worker running."), hint=_("Run new workers with manage.py rqworker"), id="pootle.W001", ) ) return errors
Example #4
Source File: test_checks.py From django-pgschemas with MIT License | 5 votes |
def test_name_clash(self): backup_create = TenantModel.auto_create_schema TenantModel.auto_create_schema = False # public TenantModel.objects.create(schema_name="public") errors = check_schema_names(self.app_config) expected_errors = [ checks.Critical("Name clash found between static and dynamic tenants: {'public'}", id="pgschemas.W004"), ] self.assertEqual(errors, expected_errors) TenantModel.objects.all().delete() # www TenantModel.objects.create(schema_name="www") errors = check_schema_names(self.app_config) expected_errors = [ checks.Critical("Name clash found between static and dynamic tenants: {'www'}", id="pgschemas.W004"), ] self.assertEqual(errors, expected_errors) TenantModel.objects.all().delete() # sample TenantModel.objects.create(schema_name="sample") errors = check_schema_names(self.app_config) expected_errors = [ checks.Critical("Name clash found between static and dynamic tenants: {'sample'}", id="pgschemas.W004"), ] self.assertEqual(errors, expected_errors) TenantModel.objects.all().delete() TenantModel.auto_create_schema = backup_create
Example #5
Source File: test_checks.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_is_anonymous_authenticated_methods(self): """ <User Model>.is_anonymous/is_authenticated must not be methods. """ class BadUser(AbstractBaseUser): username = models.CharField(max_length=30, unique=True) USERNAME_FIELD = 'username' def is_anonymous(self): return True def is_authenticated(self): return True errors = checks.run_checks(app_configs=self.apps.get_app_configs()) self.assertEqual(errors, [ checks.Critical( '%s.is_anonymous must be an attribute or property rather than ' 'a method. Ignoring this is a security issue as anonymous ' 'users will be treated as authenticated!' % BadUser, obj=BadUser, id='auth.C009', ), checks.Critical( '%s.is_authenticated must be an attribute or property rather ' 'than a method. Ignoring this is a security issue as anonymous ' 'users will be treated as authenticated!' % BadUser, obj=BadUser, id='auth.C010', ), ])
Example #6
Source File: test_checks.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_is_anonymous_authenticated_methods(self): """ <User Model>.is_anonymous/is_authenticated must not be methods. """ class BadUser(AbstractBaseUser): username = models.CharField(max_length=30, unique=True) USERNAME_FIELD = 'username' def is_anonymous(self): return True def is_authenticated(self): return True errors = checks.run_checks(app_configs=self.apps.get_app_configs()) self.assertEqual(errors, [ checks.Critical( '%s.is_anonymous must be an attribute or property rather than ' 'a method. Ignoring this is a security issue as anonymous ' 'users will be treated as authenticated!' % BadUser, obj=BadUser, id='auth.C009', ), checks.Critical( '%s.is_authenticated must be an attribute or property rather ' 'than a method. Ignoring this is a security issue as anonymous ' 'users will be treated as authenticated!' % BadUser, obj=BadUser, id='auth.C010', ), ])