def test_clone_test_db_options_ordering(self): creation = DatabaseCreation(connection) try: saved_settings = connection.settings_dict connection.settings_dict = { "NAME": "source_db", "USER": "", "PASSWORD": "", "PORT": "", "HOST": "", "ENGINE": "django.db.backends.mysql", "OPTIONS": { "read_default_file": "my.cnf", }, } with mock.patch.object(subprocess, "Popen") as mocked_popen: creation._clone_db("source_db", "target_db") mocked_popen.assert_has_calls([ mock.call( [ "mysqldump", "--defaults-file=my.cnf", "--routines", "--events", "source_db", ], stdout=subprocess.PIPE, env=None, ), ]) finally: connection.settings_dict = saved_settings
def test_clone_test_db_options_ordering(self): creation = DatabaseCreation(connection) try: saved_settings = connection.settings_dict connection.settings_dict = { 'NAME': 'source_db', 'USER': '', 'PASSWORD': '', 'PORT': '', 'HOST': '', 'ENGINE': 'django.db.backends.mysql', 'OPTIONS': { 'read_default_file': 'my.cnf', }, } with mock.patch.object(subprocess, 'Popen') as mocked_popen: creation._clone_db('source_db', 'target_db') mocked_popen.assert_has_calls([ mock.call( [ 'mysqldump', '--defaults-file=my.cnf', '--routines', '--events', 'source_db', ], stdout=subprocess.PIPE, env=None, ), ]) finally: connection.settings_dict = saved_settings
def test_create_test_db_unexpected_error(self, *mocked_objects): # Simulate test database creation raising unexpected error creation = DatabaseCreation(connection) with self.patch_test_db_creation(self._execute_raise_access_denied): with self.assertRaises(SystemExit): creation._create_test_db(verbosity=0, autoclobber=False, keepdb=False)
def test_create_test_db_database_exists(self, *mocked_objects): # Simulate test database creation raising "database exists" creation = MySQLDatabaseCreation(connection) with self.patch_test_db_creation(self._execute_raise_database_exists): with mock.patch('builtins.input', return_value='no'): with self.assertRaises(SystemExit): # SystemExit is raised if the user answers "no" to the # prompt asking if it's okay to delete the test database. creation._create_test_db(verbosity=0, autoclobber=False, keepdb=False) # "Database exists" shouldn't appear when keepdb is on creation._create_test_db(verbosity=0, autoclobber=False, keepdb=True)
def test_create_test_db_database_exists(self, *mocked_objects): # Simulate test database creation raising "database exists" creation = MySQLDatabaseCreation(connection) with self.patch_test_db_creation(self._execute_raise_database_exists): with mock.patch('builtins.input', return_value='no'): with self.assertRaises(SystemExit): # SystemExit is raised if the user answers "no" to the # prompt asking if it's okay to delete the test database. creation._create_test_db(verbosity=0, autoclobber=False, keepdb=False) # "Database exists" shouldn't appear when keepdb is on creation._create_test_db(verbosity=0, autoclobber=False, keepdb=True)
def __init__(self, *args, **kwargs): super(DatabaseWrapper, self).__init__(*args, **kwargs) self.features = DatabaseFeatures(self) self.ops = DatabaseOperations(self) self.client = DatabaseClient(self) self.creation = DatabaseCreation(self) self.introspection = DatabaseIntrospection(self) self.validation = DatabaseValidation(self)
def __init__(self, *args, **kwargs): super(DatabaseWrapper, self).__init__(*args, **kwargs) self.server_version = None self.features = DatabaseFeatures() self.ops = mysqldb_base.DatabaseOperations() self.client = DatabaseClient(self) self.creation = DatabaseCreation(self) self.introspection = DatabaseIntrospection(self) self.validation = DatabaseValidation(self) self.pool = None
def __init__(self, *args, **kwargs): super(DatabaseWrapper, self).__init__(*args, **kwargs) self.server_version = None self.features = DatabaseFeatures(self) self.ops = DatabaseOperations(self) self.client = DatabaseClient(self) self.creation = DatabaseCreation(self) #数据库创建器, from django.db.backends.mysql.creation import DatabaseCreation self.introspection = DatabaseIntrospection(self) self.validation = DatabaseValidation(self)
def test_clone_test_db_database_exists(self): creation = DatabaseCreation(connection) with self.patch_test_db_creation(self._execute_raise_database_exists): with mock.patch.object(DatabaseCreation, '_clone_db') as _clone_db: creation._clone_test_db('suffix', verbosity=0, keepdb=True) _clone_db.assert_not_called()
def test_create_test_db_unexpected_error(self, *mocked_objects): # Simulate test database creation raising unexpected error creation = MySQLDatabaseCreation(connection) with self.patch_test_db_creation(self._execute_raise_access_denied): with self.assertRaises(SystemExit): creation._create_test_db(verbosity=0, autoclobber=False, keepdb=False)
def test_clone_test_db_database_exists(self): creation = DatabaseCreation(connection) with self.patch_test_db_creation(self._execute_raise_database_exists): with mock.patch.object(DatabaseCreation, '_clone_db') as _clone_db: creation._clone_test_db('suffix', verbosity=0, keepdb=True) _clone_db.assert_not_called()