Best Python code snippet using autotest_python
creation.py
Source:creation.py
1import sys2from django.db.backends.base.creation import BaseDatabaseCreation3class DatabaseCreation(BaseDatabaseCreation):4 def _quote_name(self, name):5 return self.connection.ops.quote_name(name)6 def _get_database_create_suffix(self, encoding=None, template=None):7 suffix = ""8 if encoding:9 suffix += " ENCODING '{}'".format(encoding)10 if template:11 suffix += " TEMPLATE {}".format(self._quote_name(template))12 if suffix:13 suffix = "WITH" + suffix14 return suffix15 def sql_table_creation_suffix(self):16 test_settings = self.connection.settings_dict['TEST']17 assert test_settings['COLLATION'] is None, (18 "PostgreSQL does not support collation setting at database creation time."19 )20 return self._get_database_create_suffix(21 encoding=test_settings['CHARSET'],22 template=test_settings.get('TEMPLATE'),23 )24 def _clone_test_db(self, number, verbosity, keepdb=False):25 # CREATE DATABASE ... WITH TEMPLATE ... requires closing connections26 # to the template database.27 self.connection.close()28 source_database_name = self.connection.settings_dict['NAME']29 target_database_name = self.get_test_db_clone_settings(number)['NAME']30 suffix = self._get_database_create_suffix(template=source_database_name)31 creation_sql = "CREATE DATABASE {} {}".format(self._quote_name(target_database_name), suffix)32 with self._nodb_connection.cursor() as cursor:33 try:34 cursor.execute(creation_sql)35 except Exception:36 if keepdb:37 return38 try:39 if verbosity >= 1:40 print("Destroying old test database for alias %s..." % (41 self._get_database_display_str(verbosity, target_database_name),42 ))43 cursor.execute("DROP DATABASE %s" % self._quote_name(target_database_name))44 cursor.execute(creation_sql)45 except Exception as e:46 sys.stderr.write("Got an error cloning the test database: %s\n" % e)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!