Python django.db.connection.features() Examples
The following are 30
code examples of django.db.connection.features().
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.db.connection
, or try the search function
.
Example #1
Source File: testcases.py From python2017 with MIT License | 5 votes |
def _should_check_constraints(self, connection): return ( connection.features.can_defer_constraint_checks and not connection.needs_rollback and connection.is_usable() )
Example #2
Source File: testcases.py From python with Apache License 2.0 | 5 votes |
def skipIfDBFeature(*features): """ Skip a test if a database has at least one of the named features. """ return _deferredSkip( lambda: any(getattr(connection.features, feature, False) for feature in features), "Database has feature(s) %s" % ", ".join(features) )
Example #3
Source File: testcases.py From python with Apache License 2.0 | 5 votes |
def skipUnlessAnyDBFeature(*features): """ Skip a test unless a database has any of the named features. """ return _deferredSkip( lambda: not any(getattr(connection.features, feature, False) for feature in features), "Database doesn't support any of the feature(s): %s" % ", ".join(features) )
Example #4
Source File: options.py From openhgsenti with Apache License 2.0 | 5 votes |
def can_migrate(self, connection): """ Return True if the model can/should be migrated on the `connection`. `connection` can be either a real connection or a connection alias. """ if self.proxy or self.swapped or not self.managed: return False if isinstance(connection, six.string_types): connection = connections[connection] if self.required_db_vendor: return self.required_db_vendor == connection.vendor if self.required_db_features: return all(getattr(connection.features, feat, False) for feat in self.required_db_features) return True
Example #5
Source File: testcases.py From openhgsenti with Apache License 2.0 | 5 votes |
def _reset_sequences(self, db_name): conn = connections[db_name] if conn.features.supports_sequence_reset: sql_list = conn.ops.sequence_reset_by_name_sql( no_style(), conn.introspection.sequence_list()) if sql_list: with transaction.atomic(using=db_name): cursor = conn.cursor() for sql in sql_list: cursor.execute(sql)
Example #6
Source File: testcases.py From openhgsenti with Apache License 2.0 | 5 votes |
def connections_support_transactions(): """ Returns True if all connections support transactions. """ return all(conn.features.supports_transactions for conn in connections.all())
Example #7
Source File: testcases.py From openhgsenti with Apache License 2.0 | 5 votes |
def skipIfDBFeature(*features): """ Skip a test if a database has at least one of the named features. """ return _deferredSkip( lambda: any(getattr(connection.features, feature, False) for feature in features), "Database has feature(s) %s" % ", ".join(features) )
Example #8
Source File: testcases.py From openhgsenti with Apache License 2.0 | 5 votes |
def skipUnlessDBFeature(*features): """ Skip a test unless a database has all the named features. """ return _deferredSkip( lambda: not all(getattr(connection.features, feature, False) for feature in features), "Database doesn't support feature(s): %s" % ", ".join(features) )
Example #9
Source File: options.py From python2017 with MIT License | 5 votes |
def can_migrate(self, connection): """ Return True if the model can/should be migrated on the `connection`. `connection` can be either a real connection or a connection alias. """ if self.proxy or self.swapped or not self.managed: return False if isinstance(connection, six.string_types): connection = connections[connection] if self.required_db_vendor: return self.required_db_vendor == connection.vendor if self.required_db_features: return all(getattr(connection.features, feat, False) for feat in self.required_db_features) return True
Example #10
Source File: testcases.py From python2017 with MIT License | 5 votes |
def _reset_sequences(self, db_name): conn = connections[db_name] if conn.features.supports_sequence_reset: sql_list = conn.ops.sequence_reset_by_name_sql( no_style(), conn.introspection.sequence_list()) if sql_list: with transaction.atomic(using=db_name): cursor = conn.cursor() for sql in sql_list: cursor.execute(sql)
Example #11
Source File: testcases.py From python2017 with MIT License | 5 votes |
def connections_support_transactions(): """ Returns True if all connections support transactions. """ return all(conn.features.supports_transactions for conn in connections.all())
Example #12
Source File: testcases.py From python with Apache License 2.0 | 5 votes |
def _should_check_constraints(self, connection): return ( connection.features.can_defer_constraint_checks and not connection.needs_rollback and connection.is_usable() )
Example #13
Source File: testcases.py From python2017 with MIT License | 5 votes |
def skipIfDBFeature(*features): """ Skip a test if a database has at least one of the named features. """ return _deferredSkip( lambda: any(getattr(connection.features, feature, False) for feature in features), "Database has feature(s) %s" % ", ".join(features) )
Example #14
Source File: testcases.py From python2017 with MIT License | 5 votes |
def skipUnlessAnyDBFeature(*features): """ Skip a test unless a database has any of the named features. """ return _deferredSkip( lambda: not any(getattr(connection.features, feature, False) for feature in features), "Database doesn't support any of the feature(s): %s" % ", ".join(features) )
Example #15
Source File: test_features.py From django-sqlserver with MIT License | 5 votes |
def test_nonexistent_feature(self): self.assertFalse(hasattr(connection.features, 'nonexistent'))
Example #16
Source File: test_features.py From django-sqlserver with MIT License | 5 votes |
def test_mysql_supports_transactions(self): """ All storage engines except MyISAM support transactions. """ with mock.patch('django.db.connection.features._mysql_storage_engine', 'InnoDB'): self.assertTrue(connection.features.supports_transactions) del connection.features.supports_transactions with mock.patch('django.db.connection.features._mysql_storage_engine', 'MyISAM'): self.assertFalse(connection.features.supports_transactions) del connection.features.supports_transactions
Example #17
Source File: test_features.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_nonexistent_feature(self): self.assertFalse(hasattr(connection.features, 'nonexistent'))
Example #18
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_count_join_optimization_disabled(self): with mock.patch.object(connection.features, 'supports_foreign_keys', False), \ CaptureQueriesContext(connection) as query: self.article.publications.count() self.assertIn('JOIN', query[0]['sql'])
Example #19
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_exists_join_optimization_disabled(self): with mock.patch.object(connection.features, 'supports_foreign_keys', False), \ CaptureQueriesContext(connection) as query: self.article.publications.exists() self.assertIn('JOIN', query[0]['sql'])
Example #20
Source File: test_relative_fields.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_nullable_primary_key(self): class Model(models.Model): field = models.IntegerField(primary_key=True, null=True) field = Model._meta.get_field('field') with mock.patch.object(connection.features, 'interprets_empty_strings_as_nulls', False): results = field.check() self.assertEqual(results, [ Error( 'Primary keys must not have null=True.', hint='Set null=False on the field, or remove primary_key=True argument.', obj=field, id='fields.E007', ), ])
Example #21
Source File: test_features.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_nonexistent_feature(self): self.assertFalse(hasattr(connection.features, 'nonexistent'))
Example #22
Source File: test_mocks.py From django-mock-queries with MIT License | 5 votes |
def test_mock_django_connection(self, mock_handler): is_foo_before = bool(getattr(connection.features, 'is_foo', False)) mock_django_connection(disabled_features=['is_foo']) is_foo_after = bool(getattr(connection.features, 'is_foo', False)) self.assertTrue(is_foo_before) self.assertFalse(is_foo_after) # noinspection PyUnresolvedReferences,PyStatementEffect
Example #23
Source File: testcases.py From GTDWeb with GNU General Public License v2.0 | 5 votes |
def connections_support_transactions(): """ Returns True if all connections support transactions. """ return all(conn.features.supports_transactions for conn in connections.all())
Example #24
Source File: testcases.py From GTDWeb with GNU General Public License v2.0 | 5 votes |
def skipIfDBFeature(*features): """ Skip a test if a database has at least one of the named features. """ return _deferredSkip( lambda: any(getattr(connection.features, feature, False) for feature in features), "Database has feature(s) %s" % ", ".join(features) )
Example #25
Source File: testcases.py From GTDWeb with GNU General Public License v2.0 | 5 votes |
def skipUnlessDBFeature(*features): """ Skip a test unless a database has all the named features. """ return _deferredSkip( lambda: not all(getattr(connection.features, feature, False) for feature in features), "Database doesn't support feature(s): %s" % ", ".join(features) )
Example #26
Source File: options.py From bioforum with MIT License | 5 votes |
def can_migrate(self, connection): """ Return True if the model can/should be migrated on the `connection`. `connection` can be either a real connection or a connection alias. """ if self.proxy or self.swapped or not self.managed: return False if isinstance(connection, str): connection = connections[connection] if self.required_db_vendor: return self.required_db_vendor == connection.vendor if self.required_db_features: return all(getattr(connection.features, feat, False) for feat in self.required_db_features) return True
Example #27
Source File: testcases.py From bioforum with MIT License | 5 votes |
def _reset_sequences(self, db_name): conn = connections[db_name] if conn.features.supports_sequence_reset: sql_list = conn.ops.sequence_reset_by_name_sql( no_style(), conn.introspection.sequence_list()) if sql_list: with transaction.atomic(using=db_name): cursor = conn.cursor() for sql in sql_list: cursor.execute(sql)
Example #28
Source File: testcases.py From bioforum with MIT License | 5 votes |
def connections_support_transactions(): """Return True if all connections support transactions.""" return all(conn.features.supports_transactions for conn in connections.all())
Example #29
Source File: testcases.py From bioforum with MIT License | 5 votes |
def _should_check_constraints(self, connection): return ( connection.features.can_defer_constraint_checks and not connection.needs_rollback and connection.is_usable() )
Example #30
Source File: testcases.py From bioforum with MIT License | 5 votes |
def skipIfDBFeature(*features): """Skip a test if a database has at least one of the named features.""" return _deferredSkip( lambda: any(getattr(connection.features, feature, False) for feature in features), "Database has feature(s) %s" % ", ".join(features) )