Best Python code snippet using testcontainers-python_python
test_httpclient.py
Source:test_httpclient.py
...94 '%(error)s (HTTP 500)\n%(trace)s' % {'error': error_msg,95 'trace': error_trace},96 "%(error)s\n%(details)s" % {'error': str(error),97 'details': str(error.details)})98 def test_get_connection_params(self):99 endpoint = 'http://magnum-host:6385'100 expected = (HTTP_CLASS,101 ('magnum-host', 6385, ''),102 {'timeout': DEFAULT_TIMEOUT})103 params = http.HTTPClient.get_connection_params(endpoint)104 self.assertEqual(expected, params)105 def test_get_connection_params_with_trailing_slash(self):106 endpoint = 'http://magnum-host:6385/'107 expected = (HTTP_CLASS,108 ('magnum-host', 6385, ''),109 {'timeout': DEFAULT_TIMEOUT})110 params = http.HTTPClient.get_connection_params(endpoint)111 self.assertEqual(expected, params)112 def test_get_connection_params_with_ssl(self):113 endpoint = 'https://magnum-host:6385'114 expected = (HTTPS_CLASS,115 ('magnum-host', 6385, ''),116 {117 'timeout': DEFAULT_TIMEOUT,118 'ca_file': None,119 'cert_file': None,120 'key_file': None,121 'insecure': False,122 })123 params = http.HTTPClient.get_connection_params(endpoint)124 self.assertEqual(expected, params)125 def test_get_connection_params_with_ssl_params(self):126 endpoint = 'https://magnum-host:6385'127 ssl_args = {128 'ca_file': '/path/to/ca_file',129 'cert_file': '/path/to/cert_file',130 'key_file': '/path/to/key_file',131 'insecure': True,132 }133 expected_kwargs = {'timeout': DEFAULT_TIMEOUT}134 expected_kwargs.update(ssl_args)135 expected = (HTTPS_CLASS,136 ('magnum-host', 6385, ''),137 expected_kwargs)138 params = http.HTTPClient.get_connection_params(endpoint, **ssl_args)139 self.assertEqual(expected, params)140 def test_get_connection_params_with_timeout(self):141 endpoint = 'http://magnum-host:6385'142 expected = (HTTP_CLASS,143 ('magnum-host', 6385, ''),144 {'timeout': 300.0})145 params = http.HTTPClient.get_connection_params(endpoint, timeout=300)146 self.assertEqual(expected, params)147 def test_get_connection_params_with_version(self):148 endpoint = 'http://magnum-host:6385/v1'149 expected = (HTTP_CLASS,150 ('magnum-host', 6385, ''),151 {'timeout': DEFAULT_TIMEOUT})152 params = http.HTTPClient.get_connection_params(endpoint)153 self.assertEqual(expected, params)154 def test_get_connection_params_with_version_trailing_slash(self):155 endpoint = 'http://magnum-host:6385/v1/'156 expected = (HTTP_CLASS,157 ('magnum-host', 6385, ''),158 {'timeout': DEFAULT_TIMEOUT})159 params = http.HTTPClient.get_connection_params(endpoint)160 self.assertEqual(expected, params)161 def test_get_connection_params_with_subpath(self):162 endpoint = 'http://magnum-host:6385/magnum'163 expected = (HTTP_CLASS,164 ('magnum-host', 6385, '/magnum'),165 {'timeout': DEFAULT_TIMEOUT})166 params = http.HTTPClient.get_connection_params(endpoint)167 self.assertEqual(expected, params)168 def test_get_connection_params_with_subpath_trailing_slash(self):169 endpoint = 'http://magnum-host:6385/magnum/'170 expected = (HTTP_CLASS,171 ('magnum-host', 6385, '/magnum'),172 {'timeout': DEFAULT_TIMEOUT})173 params = http.HTTPClient.get_connection_params(endpoint)174 self.assertEqual(expected, params)175 def test_get_connection_params_with_subpath_version(self):176 endpoint = 'http://magnum-host:6385/magnum/v1'177 expected = (HTTP_CLASS,178 ('magnum-host', 6385, '/magnum'),179 {'timeout': DEFAULT_TIMEOUT})180 params = http.HTTPClient.get_connection_params(endpoint)181 self.assertEqual(expected, params)182 def test_get_connection_params_with_subpath_version_trailing_slash(self):183 endpoint = 'http://magnum-host:6385/magnum/v1/'184 expected = (HTTP_CLASS,185 ('magnum-host', 6385, '/magnum'),186 {'timeout': DEFAULT_TIMEOUT})187 params = http.HTTPClient.get_connection_params(endpoint)188 self.assertEqual(expected, params)189 def test_401_unauthorized_exception(self):190 error_body = _get_error_body()191 fake_resp = utils.FakeResponse({'content-type': 'text/plain'},192 six.StringIO(error_body),193 version=1,194 status=401)195 client = http.HTTPClient('http://localhost/')196 client.get_connection = (lambda *a,197 **kw: utils.FakeConnection(fake_resp))198 self.assertRaises(exc.Unauthorized, client.json_request,199 'GET', '/v1/resources')200class SessionClientTest(utils.BaseTestCase):201 def test_server_exception_msg_and_traceback(self):...
test_base.py
Source:test_base.py
...21 modifies self.settings_dict from django.db.backends.base.BaseDatabaseWrapper22 """23 num_threads = 1024 db_conn = VaultDatabaseWrapper(db_config)25 conn_params = db_conn.get_connection_params()26 def slow_get_conn_params():27 # Sleep for pseudo-random number of seconds in the range [0.0, 1.0)28 time.sleep(random.random())29 return conn_params30 # Patch the non-vault parent class's get_connection_params method:31 mocker.patch(32 "django_informixdb.base.DatabaseWrapper.get_connection_params",33 side_effect=slow_get_conn_params,34 )35 def get_conn_params_worker():36 db_conn.get_connection_params()37 threads = []38 for tnum in range(num_threads):39 threads.append(PropagatingThread(target=get_conn_params_worker))40 threads[tnum].start()41 # Because we're using PropagatingThread, calling join on each thread42 # will raise any exception which was raised within the thread,43 # e.g. KeyError: 'USER'44 for tnum in range(num_threads):...
config.py
Source:config.py
...4 from django.db import connection5 return connection.cursor()6def get_uri():7 from django.db import connection as db8 return "postgresql://"+db.get_connection_params()['user'] +":"+ db.get_connection_params()['password'] +"@"+ db.get_connection_params()['host']+":"+ db.get_connection_params()['port'] +'/'+db.get_connection_params()['database']9def get_max_cores():10 from django.conf import settings11 return settings.PARALLEL["MAX_THREADS"]12def get_max_rows():13 from django.conf import settings...
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!!