當前位置: 首頁>>代碼示例>>Python>>正文


Python utils.NotSupportedError方法代碼示例

本文整理匯總了Python中django.db.utils.NotSupportedError方法的典型用法代碼示例。如果您正苦於以下問題:Python utils.NotSupportedError方法的具體用法?Python utils.NotSupportedError怎麽用?Python utils.NotSupportedError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.db.utils的用法示例。


在下文中一共展示了utils.NotSupportedError方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: callproc

# 需要導入模塊: from django.db import utils [as 別名]
# 或者: from django.db.utils import NotSupportedError [as 別名]
def callproc(self, procname, params=None, kparams=None):
        # Keyword parameters for callproc aren't supported in PEP 249, but the
        # database driver may support them (e.g. cx_Oracle).
        if kparams is not None and not self.db.features.supports_callproc_kwargs:
            raise NotSupportedError(
                'Keyword parameters for callproc are not supported on this '
                'database backend.'
            )
        self.db.validate_no_broken_transaction()
        with self.db.wrap_database_errors:
            if params is None and kparams is None:
                return self.cursor.callproc(procname)
            elif kparams is None:
                return self.cursor.callproc(procname, params)
            else:
                params = params or ()
                return self.cursor.callproc(procname, params, kparams) 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:19,代碼來源:utils.py

示例2: test_model_mocker_does_not_interfere_with_non_mocked_models

# 需要導入模塊: from django.db import utils [as 別名]
# 或者: from django.db.utils import NotSupportedError [as 別名]
def test_model_mocker_does_not_interfere_with_non_mocked_models(self):
        original_objects = CarVariation.objects

        with ModelMocker(Manufacturer) as make_mocker:
            self.assertEqual(Manufacturer.objects, make_mocker.objects)

            with ModelMocker(Car, outer=False) as car_mocker:
                self.assertEqual(Car.objects, car_mocker.objects)
                self.assertEqual(CarVariation.objects, original_objects)

                with self.assertRaises(NotSupportedError):
                    CarVariation.objects.create(color='blue')

                with self.assertRaises(NotSupportedError):
                    CarVariation(color='blue').save()

                with self.assertRaises(NotSupportedError):
                    CarVariation(id=1, color='blue').save()

                with self.assertRaises(NotSupportedError):
                    CarVariation(pk=1).delete()

                with self.assertRaises(NotSupportedError):
                    CarVariation.objects.all().delete() 
開發者ID:stphivos,項目名稱:django-mock-queries,代碼行數:26,代碼來源:test_mocks.py

示例3: check_expression_support

# 需要導入模塊: from django.db import utils [as 別名]
# 或者: from django.db.utils import NotSupportedError [as 別名]
def check_expression_support(self, expression):
        bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
        bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
        if isinstance(expression, bad_aggregates):
            for expr in expression.get_source_expressions():
                try:
                    output_field = expr.output_field
                except FieldError:
                    # Not every subexpression has an output_field which is fine
                    # to ignore.
                    pass
                else:
                    if isinstance(output_field, bad_fields):
                        raise utils.NotSupportedError(
                            'You cannot use Sum, Avg, StdDev, and Variance '
                            'aggregations on date/time fields in sqlite3 '
                            'since date/time is saved as text.'
                        ) 
開發者ID:PacktPublishing,項目名稱:Hands-On-Application-Development-with-PyCharm,代碼行數:20,代碼來源:operations.py

示例4: test_field_rename_inside_atomic_block

# 需要導入模塊: from django.db import utils [as 別名]
# 或者: from django.db.utils import NotSupportedError [as 別名]
def test_field_rename_inside_atomic_block(self):
        """
        NotImplementedError is raised when a model field rename is attempted
        inside an atomic block.
        """
        new_field = CharField(max_length=255, unique=True)
        new_field.set_attributes_from_name('renamed')
        msg = (
            "Renaming the 'backends_author'.'name' column while in a "
            "transaction is not supported on SQLite because it would break "
            "referential integrity. Try adding `atomic = False` to the "
            "Migration class."
        )
        with self.assertRaisesMessage(NotSupportedError, msg):
            with connection.schema_editor(atomic=True) as editor:
                editor.alter_field(Author, Author._meta.get_field('name'), new_field) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:18,代碼來源:tests.py

示例5: test_field_rename_inside_atomic_block

# 需要導入模塊: from django.db import utils [as 別名]
# 或者: from django.db.utils import NotSupportedError [as 別名]
def test_field_rename_inside_atomic_block(self):
        """
        NotImplementedError is raised when a model field rename is attempted
        inside an atomic block.
        """
        new_field = CharField(max_length=255, unique=True)
        new_field.set_attributes_from_name('renamed')
        msg = (
            "Renaming the 'backends_author'.'name' column while in a "
            "transaction is not supported on SQLite < 3.26 because it would "
            "break referential integrity. Try adding `atomic = False` to the "
            "Migration class."
        )
        with self.assertRaisesMessage(NotSupportedError, msg):
            with connection.schema_editor(atomic=True) as editor:
                editor.alter_field(Author, Author._meta.get_field('name'), new_field) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:18,代碼來源:tests.py

示例6: alter_db_table

# 需要導入模塊: from django.db import utils [as 別名]
# 或者: from django.db.utils import NotSupportedError [as 別名]
def alter_db_table(self, model, old_db_table, new_db_table, disable_constraints=True):
        if model._meta.related_objects and disable_constraints:
            if self.connection.in_atomic_block:
                raise NotSupportedError((
                    'Renaming the %r table while in a transaction is not '
                    'supported on SQLite because it would break referential '
                    'integrity. Try adding `atomic = False` to the Migration class.'
                ) % old_db_table)
            self.connection.enable_constraint_checking()
            super().alter_db_table(model, old_db_table, new_db_table)
            self.connection.disable_constraint_checking()
        else:
            super().alter_db_table(model, old_db_table, new_db_table) 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:15,代碼來源:schema.py

示例7: alter_field

# 需要導入模塊: from django.db import utils [as 別名]
# 或者: from django.db.utils import NotSupportedError [as 別名]
def alter_field(self, model, old_field, new_field, strict=False):
        old_field_name = old_field.name
        if (new_field.name != old_field_name and
                any(r.field_name == old_field.name for r in model._meta.related_objects)):
            if self.connection.in_atomic_block:
                raise NotSupportedError((
                    'Renaming the %r.%r column while in a transaction is not '
                    'supported on SQLite because it would break referential '
                    'integrity. Try adding `atomic = False` to the Migration class.'
                ) % (model._meta.db_table, old_field_name))
            with atomic(self.connection.alias):
                super().alter_field(model, old_field, new_field, strict=strict)
                # Follow SQLite's documented procedure for performing changes
                # that don't affect the on-disk content.
                # https://sqlite.org/lang_altertable.html#otheralter
                with self.connection.cursor() as cursor:
                    schema_version = cursor.execute('PRAGMA schema_version').fetchone()[0]
                    cursor.execute('PRAGMA writable_schema = 1')
                    table_name = model._meta.db_table
                    references_template = ' REFERENCES "%s" ("%%s") ' % table_name
                    old_column_name = old_field.get_attname_column()[1]
                    new_column_name = new_field.get_attname_column()[1]
                    search = references_template % old_column_name
                    replacement = references_template % new_column_name
                    cursor.execute('UPDATE sqlite_master SET sql = replace(sql, %s, %s)', (search, replacement))
                    cursor.execute('PRAGMA schema_version = %d' % (schema_version + 1))
                    cursor.execute('PRAGMA writable_schema = 0')
                    # The integrity check will raise an exception and rollback
                    # the transaction if the sqlite_master updates corrupt the
                    # database.
                    cursor.execute('PRAGMA integrity_check')
            # Perform a VACUUM to refresh the database representation from
            # the sqlite_master table.
            with self.connection.cursor() as cursor:
                cursor.execute('VACUUM')
        else:
            super().alter_field(model, old_field, new_field, strict=strict) 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:39,代碼來源:schema.py

示例8: mock_django_connection

# 需要導入模塊: from django.db import utils [as 別名]
# 或者: from django.db.utils import NotSupportedError [as 別名]
def mock_django_connection(disabled_features=None):
    """ Overwrite the Django database configuration with a mocked version.

    This is a helper function that does the actual monkey patching.
    """
    db = connections.databases['default']
    db['PASSWORD'] = '****'
    db['USER'] = '**Database disabled for unit tests**'
    ConnectionHandler.__getitem__ = MagicMock(name='mock_connection')
    # noinspection PyUnresolvedReferences
    mock_connection = ConnectionHandler.__getitem__.return_value
    if disabled_features:
        for feature in disabled_features:
            setattr(mock_connection.features, feature, False)
    mock_ops = mock_connection.ops

    # noinspection PyUnusedLocal
    def compiler(queryset, connection, using, **kwargs):
        result = MagicMock(name='mock_connection.ops.compiler()')
        # noinspection PyProtectedMember
        result.execute_sql.side_effect = NotSupportedError(
            "Mock database tried to execute SQL for {} model.".format(
                queryset.model._meta.object_name))
        result.has_results.side_effect = result.execute_sql.side_effect
        return result

    mock_ops.compiler.return_value.side_effect = compiler
    mock_ops.integer_field_range.return_value = (-sys.maxsize - 1, sys.maxsize)
    mock_ops.max_name_length.return_value = sys.maxsize

    Model.refresh_from_db = Mock()  # Make this into a noop. 
開發者ID:stphivos,項目名稱:django-mock-queries,代碼行數:33,代碼來源:mocks.py

示例9: test_mock_sql_raises_error

# 需要導入模塊: from django.db import utils [as 別名]
# 或者: from django.db.utils import NotSupportedError [as 別名]
def test_mock_sql_raises_error(self):
        """ Get a clear error if you forget to mock a database query. """
        with self.assertRaisesRegexp(
                NotSupportedError,
                "Mock database tried to execute SQL for Car model."):
            Car.objects.count() 
開發者ID:stphivos,項目名稱:django-mock-queries,代碼行數:8,代碼來源:test_mocks.py

示例10: test_exists_raises_error

# 需要導入模塊: from django.db import utils [as 別名]
# 或者: from django.db.utils import NotSupportedError [as 別名]
def test_exists_raises_error(self):
        """ Get a clear error if you forget to mock a database query. """
        with self.assertRaisesRegexp(
                NotSupportedError,
                "Mock database tried to execute SQL for Car model."):
            Car.objects.exists() 
開發者ID:stphivos,項目名稱:django-mock-queries,代碼行數:8,代碼來源:test_mocks.py

示例11: test_not_mocked

# 需要導入模塊: from django.db import utils [as 別名]
# 或者: from django.db.utils import NotSupportedError [as 別名]
def test_not_mocked(self):
        car = Car(id=99)

        with self.assertRaises(NotSupportedError):
            car.sedan 
開發者ID:stphivos,項目名稱:django-mock-queries,代碼行數:7,代碼來源:test_mocks.py

示例12: supports_stddev

# 需要導入模塊: from django.db import utils [as 別名]
# 或者: from django.db.utils import NotSupportedError [as 別名]
def supports_stddev(self):
        """Confirm support for STDDEV and related stats functions."""
        try:
            self.connection.ops.check_expression_support(StdDev(1))
        except NotSupportedError:
            return False
        return True 
開發者ID:PacktPublishing,項目名稱:Hands-On-Application-Development-with-PyCharm,代碼行數:9,代碼來源:features.py

示例13: __enter__

# 需要導入模塊: from django.db import utils [as 別名]
# 或者: from django.db.utils import NotSupportedError [as 別名]
def __enter__(self):
        # Some SQLite schema alterations need foreign key constraints to be
        # disabled. Enforce it here for the duration of the schema edition.
        if not self.connection.disable_constraint_checking():
            raise NotSupportedError(
                'SQLite schema editor cannot be used while foreign key '
                'constraint checks are enabled. Make sure to disable them '
                'before entering a transaction.atomic() context because '
                'SQLite3 does not support disabling them in the middle of '
                'a multi-statement transaction.'
            )
        self.connection.cursor().execute('PRAGMA legacy_alter_table = ON')
        return super().__enter__() 
開發者ID:PacktPublishing,項目名稱:Hands-On-Application-Development-with-PyCharm,代碼行數:15,代碼來源:schema.py

示例14: alter_db_table

# 需要導入模塊: from django.db import utils [as 別名]
# 或者: from django.db.utils import NotSupportedError [as 別名]
def alter_db_table(self, model, old_db_table, new_db_table, disable_constraints=True):
        if disable_constraints and self._is_referenced_by_fk_constraint(old_db_table):
            if self.connection.in_atomic_block:
                raise NotSupportedError((
                    'Renaming the %r table while in a transaction is not '
                    'supported on SQLite because it would break referential '
                    'integrity. Try adding `atomic = False` to the Migration class.'
                ) % old_db_table)
            self.connection.enable_constraint_checking()
            super().alter_db_table(model, old_db_table, new_db_table)
            self.connection.disable_constraint_checking()
        else:
            super().alter_db_table(model, old_db_table, new_db_table) 
開發者ID:PacktPublishing,項目名稱:Hands-On-Application-Development-with-PyCharm,代碼行數:15,代碼來源:schema.py

示例15: alter_field

# 需要導入模塊: from django.db import utils [as 別名]
# 或者: from django.db.utils import NotSupportedError [as 別名]
def alter_field(self, model, old_field, new_field, strict=False):
        old_field_name = old_field.name
        table_name = model._meta.db_table
        _, old_column_name = old_field.get_attname_column()
        if (new_field.name != old_field_name and
                self._is_referenced_by_fk_constraint(table_name, old_column_name, ignore_self=True)):
            if self.connection.in_atomic_block:
                raise NotSupportedError((
                    'Renaming the %r.%r column while in a transaction is not '
                    'supported on SQLite because it would break referential '
                    'integrity. Try adding `atomic = False` to the Migration class.'
                ) % (model._meta.db_table, old_field_name))
            with atomic(self.connection.alias):
                super().alter_field(model, old_field, new_field, strict=strict)
                # Follow SQLite's documented procedure for performing changes
                # that don't affect the on-disk content.
                # https://sqlite.org/lang_altertable.html#otheralter
                with self.connection.cursor() as cursor:
                    schema_version = cursor.execute('PRAGMA schema_version').fetchone()[0]
                    cursor.execute('PRAGMA writable_schema = 1')
                    references_template = ' REFERENCES "%s" ("%%s") ' % table_name
                    new_column_name = new_field.get_attname_column()[1]
                    search = references_template % old_column_name
                    replacement = references_template % new_column_name
                    cursor.execute('UPDATE sqlite_master SET sql = replace(sql, %s, %s)', (search, replacement))
                    cursor.execute('PRAGMA schema_version = %d' % (schema_version + 1))
                    cursor.execute('PRAGMA writable_schema = 0')
                    # The integrity check will raise an exception and rollback
                    # the transaction if the sqlite_master updates corrupt the
                    # database.
                    cursor.execute('PRAGMA integrity_check')
            # Perform a VACUUM to refresh the database representation from
            # the sqlite_master table.
            with self.connection.cursor() as cursor:
                cursor.execute('VACUUM')
        else:
            super().alter_field(model, old_field, new_field, strict=strict) 
開發者ID:PacktPublishing,項目名稱:Hands-On-Application-Development-with-PyCharm,代碼行數:39,代碼來源:schema.py


注:本文中的django.db.utils.NotSupportedError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。