Best Python code snippet using toolium_python
test_system.py
Source:test_system.py
...51 s.take_volume_offline(volume_name)52 finally:53 s.destroy_volume(volume_name)54 def login_session(self):55 login_url = self.get_server_url() + "/login"56 self.s = requests.Session()57 self.s.get(login_url)58 return self.s59 @contextmanager60 def perform(self, operation, relative_url, payload=None):61 result = getattr(self.s, operation)(62 self.get_server_url() + relative_url,63 headers=_DEFAULT_HEADERS,64 data=payload)65 try:66 yield result.json(), result.status_code67 except json.decoder.JSONDecodeError:68 yield None, result.status_code69class GenericLiveTests(LiveTests):70 def test_openapi_spec_validity(self):71 url = self.get_server_url() + '/swagger.json'72 r = self.login_session().get(url)73 assert r.status_code == 20074 parsed_spec = r.json()75 assert isinstance(validator20.validate_spec(parsed_spec), RefResolver)76 def test_server_root_ok(self):77 url = self.get_server_url()78 r = requests.get(url + "/")79 assert r.status_code == 20080 def test_login(self):81 url = self.get_server_url()82 r = requests.get(url + "/login")83 assert r.status_code == 20084 def test_login_logout(self):85 url = self.get_server_url()86 s = self.login_session()87 r = s.get(url + "/logout")88 assert r.status_code == 20089@pytest.mark.skipif('ONTAP_HOST' not in os.environ,90 reason="Requires a live filer")91class NetappLiveTests(LiveTests):92 def test_netapp_create_delete_volume(self):93 ns = "%s/test" % ROOT_URL94 s = self.login_session()95 url = self.get_server_url()96 with self.perform(97 'post',98 "%s/volumes/nothing:/test_volume_api_system_test_14" % ns,99 payload=json.dumps({'name':100 'my_test_volume_api_system_test_14',101 'size_total': 20971520})) as (r, code):102 try:103 assert code == 201104 all_names = [v['name'] for v in105 s.get(url + "{}/test/volumes"106 .format(ns)).json()]107 assert r['name'] in all_names108 r2 = s.delete(url + "{}/test/volumes/{}:{}"109 .format(ns,110 r['filer_address'],111 r['junction_path']),112 headers=_DEFAULT_HEADERS)113 assert r2.status_code == 204114 assert r['name'] not in [v['name'] for v in115 s.get(url + "%s/test/volumes" % ns)\116 .json()]117 finally:118 try:119 self.hard_delete_volume(volume_name=r['name'])120 except Exception:121 pass122 def test_get_protected_resource(self):123 url = self.get_server_url() + ROOT_URL124 s = self.login_session()125 r1 = s.post(url + "/test/volumes/bork", data=json.dumps({}),126 headers=_DEFAULT_HEADERS)127 assert r1.status_code == 201128 r = s.get(url + "/test/volumes/bork/locks")129 assert r.status_code == 200130 def test_netapp_get_volumes(self):131 url = self.get_server_url()132 s = self.login_session()133 with self.recorder.use_cassette('get_volumes'):134 r1 = s.get(url + "/test/volumes")135 assert r1.status_code == 200136 result = r1.json() # noqa137 def test_netapp_get_specific_volume(self):138 url = self.get_server_url() + ROOT_URL139 s = self.login_session()140 NUM_COMPARISONS = 5141 with self.recorder.use_cassette('get_specific'):142 for cmp_no, volume in enumerate(s.get(url + "/test/volumes")143 .json()):144 name_path_address = ("{}/test/volumes/{}:{}"145 .format(url, volume['filer_address'],146 volume['junction_path']))147 if name_path_address[-1] == '/':148 continue149 by_name = s.get(name_path_address).json()150 print(volume)151 assert by_name == volume152 if cmp_no >= NUM_COMPARISONS:...
test_deploymentapi.py
Source:test_deploymentapi.py
...8 # Default timeout is 5 seconds9 app.config['LIVESERVER_TIMEOUT'] = 1010 return app11 def test_server_is_up_and_running(self):12 response = urllib.request.urlopen(self.get_server_url())13 self.assertEqual(response.code, 200)14 def test_getallengineers(self):15 response = urllib.request.urlopen(self.get_server_url()+"/getallengineers")16 self.assertEqual(response.code, 200)17 def test_eventsbyengineer(self):18 response = urllib.request.urlopen(self.get_server_url()+"/eventsbyengineer/sajan")19 self.assertEqual(response.code, 200)20 def test_events_valid(self):21 response = urllib.request.urlopen(self.get_server_url()+"/events?from=1509050542&to=1509050922")22 self.assertEqual(response.code, 200)23 def test_events_invalid1(self):24 response=025 try:26 response = urllib.request.urlopen(self.get_server_url()+"/events?to=1509050922").getcode()27 except:28 self.assertNotEqual(response, 200)29 def test_summary(self):30 response = urllib.request.urlopen(self.get_server_url()+"/summary?date=1509115946")31 self.assertEqual(response.code, 200)32 def test_getallengineers_json(self):33 response = urllib.request.urlopen(self.get_server_url()+"/getallengineers")34 response_data=response.read().decode('utf-8')35 self.assertIsNotNone(response_data)36 def test_eventsbyengineer_json_value(self):37 response = urllib.request.urlopen(self.get_server_url()+"/eventsbyengineer/sajan")38 response_data = response.read().decode('utf-8')39 self.assertIsNotNone(response_data)40 def test_events_valid_json(self):41 response = urllib.request.urlopen(self.get_server_url()+"/events?from=1509050542&to=1509050922")42 response_data = response.read().decode('utf-8')43 self.assertIsNotNone(response_data)44 def test_summary_json(self):45 response = urllib.request.urlopen(self.get_server_url() + "/summary?date=1509115946")46 response_data = response.read().decode('utf-8')47 self.assertIsNotNone(response_data)48 def test_summary_json_value(self):49 response = urllib.request.urlopen(self.get_server_url()+"/summary?date=1509115946")50 response_data = response.read().decode('utf-8')51 self.assertIn("callista",response_data)52 def test_getallengineers_json_value(self):53 response = urllib.request.urlopen(self.get_server_url()+"/getallengineers")54 response_data=response.read().decode('utf-8')55 self.assertIn("isaac",response_data)56 def test_eventsbyengineer_json_value(self):57 response = urllib.request.urlopen(self.get_server_url()+"/eventsbyengineer/sajan")58 response_data = response.read().decode('utf-8')59 self.assertIn("15096384033449",response_data)60 def test_events_valid_json_value(self):61 response = urllib.request.urlopen(self.get_server_url()+"/events?from=1509050542&to=1509050922")62 response_data = response.read().decode('utf-8')...
admin.py
Source:admin.py
...11 server = get_server_by_value(obj.server.server_type)12 return server.title13 get_server_type.short_description = "Server Type"14 get_server_type.admin_order_field = "server__server_type"15 def get_server_url(self, obj):16 return obj.server.url17 get_server_url.short_description = "Server URL"...
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!!