Best Python code snippet using tempest_python
test_legacy_mgmt_sqldatabase.py
Source:test_legacy_mgmt_sqldatabase.py
...42 except:43 pass44 return super(LegacyMgmtSqlDatabaseTest, self).tearDown()45 #--Helpers-----------------------------------------------------------------46 def _create_server(self):47 result = self.sqlms.create_server('azuredb', 'T5ii-B48x', 'West US')48 self.created_server = result.server_name49 def _server_exists(self, server_name):50 result = self.sqlms.list_servers()51 match = [s for s in result if s.name == server_name]52 return len(match) == 153 def _create_database(self, name):54 result = self.sqlms.create_database(55 self.created_server,56 name,57 'dd6d99bb-f193-4ec1-86f2-43d3bccbc49c',58 edition='Basic'59 )60 #--Operations for servers -------------------------------------------------61 @record62 def test_create_server(self):63 # Arrange64 # Act65 result = self.sqlms.create_server('azuredb', 'T5ii-B48x', 'West US')66 self.created_server = result.server_name67 # Assert68 self.assertGreater(len(result.server_name), 0)69 self.assertGreater(len(result.fully_qualified_domain_name), 0)70 self.assertTrue(self._server_exists(self.created_server))71 @record72 def test_set_server_admin_password(self):73 # Arrange74 self._create_server()75 # Act76 result = self.sqlms.set_server_admin_password(self.created_server, 'U6jj-C59y')77 # Assert78 self.assertIsNone(result)79 @record80 def test_delete_server(self):81 # Arrange82 self._create_server()83 # Act84 result = self.sqlms.delete_server(self.created_server)85 # Assert86 self.assertIsNone(result)87 self.assertFalse(self._server_exists(self.created_server))88 @record89 def test_list_servers(self):90 # Arrange91 self._create_server()92 # Act93 result = self.sqlms.list_servers()94 # Assert95 self.assertIsNotNone(result)96 self.assertIsInstance(result, Servers)97 for server in result:98 self.assertIsInstance(server, Server)99 match = [s for s in result if s.name == self.created_server][0]100 self.assertEqual(match.name, self.created_server)101 self.assertEqual(match.administrator_login, 'azuredb')102 self.assertEqual(match.location, 'West US')103 self.assertEqual(match.geo_paired_region, '')104 self.assertTrue(match.fully_qualified_domain_name.startswith(self.created_server))105 self.assertGreater(len(match.version), 0)106 @record107 def test_list_quotas(self):108 # Arrange109 self._create_server()110 # Act111 result = self.sqlms.list_quotas(self.created_server)112 # Assert113 self.assertIsNotNone(result)114 self.assertIsInstance(result, list)115 for quota in result:116 self.assertIsInstance(quota, ServerQuota)117 self.assertGreater(len(quota.name), 0)118 self.assertGreater(quota.value, 0)119 #--Operations for firewall rules ------------------------------------------120 @record121 def test_create_firewall_rule(self):122 # Arrange123 self._create_server()124 # Act125 result = self.sqlms.create_firewall_rule(self.created_server,126 'AllowAll',127 '192.168.144.0',128 '192.168.144.255')129 # Assert130 self.assertIsNone(result)131 @record132 def test_delete_firewall_rule(self):133 # Arrange134 self._create_server()135 result = self.sqlms.create_firewall_rule(self.created_server,136 'AllowAll',137 '192.168.144.0',138 '192.168.144.255')139 # Act140 result = self.sqlms.delete_firewall_rule(self.created_server,141 'AllowAll')142 # Assert143 self.assertIsNone(result)144 @record145 def test_update_firewall_rule(self):146 # Arrange147 self._create_server()148 result = self.sqlms.create_firewall_rule(self.created_server,149 'AllowAll',150 '192.168.144.0',151 '192.168.144.255')152 # Act153 result = self.sqlms.update_firewall_rule(self.created_server,154 'AllowAll',155 '192.168.116.0',156 '192.168.116.255')157 # Assert158 self.assertIsNone(result)159 @record160 def test_list_firewall_rules(self):161 # Arrange162 self._create_server()163 result = self.sqlms.create_firewall_rule(self.created_server,164 'AllowAll',165 '192.168.144.0',166 '192.168.144.255')167 # Act168 result = self.sqlms.list_firewall_rules(self.created_server)169 # Assert170 self.assertIsNotNone(result)171 self.assertIsInstance(result, list)172 for rule in result:173 self.assertIsInstance(rule, FirewallRule)174 @record175 def test_list_service_level_objectives(self):176 # Arrange177 self._create_server()178 # Act179 result = self.sqlms.list_service_level_objectives(self.created_server)180 # Assert181 self.assertIsNotNone(result)182 self.assertIsInstance(result, list)183 for rule in result:184 self.assertIsInstance(rule, ServiceObjective)185 @record186 def test_create_database(self):187 # Arrange188 self._create_server()189 # Act190 result = self.sqlms.create_database(191 self.created_server,192 'testdb',193 'dd6d99bb-f193-4ec1-86f2-43d3bccbc49c',194 edition='Basic'195 )196 # Assert197 self.assertIsNone(result)198 @record199 def test_delete_database(self):200 # Arrange201 self._create_server()202 self._create_database('temp')203 # Act204 result = self.sqlms.delete_database(self.created_server, 'temp')205 # Assert206 result = self.sqlms.list_databases(self.created_server)207 match = [d for d in result if d.name == 'temp']208 self.assertEqual(len(match), 0)209 @record210 def test_update_database(self):211 # Arrange212 self._create_server()213 self._create_database('temp')214 # Act215 result = self.sqlms.update_database(self.created_server,216 'temp',217 'newname')218 # Assert219 result = self.sqlms.list_databases(self.created_server)220 match = [d for d in result if d.name == 'newname']221 self.assertEqual(len(match), 1)222 @record223 def test_list_databases(self):224 # Arrange225 self._create_server()226 self._create_database('temp')227 # Act228 result = self.sqlms.list_databases(self.created_server)229 # Assert230 self.assertIsNotNone(result)231 self.assertIsInstance(result, list)232 for db in result:233 self.assertIsInstance(db, Database)234 match = [d for d in result if d.name == 'temp'][0]235 self.assertEqual(match.name, 'temp')236 self.assertEqual(match.state, 'Normal')237 self.assertGreater(match.max_size_bytes, 0)238 self.assertGreater(match.id, 0)239 self.assertGreater(len(match.edition), 0)...
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!!