Best Python code snippet using autotest_python
readonly_connection.py
Source:readonly_connection.py
...31 if self._connection is not None:32 return33 self._save_django_state()34 self._connection = self._get_readonly_connection()35 self._restore_django_state()36 def _save_django_state(self):37 self._old_connection = django_db.connection.connection38 _default_db = settings.DATABASES['default']39 self._old_host = _default_db['HOST']40 self._old_username = _default_db['USER']41 self._old_password = _default_db['PASSWORD']42 def _restore_django_state(self):43 django_db.connection.connection = self._old_connection44 _default_db = settings.DATABASES['default']45 _default_db['HOST'] = self._old_host46 _default_db['USER'] = self._old_username47 _default_db['PASSWORD'] = self._old_password48 def _get_readonly_connection(self):49 _default_db = settings.DATABASES['default']50 _default_db['HOST'] = _default_db['READONLY_HOST']51 _default_db['USER'] = _default_db['READONLY_USER']52 _default_db['PASSWORD'] = _default_db['READONLY_PASSWORD']53 reload(django_db)54 # cursor() causes a new connection to be created55 cursor = django_db.connection.cursor()56 assert django_db.connection.connection is not None...
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!!