Best Python code snippet using yandex-tank
test_ldap_rename_entries.py
Source:test_ldap_rename_entries.py
1from uuid import uuid42from .features import LdapTestCase, ROOT_DC3class TestLdapRenameEntries(LdapTestCase):4 def test_rename_user_entry(self):5 def prepare_test(con, context, data):6 user_uid = "user-%s" % uuid4()7 user_dn = "uid=%s,ou=people,%s" % (user_uid, ROOT_DC)8 user2_uid = "uid=user-%s" % uuid4()9 user2_dn = "%s,ou=people,%s" % (user2_uid, ROOT_DC)10 self.create_user(user_uid, user_dn)11 data["dn"] = user_dn12 data["new_uid"] = user2_uid13 data["new_dn"] = user2_dn14 def rename_dn_entry(con, context, data):15 return con.modify_dn(data['dn'], data['new_uid']), con.result16 def assert_dn_exists(con, context, data):17 self.assertEntryExists(18 data['new_dn'], None19 )20 def assert_dn_does_not_exists(con, context, data):21 entries = self.get_ldap_dn(data['new_dn'], None)22 self.assertTrue(23 len(entries) == 024 )25 test_suite = {26 'anonymous': {27 'assert': self.assertFalse,28 'run_before_test': prepare_test,29 'run_after_test': assert_dn_does_not_exists30 },31 'user': {32 'assert': self.assertFalse,33 'run_before_test': prepare_test,34 'run_after_test': assert_dn_does_not_exists,35 },36 'user-people-admin': {37 'assert': self.assertTrue,38 'run_before_test': prepare_test,39 'run_after_test': assert_dn_exists,40 },41 'user-apps-admin': {42 'assert': self.assertFalse,43 'run_before_test': prepare_test,44 'run_after_test': assert_dn_does_not_exists,45 },46 'user-admin': {47 'assert': self.assertTrue,48 'run_before_test': prepare_test,49 'run_after_test': assert_dn_exists,50 },51 'admin': {52 'assert': self.assertTrue,53 'run_before_test': prepare_test,54 'run_after_test': assert_dn_exists,55 },56 'app': {57 'assert': self.assertFalse,58 'run_before_test': prepare_test,59 'run_after_test': assert_dn_does_not_exists,60 },61 'app-people-admin': {62 'assert': self.assertTrue,63 'run_before_test': prepare_test,64 'run_after_test': assert_dn_exists,65 },66 'app-apps-admin': {67 'assert': self.assertFalse,68 'run_before_test': prepare_test,69 'run_after_test': assert_dn_does_not_exists,70 },71 'app-admin': {72 'assert': self.assertTrue,73 'run_before_test': prepare_test,74 'run_after_test': assert_dn_exists,75 },76 }77 self.run_case(78 rename_dn_entry,79 test_suite,80 "Test creating rename user dn"81 )82 def test_rename_app_entry(self):83 def prepare_test(con, context, data):84 app_uid = "app-%s" % uuid4()85 app_dn = "uid=%s,ou=applications,%s" % (app_uid, ROOT_DC)86 app2_uid = "uid=app-%s" % uuid4()87 app2_dn = "%s,ou=applications,%s" % (88 app2_uid, ROOT_DC89 )90 self.create_app(app_uid, app_dn)91 data["dn"] = app_dn92 data["new_uid"] = app2_uid93 data["new_dn"] = app2_dn94 def rename_dn_entry(con, context, data):95 return con.modify_dn(data['dn'], data['new_uid']), con.result96 def assert_dn_exists(con, context, data):97 self.assertEntryExists(98 data['new_dn'], None99 )100 def assert_dn_does_not_exists(con, context, data):101 entries = self.get_ldap_dn(data['new_dn'], None)102 self.assertTrue(103 len(entries) == 0104 )105 test_suite = {106 'anonymous': {107 'assert': self.assertFalse,108 'run_before_test': prepare_test,109 'run_after_test': assert_dn_does_not_exists110 },111 'user': {112 'assert': self.assertFalse,113 'run_before_test': prepare_test,114 'run_after_test': assert_dn_does_not_exists,115 },116 'user-people-admin': {117 'assert': self.assertFalse,118 'run_before_test': prepare_test,119 'run_after_test': assert_dn_does_not_exists,120 },121 'user-apps-admin': {122 'assert': self.assertTrue,123 'run_before_test': prepare_test,124 'run_after_test': assert_dn_exists,125 },126 'user-admin': {127 'assert': self.assertTrue,128 'run_before_test': prepare_test,129 'run_after_test': assert_dn_exists,130 },131 'admin': {132 'assert': self.assertTrue,133 'run_before_test': prepare_test,134 'run_after_test': assert_dn_exists,135 },136 'app': {137 'assert': self.assertFalse,138 'run_before_test': prepare_test,139 'run_after_test': assert_dn_does_not_exists,140 },141 'app-people-admin': {142 'assert': self.assertFalse,143 'run_before_test': prepare_test,144 'run_after_test': assert_dn_does_not_exists,145 },146 'app-apps-admin': {147 'assert': self.assertTrue,148 'run_before_test': prepare_test,149 'run_after_test': assert_dn_exists,150 },151 'app-admin': {152 'assert': self.assertTrue,153 'run_before_test': prepare_test,154 'run_after_test': assert_dn_exists,155 },156 }157 self.run_case(158 rename_dn_entry,159 test_suite,160 "Test creating rename app dn"161 )162 def test_rename_group_entry(self):163 def prepare_test(con, context, data):164 group_cn = "group-%s" % uuid4()165 group_dn = "cn=%s,ou=groups,%s" % (group_cn, ROOT_DC)166 group2_cn = "cn=group-%s" % uuid4()167 group2_dn = "%s,ou=groups,%s" % (group2_cn, ROOT_DC)168 self.create_group(169 group_cn, group_dn, ["uid=tuser,ou=people,%s" % ROOT_DC]170 )171 data["dn"] = group_dn172 data["new_cn"] = group2_cn173 data["new_dn"] = group2_dn174 def rename_dn_entry(con, context, data):175 return con.modify_dn(data['dn'], data['new_cn']), con.result176 def assert_dn_exists(con, context, data):177 self.assertEntryExists(178 data['new_dn'], None179 )180 def assert_dn_does_not_exists(con, context, data):181 entries = self.get_ldap_dn(data['new_dn'], None)182 self.assertTrue(183 len(entries) == 0184 )185 test_suite = {186 'anonymous': {187 'assert': self.assertFalse,188 'run_before_test': prepare_test,189 'run_after_test': assert_dn_does_not_exists190 },191 'user': {192 'assert': self.assertFalse,193 'run_before_test': prepare_test,194 'run_after_test': assert_dn_does_not_exists,195 },196 'user-people-admin': {197 'assert': self.assertTrue,198 'run_before_test': prepare_test,199 'run_after_test': assert_dn_exists,200 },201 'user-apps-admin': {202 'assert': self.assertFalse,203 'run_before_test': prepare_test,204 'run_after_test': assert_dn_does_not_exists,205 },206 'user-admin': {207 'assert': self.assertTrue,208 'run_before_test': prepare_test,209 'run_after_test': assert_dn_exists,210 },211 'admin': {212 'assert': self.assertTrue,213 'run_before_test': prepare_test,214 'run_after_test': assert_dn_exists,215 },216 'app': {217 'assert': self.assertFalse,218 'run_before_test': prepare_test,219 'run_after_test': assert_dn_does_not_exists,220 },221 'app-people-admin': {222 'assert': self.assertTrue,223 'run_before_test': prepare_test,224 'run_after_test': assert_dn_exists,225 },226 'app-apps-admin': {227 'assert': self.assertFalse,228 'run_before_test': prepare_test,229 'run_after_test': assert_dn_does_not_exists,230 },231 'app-admin': {232 'assert': self.assertTrue,233 'run_before_test': prepare_test,234 'run_after_test': assert_dn_exists,235 },236 }237 self.run_case(238 rename_dn_entry,239 test_suite,240 "Test creating rename group dn"241 )242 def test_rename_policy_entry(self):243 def prepare_test(con, context, data):244 policy_cn = "policy-%s" % uuid4()245 policy_dn = "cn=%s,ou=policies,%s" % (policy_cn, ROOT_DC)246 policy2_cn = "cn=policy-%s" % uuid4()247 policy2_dn = "%s,ou=policies,%s" % (policy2_cn, ROOT_DC)248 self.create_policy(policy_cn, policy_dn)249 data["dn"] = policy_dn250 data["new_cn"] = policy2_cn251 data["new_dn"] = policy2_dn252 def rename_dn_entry(con, context, data):253 return con.modify_dn(data['dn'], data['new_cn']), con.result254 def assert_dn_exists(con, context, data):255 self.assertEntryExists(256 data['new_dn'], None257 )...
test_ldap_delete_entries.py
Source:test_ldap_delete_entries.py
1from uuid import uuid42from .features import LdapTestCase, ROOT_DC3class TestLdapRemoveEntries(LdapTestCase):4 def test_remove_app_entry(self):5 def prepare_test(con, context, data):6 user_uid = "user-%s" % uuid4()7 user_dn = "uid=%s,ou=applications,%s" % (user_uid, ROOT_DC)8 self.create_app(user_uid, user_dn)9 data["dn"] = user_dn10 def delete_dn_entry(con, context, data):11 return con.delete(data['dn']), con.result12 def assert_dn_exists(con, context, data):13 self.assertEntryExists(14 data['dn'], None15 )16 def assert_dn_does_not_exists(con, context, data):17 entries = self.get_ldap_dn(data['dn'], None)18 self.assertTrue(19 len(entries) == 020 )21 test_suite = {22 'anonymous': {23 'assert': self.assertFalse,24 'run_before_test': prepare_test,25 'run_after_test': assert_dn_exists26 },27 'user': {28 'assert': self.assertFalse,29 'run_before_test': prepare_test,30 'run_after_test': assert_dn_exists,31 },32 'user-people-admin': {33 'assert': self.assertFalse,34 'run_before_test': prepare_test,35 'run_after_test': assert_dn_exists,36 },37 'user-apps-admin': {38 'assert': self.assertTrue,39 'run_before_test': prepare_test,40 'run_after_test': assert_dn_does_not_exists,41 },42 'user-admin': {43 'assert': self.assertTrue,44 'run_before_test': prepare_test,45 'run_after_test': assert_dn_does_not_exists,46 },47 'admin': {48 'assert': self.assertTrue,49 'run_before_test': prepare_test,50 'run_after_test': assert_dn_does_not_exists,51 },52 'app': {53 'assert': self.assertFalse,54 'run_before_test': prepare_test,55 'run_after_test': assert_dn_exists,56 },57 'app-people-admin': {58 'assert': self.assertFalse,59 'run_before_test': prepare_test,60 'run_after_test': assert_dn_exists,61 },62 'app-apps-admin': {63 'assert': self.assertTrue,64 'run_before_test': prepare_test,65 'run_after_test': assert_dn_does_not_exists,66 },67 'app-admin': {68 'assert': self.assertTrue,69 'run_before_test': prepare_test,70 'run_after_test': assert_dn_does_not_exists,71 },72 }73 self.run_case(74 delete_dn_entry,75 test_suite,76 "Test creating delete user dn"77 )78 def test_remove_group_entry(self):79 def prepare_test(con, context, data):80 group_cn = "group-%s" % uuid4()81 group_dn = "cn=%s,ou=groups,%s" % (group_cn, ROOT_DC)82 self.create_group(83 group_cn,84 group_dn,85 members=["uid=tuser2,ou=people," + ROOT_DC]86 )87 data["dn"] = group_dn88 def delete_dn_entry(con, context, data):89 return con.delete(data['dn']), con.result90 def assert_dn_exists(con, context, data):91 self.assertEntryExists(92 data['dn'], None93 )94 def assert_dn_does_not_exists(con, context, data):95 entries = self.get_ldap_dn(data['dn'], None)96 self.assertTrue(97 len(entries) == 098 )99 test_suite = {100 'anonymous': {101 'assert': self.assertFalse,102 'run_before_test': prepare_test,103 'run_after_test': assert_dn_exists104 },105 'user': {106 'assert': self.assertFalse,107 'run_before_test': prepare_test,108 'run_after_test': assert_dn_exists,109 },110 'user-people-admin': {111 'assert': self.assertTrue,112 'run_before_test': prepare_test,113 'run_after_test': assert_dn_does_not_exists,114 },115 'user-apps-admin': {116 'assert': self.assertFalse,117 'run_before_test': prepare_test,118 'run_after_test': assert_dn_exists,119 },120 'user-admin': {121 'assert': self.assertTrue,122 'run_before_test': prepare_test,123 'run_after_test': assert_dn_does_not_exists,124 },125 'admin': {126 'assert': self.assertTrue,127 'run_before_test': prepare_test,128 'run_after_test': assert_dn_does_not_exists,129 },130 'app': {131 'assert': self.assertFalse,132 'run_before_test': prepare_test,133 'run_after_test': assert_dn_exists,134 },135 'app-people-admin': {136 'assert': self.assertTrue,137 'run_before_test': prepare_test,138 'run_after_test': assert_dn_does_not_exists,139 },140 'app-apps-admin': {141 'assert': self.assertFalse,142 'run_before_test': prepare_test,143 'run_after_test': assert_dn_exists,144 },145 'app-admin': {146 'assert': self.assertTrue,147 'run_before_test': prepare_test,148 'run_after_test': assert_dn_does_not_exists,149 },150 }151 self.run_case(152 delete_dn_entry,153 test_suite,154 "Test creating delete user dn"155 )156 def test_remove_policy_entry(self):157 def prepare_test(con, context, data):158 policy_cn = "policy-%s" % uuid4()159 policy_dn = "cn=%s,ou=policies,%s" % (policy_cn, ROOT_DC)160 self.create_policy(policy_cn, policy_dn)161 data["dn"] = policy_dn162 def delete_dn_entry(con, context, data):163 return con.delete(data['dn']), con.result164 def assert_dn_exists(con, context, data):165 self.assertEntryExists(166 data['dn'], None167 )168 def assert_dn_does_not_exists(con, context, data):169 entries = self.get_ldap_dn(data['dn'], None)170 self.assertTrue(171 len(entries) == 0172 )173 test_suite = {174 'anonymous': {175 'assert': self.assertFalse,176 'run_before_test': prepare_test,177 'run_after_test': assert_dn_exists178 },179 'user': {180 'assert': self.assertFalse,181 'run_before_test': prepare_test,182 'run_after_test': assert_dn_exists,183 },184 'user-people-admin': {185 'assert': self.assertFalse,186 'run_before_test': prepare_test,187 'run_after_test': assert_dn_exists,188 },189 'user-apps-admin': {190 'assert': self.assertFalse,191 'run_before_test': prepare_test,192 'run_after_test': assert_dn_exists,193 },194 'user-admin': {195 'assert': self.assertFalse,196 'run_before_test': prepare_test,197 'run_after_test': assert_dn_exists,198 },199 'admin': {200 'assert': self.assertTrue,201 'run_before_test': prepare_test,202 'run_after_test': assert_dn_does_not_exists,203 },204 'app': {205 'assert': self.assertFalse,206 'run_before_test': prepare_test,207 'run_after_test': assert_dn_exists,208 },209 'app-people-admin': {210 'assert': self.assertFalse,211 'run_before_test': prepare_test,212 'run_after_test': assert_dn_exists,213 },214 'app-apps-admin': {215 'assert': self.assertFalse,216 'run_before_test': prepare_test,217 'run_after_test': assert_dn_exists,218 },219 'app-admin': {220 'assert': self.assertFalse,221 'run_before_test': prepare_test,222 'run_after_test': assert_dn_exists,223 },224 }225 self.run_case(226 delete_dn_entry,227 test_suite,228 "Test creating delete user dn"229 )230 def test_remove_user_entry(self):231 def prepare_test(con, context, data):232 user_uid = "user-%s" % uuid4()233 user_dn = "uid=%s,ou=people,%s" % (user_uid, ROOT_DC)234 self.create_user(user_uid, user_dn)235 data["dn"] = user_dn236 def delete_dn_entry(con, context, data):237 return con.delete(data['dn']), con.result238 def assert_dn_exists(con, context, data):239 self.assertEntryExists(240 data['dn'], None241 )242 def assert_dn_does_not_exists(con, context, data):243 entries = self.get_ldap_dn(data['dn'], None)244 self.assertTrue(245 len(entries) == 0...
tests.py
Source:tests.py
...8"""9run_test = """10RET['code_result'] = {}11"""12def prepare_test(test="", answer=None, middle_code="", show_code=None):13 if show_code is None:14 show_code = middle_code + "\n" + test15 if not test:16 return_code = "\nRET['code_result'] = ''"17 answer = ''18 else:19 return_code = run_test.format(test)20 return {"test_code": {"python-3": init_code + middle_code + return_code},21 "show": {"python-3": show_code},22 "answer": answer}23TESTS = {24 "1. Add": [25 prepare_test(middle_code="calc = SimpleCalculator()",26 test="calc.add(1, 5, 0.3)",27 answer=6.3)28 ],29 "2. Sub": [30 prepare_test(middle_code="calc = SimpleCalculator()",31 test="calc.sub(99, -1)",32 answer=100)33 ],34 "3. Add": [35 prepare_test(middle_code='''calc = SimpleCalculator()36calc = ComplexCalculator(calc)37''',38 test="calc.add(10, 9, -19)",39 answer=0)40 ],41 "4. Sub": [42 prepare_test(middle_code='''calc = SimpleCalculator()43calc = ComplexCalculator(calc)44''',45 test="calc.sub(114, 14.1)",46 answer=99.9)47 ],48 "5. Multi": [49 prepare_test(middle_code='''calc = SimpleCalculator()50calc = ComplexCalculator(calc)51''',52 test="calc.multi(2, 5, 3.1415926)",53 answer=31.41593)54 ],55 "6. Div": [56 prepare_test(middle_code='''calc = SimpleCalculator()57calc = ComplexCalculator(calc)58''',59 test="calc.div(2, 3)",60 answer=0.66667)61 ],62 "7. Power": [63 prepare_test(middle_code='''calc = SimpleCalculator()64calc = ComplexCalculator(calc)65''',66 test="calc.power(2, 10)",67 answer=1024)68 ],69 "8. Root": [70 prepare_test(middle_code='''calc = SimpleCalculator()71calc = ComplexCalculator(calc)72''',73 test="calc.root(81, 4)",74 answer=3)75 ],76 "9. Add": [77 prepare_test(middle_code="calc = SimpleCalculator()",78 test="calc.add(34, 5, 0.23456789)",79 answer=39.23457)80 ],81 "10. Sub": [82 prepare_test(middle_code="calc = SimpleCalculator()",83 test="calc.sub(11, 12.5)",84 answer=-1.5)85 ],86 "11. Add": [87 prepare_test(middle_code='''calc = SimpleCalculator()88calc = ComplexCalculator(calc)89''',90 test="calc.add(500, -499, -11)",91 answer=-10)92 ],93 "12. Sub": [94 prepare_test(middle_code='''calc = SimpleCalculator()95calc = ComplexCalculator(calc)96''',97 test="calc.sub(254, 100)",98 answer=154)99 ],100 "13. Multi": [101 prepare_test(middle_code='''calc = SimpleCalculator()102calc = ComplexCalculator(calc)103''',104 test="calc.multi(32, 17, 566, 0.1)",105 answer=39790.4)106 ],107 "14. Div": [108 prepare_test(middle_code='''calc = SimpleCalculator()109calc = ComplexCalculator(calc)110''',111 test="calc.div(22, 7)",112 answer=3.14286)113 ],114 "15. Power": [115 prepare_test(middle_code='''calc = SimpleCalculator()116calc = ComplexCalculator(calc)117''',118 test="calc.power(100, 0.5)",119 answer=10)120 ],121 "16. Root": [122 prepare_test(middle_code='''calc = SimpleCalculator()123calc = ComplexCalculator(calc)124''',125 test="calc.root(33, 3.5)",126 answer=2.71557)127 ]...
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!!