Best Python code snippet using mailosaur-python_python
test_compute.py
Source:test_compute.py
...29 url = vm.get_model_view_url()30 response = self.client.get(url)31 self.assertEqual(response.status_code, 200)32 self.assertJSONEqual(response.content, vm.model_view)33 def test_not_found(self):34 vm = factories.VirtualMachineFactory()35 base_url = vm.get_model_view_url()36 # Bad subscription37 url = base_url.replace(vm.resource_group.subscription.uuid, faker.uuid4())38 response = self.client.get(url)39 self.assertEqual(response.status_code, 404)40 # Bad resource group41 url = base_url.replace(vm.resource_group.name, 'bar')42 response = self.client.get(url)43 self.assertEqual(response.status_code, 404)44 # Bad VM name45 url = base_url.replace(vm.name, 'ham')46 response = self.client.get(url)47 self.assertEqual(response.status_code, 404)48class VirtualMachineViewDeleteTest(TestCase):49 def test_delete(self):50 vm = factories.VirtualMachineFactory()51 url = vm.get_model_view_url()52 response = self.client.delete(url)53 self.assertEqual(response.status_code, 202)54 exists = models.VirtualMachine.objects.filter(id=vm.id).exists()55 self.assertFalse(exists)56 def test_not_found(self):57 vm = factories.VirtualMachineFactory()58 base_url = vm.get_model_view_url()59 # Bad subscription60 url = base_url.replace(vm.resource_group.subscription.uuid, faker.uuid4())61 response = self.client.delete(url)62 self.assertEqual(response.status_code, 404)63 # Bad resource group64 url = base_url.replace(vm.resource_group.name, 'bar')65 response = self.client.delete(url)66 self.assertEqual(response.status_code, 404)67 # Bad VM name68 url = base_url.replace(vm.name, 'ham')69 response = self.client.delete(url)70 self.assertEqual(response.status_code, 404)71 # Nothin has been deleted72 exists = models.VirtualMachine.objects.filter(id=vm.id).exists()73 self.assertTrue(exists)74class VirtualMachineDeleteViewTest(TestCase):75 def test_get(self):76 vm = factories.VirtualMachineFactory()77 url = vm.get_model_view_url()78 response = self.client.get(url)79 self.assertEqual(response.status_code, 200)80 self.assertJSONEqual(response.content, vm.model_view)81 def test_not_found(self):82 vm = factories.VirtualMachineFactory()83 base_url = vm.get_model_view_url()84 # Bad subscription85 url = base_url.replace(vm.resource_group.subscription.uuid, faker.uuid4())86 response = self.client.get(url)87 self.assertEqual(response.status_code, 404)88 # Bad resource group89 url = base_url.replace(vm.resource_group.name, 'bar')90 response = self.client.get(url)91 self.assertEqual(response.status_code, 404)92 # Bad VM name93 url = base_url.replace(vm.name, 'ham')94 response = self.client.get(url)95 self.assertEqual(response.status_code, 404)96class VirtualMachineGetInstanceViewViewTest(TestCase):97 def test_get(self):98 vm = factories.VirtualMachineFactory()99 url = vm.get_instance_view_url()100 response = self.client.get(url)101 self.assertEqual(response.status_code, 200)102 self.assertJSONEqual(response.content, vm.instance_view)103 def test_not_found(self):104 vm = factories.VirtualMachineFactory()105 base_url = vm.get_instance_view_url()106 # Bad subscription107 url = base_url.replace(vm.resource_group.subscription.uuid, faker.uuid4())108 response = self.client.get(url)109 self.assertEqual(response.status_code, 404)110 # Bad resource group111 url = base_url.replace(vm.resource_group.name, 'bar')112 response = self.client.get(url)113 self.assertEqual(response.status_code, 404)114 # Bad VM name115 url = base_url.replace(vm.name, 'ham')116 response = self.client.get(url)117 self.assertEqual(response.status_code, 404)118class VirtualMachineListView(TestCase):119 def test_get(self):120 resource_group_name = faker.word()121 vms = factories.VirtualMachineFactory.create_batch(3, resource_group__name=resource_group_name)122 url = vms[0].get_list_url()123 response = self.client.get(url)124 self.assertEqual(response.status_code, 200)125 content = json.loads(response.content)126 for dbvm, vm in zip(vms, content['value']):127 self.assertEqual(dbvm.model_view, vm)128 def test_not_found(self):129 vms = factories.VirtualMachineFactory.create_batch(3)130 base_url = vms[0].get_list_url()131 # Bad subscription132 url = base_url.replace(vms[0].resource_group.subscription.uuid, faker.uuid4())133 response = self.client.get(url)134 self.assertEqual(response.status_code, 404)135 # Bad resource group136 url = base_url.replace(vms[0].resource_group.name, 'bar')137 response = self.client.get(url)...
session_test.py
Source:session_test.py
...48 with self.mysql.dao.create_session() as session:49 user = session.execute_for_first("select * from user")50 self.assertEqual(1, user.id)51 52 def test_not_found(self):53 with self.mysql.dao.create_session() as session:54 user = session.execute_for_first("select * from user where id=0")55 self.assertIsNone(user)56 57class ExecuteForOneTest(DbTest):58 def test_success(self):59 with self.mysql.dao.create_session() as session:60 user = session.execute_for_one("select * from user")61 self.assertEqual(1, user.id)62 63 def test_not_found(self):64 with self.assertRaises(DbError):65 with self.mysql.dao.create_session() as session:66 session.execute_for_one("select * from user where id=0")67 68class ExecuteForScalarTest(DbTest):69 def test_success(self):70 with self.mysql.dao.create_session() as session:71 result = session.execute_for_scalar("select name from user where id=1")72 self.assertEqual('user1', result)73 74 def test_not_found(self):75 with self.assertRaises(DbError):76 with self.mysql.dao.create_session() as session:77 session.execute_for_scalar("select name from user where id=3")78 79 def test_multi_rows(self):80 with self.assertRaises(DbError):81 with self.mysql.dao.create_session() as session:82 session.execute_for_scalar("select name from user")83 84class GetTest(DbTest):85 def test_found(self):86 with self.mysql.dao.create_session() as session:87 user = session.get(User, 1)88 self.assertEqual('user1', user.name)89 90 def test_not_found(self):91 with self.mysql.dao.create_session() as session:92 user = session.get(User, 3)93 self.assertIsNone(user)94 95class GetOrCreateTest(DbTest):96 def test_found(self):97 with self.mysql.dao.create_session() as session:98 user = session.get_or_create(User, 1)99 self.assertEqual(1, user.id)100 self.assertEqual('user1', user.name)101 102 def test_not_found(self):103 # test104 with self.mysql.dao.create_session() as session:105 user = session.get_or_create(User, 3)106 self.assertEqual(3, user.id)107 self.assertIsNone(user.name)108 user.name = 'user3'109 110 # verify111 with self.mysql.dao.create_session() as session:112 user = session.get(User, 3)113 self.assertEqual('user3', user.name)114 115class LoadTest(DbTest):116 def test_found(self):117 with self.mysql.dao.create_session() as session:118 user = session.load(User, 1)119 self.assertEqual('user1', user.name)120 121 def test_not_found(self):122 with self.assertRaises(DbError):123 with self.mysql.dao.create_session() as session:124 session.load(User, 3)...
oas.py
Source:oas.py
1import requests as re2from sty import fg, rs, bg, ef3# GLOBALS4WRONG_CHOICE = True5TEST_NOT_FOUND = True6# BANNER7banner = '''8 Fuck LPU!!9....................../´¯/) 10....................,/¯../ 11.................../..../ 12............./´¯/'...'/´¯¯`·¸ 13........../'/.../..../......./¨¯\ 14........('(...´...´.... ¯~/'...') 15.........\.................'...../ 16..........''...\.......... _.·´ 17............\..............( 18..............\.............\...19'''20# PAYLOADS21payload = {22 'LoginId': None,23 'RoleId': 3,24 'IsDemo': 025}26q_payload = {27 'TestId': None,28 'Set': 1,29 'LoginId': None30}31o_payload = {32 'QuestionId': None33}34# HEADERS35headers = {36 'Referer': 'oas.lpu.in'37}38# HELPER FUNCTIONS39def getTest(test_id):40 global TEST_NOT_FOUND41 query = re.get('https://oas.lpu.in/api/OnlineExam/GetTestToAttemptDetail', params=payload, headers={'Referer':'oas.lpu.in'})42 result = query.json()43 print(f'{fg.yellow}searching for the test{fg.rs}...')44 for item in result:45 if item['TestId'] == test_id:46 print(f'{fg.green}caught the test!{fg.rs}')47 TEST_NOT_FOUND = False48 break49 if TEST_NOT_FOUND:50 print(f'{fg.red}TEST NOT FOUND... Make sure that test is available{fg.rs}')51 quit()52def getTestId(test_name):53 global TEST_NOT_FOUND54 query = re.get('https://oas.lpu.in/api/OnlineExam/GetTestToAttemptDetail', params=payload, headers={'Referer':'oas.lpu.in'})55 result = query.json()56 print(f'{fg.yellow}searching for the test{fg.rs}...')57 for item in result:58 if item['TestName'] == test_name:59 test_id = item['TestId']60 print(f'{fg.green}caught the test!{fg.rs}')61 TEST_NOT_FOUND = False62 break63 if TEST_NOT_FOUND:64 print(f'{fg.red}TEST NOT FOUND... Make sure that test is available{fg.rs}')65 quit()66 return test_id67def getQuestionsAndAnswers():68 print(f'{fg.yellow}extracting question details...{fg.rs}')69 query = re.get('https://oas.lpu.in/api/OnlineExam/GetQuestionNumbersDetail', params=q_payload, headers={'Referer':'oas.lpu.in'})70 result = query.json()71 print(f'{fg.green}done!{fg.rs}')72 print(f'{fg.blue}fetching answers...{fg.rs}')73 for item in result:74 correct_option = None75 correct_option_answer = None76 o_payload['QuestionId'] = item['QuestionId']77 query = re.get('https://oas.lpu.in/api/OnlineExam/GetQuestionOptionEditDetail', headers={'Referer':'oas.lpu.in'}, params=o_payload)78 result = query.json()79 for option_no, option in enumerate(result, start=1):80 if option['IsRightAnswer'] == 'True':81 correct_option = option_no82 correct_option_answer = option['OptionDescription']83 break84 print(f"[\'Q{item['QuestionNo']})\', \'Option {correct_option}', \'{correct_option_answer}' ]")85if __name__ == "__main__":86 print(banner)87 reg_id = int(input("registration id: "))88 payload['LoginId'] = reg_id89 q_payload['LoginId'] = reg_id90 while(WRONG_CHOICE):91 test_option = int(input("OPTION: 1) test id\t 2) test name: \t"))92 if test_option == 1:93 test_id = int(input("test id: "))94 q_payload['TestId'] = test_id95 getTest(test_id)96 getQuestionsAndAnswers()97 WRONG_CHOICE = False98 99 elif test_option == 2:100 101 test_name = input("test name: ")102 test_id = getTestId(test_name)103 q_payload['TestId'] = test_id104 getTest(test_id)105 getQuestionsAndAnswers()106 WRONG_CHOICE = False107 108 else:...
test_settings.py
Source:test_settings.py
2from ..settings import *3class TestKwargWithDefault(TestCase):4 def test_found(self):5 self.assertEqual(get_kwarg_with_default({'a': 1}, 'a'), 1)6 def test_not_found(self):7 self.assertFalse(get_kwarg_with_default({'a': 1}, 'markdown'))8class TestTagRenderStyle(TestCase):9 def test_inline_default(self):10 self.assertEqual(get_tag_render_style({}, 'i'), RENDER_INLINE)11 def test_block_default(self):12 self.assertEqual(get_tag_render_style({}, 'p'), RENDER_BLOCK)13 def test_according_to_children_default(self):14 self.assertEqual(get_tag_render_style({}, 'del'), RENDER_ACCORDING_TO_CHILDREN)15 def test_override_with_kwargs(self):16 self.assertEqual(17 get_tag_render_style({'del_render_style': RENDER_BLOCK}, 'del'),18 RENDER_BLOCK19 )20 def test_not_found(self):21 self.assertEqual(get_tag_render_style({}, 'foo'), RENDER_BLOCK)22 def test_upper_case(self):23 self.assertEqual(24 get_tag_render_style(25 {'foo_render_style': RENDER_INLINE},26 'FOO'27 ),28 RENDER_INLINE29 )30 def test_not_found(self):31 self.assertEqual(32 get_tag_render_style(33 {'unknown_element_render_style': RENDER_ACCORDING_TO_CHILDREN},34 'foo'35 ),36 RENDER_ACCORDING_TO_CHILDREN...
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!!