Best Python code snippet using lisa_python
test_result_backend_connection_secret.py
Source:test_result_backend_connection_secret.py
...47 values={"executor": executor},48 show_only=["templates/secrets/result-backend-connection-secret.yaml"],49 )50 assert expected_doc_count == len(docs)51 def _get_connection(self, values: dict) -> str:52 docs = render_chart(53 values=values,54 show_only=["templates/secrets/result-backend-connection-secret.yaml"],55 )56 encoded_connection = jmespath.search("data.connection", docs[0])57 return base64.b64decode(encoded_connection).decode()58 def test_default_connection(self):59 connection = self._get_connection({})60 assert (61 "db+postgresql://postgres:postgres@RELEASE-NAME-postgresql:5432/postgres?sslmode=disable"62 == connection63 )64 def test_should_default_to_custom_metadata_db_connection_with_pgbouncer_overrides(self):65 values = {66 "pgbouncer": {"enabled": True},67 "data": {"metadataConnection": {**self.non_chart_database_values}},68 }69 connection = self._get_connection(values)70 # host, port, dbname still get overridden71 assert (72 "db+postgresql://someuser:somepass@RELEASE-NAME-pgbouncer:6543"73 "/RELEASE-NAME-result-backend?sslmode=allow" == connection74 )75 def test_should_set_pgbouncer_overrides_when_enabled(self):76 values = {"pgbouncer": {"enabled": True}}77 connection = self._get_connection(values)78 # host, port, dbname get overridden79 assert (80 "db+postgresql://postgres:postgres@RELEASE-NAME-pgbouncer:6543"81 "/RELEASE-NAME-result-backend?sslmode=disable" == connection82 )83 def test_should_set_pgbouncer_overrides_with_non_chart_database_when_enabled(self):84 values = {85 "pgbouncer": {"enabled": True},86 "data": {"resultBackendConnection": {**self.non_chart_database_values}},87 }88 connection = self._get_connection(values)89 # host, port, dbname still get overridden even with an non-chart db90 assert (91 "db+postgresql://someuser:somepass@RELEASE-NAME-pgbouncer:6543"92 "/RELEASE-NAME-result-backend?sslmode=allow" == connection93 )94 def test_should_default_to_custom_metadata_db_connection(self):95 values = {96 "data": {"metadataConnection": {**self.non_chart_database_values}},97 }98 connection = self._get_connection(values)99 assert "db+postgresql://someuser:somepass@somehost:7777/somedb?sslmode=allow" == connection100 def test_should_correctly_use_non_chart_database(self):101 values = {"data": {"resultBackendConnection": {**self.non_chart_database_values}}}102 connection = self._get_connection(values)103 assert "db+postgresql://someuser:somepass@somehost:7777/somedb?sslmode=allow" == connection104 def test_should_support_non_postgres_db(self):105 values = {106 "data": {107 "resultBackendConnection": {108 **self.non_chart_database_values,109 "protocol": "mysql",110 }111 }112 }113 connection = self._get_connection(values)114 # sslmode is only added for postgresql115 assert "db+mysql://someuser:somepass@somehost:7777/somedb" == connection116 def test_should_correctly_use_non_chart_database_when_both_db_are_external(self):117 values = {118 "data": {119 "metadataConnection": {**self.non_chart_database_values},120 "resultBackendConnection": {121 **self.non_chart_database_values,122 "user": "anotheruser",123 "pass": "anotherpass",124 },125 }126 }127 connection = self._get_connection(values)128 assert "db+postgresql://anotheruser:anotherpass@somehost:7777/somedb?sslmode=allow" == connection129 def test_should_correctly_handle_password_with_special_characters(self):130 values = {131 "data": {132 "resultBackendConnection": {133 **self.non_chart_database_values,134 "user": "username@123123",135 "pass": "password@!@#$^&*()",136 },137 }138 }139 connection = self._get_connection(values)140 assert (141 "db+postgresql://username%40123123:password%40%21%40%23$%5E&%2A%28%29@somehost:7777/"142 "somedb?sslmode=allow" == connection...
test_mongodb.py
Source:test_mongodb.py
...4class MockConnection(dict):5 def __setattr__(self, key, value):6 self[key] = value7class test_mongodb(Case):8 def _get_connection(self, url, **kwargs):9 from kombu.transport import mongodb10 class Transport(mongodb.Transport):11 Connection = MockConnection12 return Connection(url, transport=Transport, **kwargs).connect()13 @skip_if_not_module('pymongo')14 def test_defaults(self):15 url = 'mongodb://'16 c = self._get_connection(url)17 hostname, dbname, options = c.channels[0]._parse_uri()18 self.assertEquals(dbname, 'kombu_default')19 self.assertEquals(hostname, 'mongodb://127.0.0.1')20 @skip_if_not_module('pymongo')21 def test_custom_host(self):22 url = 'mongodb://localhost'23 c = self._get_connection(url)24 hostname, dbname, options = c.channels[0]._parse_uri()25 self.assertEquals(dbname, 'kombu_default')26 @skip_if_not_module('pymongo')27 def test_custom_database(self):28 url = 'mongodb://localhost/dbname'29 c = self._get_connection(url)30 hostname, dbname, options = c.channels[0]._parse_uri()31 self.assertEquals(dbname, 'dbname')32 @skip_if_not_module('pymongo')33 def test_custom_credentions(self):34 url = 'mongodb://localhost/dbname'35 c = self._get_connection(url, userid='foo', password='bar')36 hostname, dbname, options = c.channels[0]._parse_uri()37 self.assertEquals(hostname, 'mongodb://foo:bar@localhost/dbname')38 self.assertEquals(dbname, 'dbname')39 @skip_if_not_module('pymongo')40 def test_options(self):41 url = 'mongodb://localhost,localhost2:29017/dbname?safe=true'42 c = self._get_connection(url)43 hostname, dbname, options = c.channels[0]._parse_uri()44 self.assertEqual(options['safe'], True)45 @skip_if_not_module('pymongo')46 def test_real_connections(self):47 from pymongo.errors import ConfigurationError48 raise SkipTest(49 'Test is functional: it actually connects to mongod')50 url = 'mongodb://localhost,localhost:29017/dbname'51 c = self._get_connection(url)52 client = c.channels[0].client53 nodes = client.connection.nodes54 # If there's just 1 node it is because we're connecting to a single55 # server instead of a repl / mongoss.56 if len(nodes) == 2:57 self.assertTrue(('localhost', 29017) in nodes)58 self.assertEquals(client.name, 'dbname')59 url = 'mongodb://localhost:27017,localhost2:29017/dbname'60 c = self._get_connection(url)61 client = c.channels[0].client62 # Login to admin db since there's no db specified63 url = 'mongodb://adminusername:adminpassword@localhost'64 c = self._get_connection()65 client = c.channels[0].client66 self.assertEquals(client.name, 'kombu_default')67 # Lets make sure that using admin db doesn't break anything68 # when no user is specified69 url = 'mongodb://localhost'70 c = self._get_connection(url)71 client = c.channels[0].client72 # Assuming there's user 'username' with password 'password'73 # configured in mongodb74 url = 'mongodb://username:password@localhost/dbname'75 c = self._get_connection(url)76 client = c.channels[0].client77 # Assuming there's no user 'nousername' with password 'nopassword'78 # configured in mongodb79 url = 'mongodb://nousername:nopassword@localhost/dbname'80 c = self._get_connection(url)81 with self.assertRaises(ConfigurationError):...
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!!