How to use test_all_args method in SeleniumLibrary

Best Python code snippet using SeleniumLibrary

test_response.py

Source:test_response.py Github

copy

Full Screen

1from unittest import TestCase2from unittest.mock import patch, Mock, MagicMock3from requests.exceptions import ConnectionError, HTTPError, Timeout4from ..response import Response5import os6from ..cache import JsonCache7from ..state import JsonState8class ResponseTestCase(TestCase):9 def _mock_response(10 self,11 status_code=200,12 content=b'CONTENT',13 raise_for_status=None):14 """15 Build a mock for each response, include errors and content data16 """17 mock_resp = Mock()18 # mock raise_for_status call w/optional error19 mock_resp.raise_for_status = Mock()20 mock_resp.status_code = status_code21 if raise_for_status:22 mock_resp.raise_for_status.side_effect = raise_for_status23 return mock_resp24 mock_resp.content = content25 mock_resp.iter_content = Mock()26 iter_result = iter([bytes([b]) for b in content])27 mock_resp.iter_content.return_value = iter_result28 return mock_resp29 def setUp(self):30 pass31 def tearDown(self):32 pass33 @staticmethod34 def _clear_environ():35 os.environ = {}36 def test_valid_arguments(self):37 self._clear_environ()38 response = Response(config_location='microsoftbotframework/tests/test_files/test_all_args.yaml')39 self.assertEqual(response.auth, True)40 self.assertEqual(response.app_client_id, 'asdf')41 self.assertEqual(response.app_client_secret, 'fdsa')42 self.assertEqual(response.http_proxy, 'http://proxy:81')43 self.assertEqual(response.https_proxy, 'https://proxy:81')44 self.assertEqual(response.cache_token, True)45 self.assertEqual(type(response.cache), type(JsonCache()))46 self.assertEqual(type(response.state), type(JsonState()))47 self.assertEqual(response.data, {})48 self.assertEqual(response.headers, None)49 self.assertEqual(response.token, None)50 self.data = {}51 self.headers = None52 self.token = None53 def test_incorrect_argument(self):54 with self.assertRaises(Exception):55 Response(bad_argument=None)56 def test_auth_disable_no_id(self):57 # If app_client_id or app_client_id is not set, disable auth58 self._clear_environ()59 response = Response(config_location='microsoftbotframework/tests/test_files/test_auth_disable.yaml')60 self.assertEqual(response.app_client_secret, None)61 self.assertEqual(response.auth, False)62 def test_auth_disable_no_secret(self):63 # If app_client_id or app_client_id is not set, disable auth64 self._clear_environ()65 response = Response(config_location='microsoftbotframework/tests/test_files/test_auth_disable.yaml')66 self.assertEqual(response.app_client_id, None)67 self.assertEqual(response.auth, False)68 def test_auth_enable(self):69 # If app_client_id or app_client_id is not set, disable auth70 response = Response(app_client_id='123456', app_client_secret='654321',71 config_location='microsoftbotframework/tests/test_files/test_auth_disable.yaml')72 self.assertEqual(response.app_client_id, '123456')73 self.assertEqual(response.app_client_secret, '654321')74 self.assertEqual(response.auth, True)75 def test_cache_default(self):76 self._clear_environ()77 response = Response(app_client_id='123456', app_client_secret='654321',78 config_location='microsoftbotframework/tests/test_files/test_auth_disable.yaml')79 self.assertEqual(type(response.cache), type(JsonCache()))80 self.assertEqual(response.cache_token, True)81 def test_cache_disable_2(self):82 self._clear_environ()83 response = Response(app_client_id='123456', app_client_secret='654321',84 config_location='microsoftbotframework/tests/test_files/test_auth_disable.yaml',85 cache=False)86 self.assertEqual(response.cache, None)87 self.assertEqual(response.cache_token, False)88 def test_cache_enable(self):89 self._clear_environ()90 response = Response(app_client_id='123456', app_client_secret='654321',91 config_location='microsoftbotframework/tests/test_files/test_auth_disable.yaml',92 cache='JsonCache')93 self.assertEqual(type(response.cache), type(JsonCache()))94 self.assertEqual(response.cache_token, True)95 def test_state_disable(self):96 self._clear_environ()97 response = Response(state=False)98 self.assertEqual(response.state, None)99 def test_state_enable(self):100 self._clear_environ()101 response = Response(state='JsonState')102 self.assertEqual(type(response.state), type(JsonState()))103 def test_state_enable_object(self):104 self._clear_environ()105 response = Response(state=JsonState())106 self.assertEqual(type(response.state), type(JsonState()))107 def test_state_default(self):108 self._clear_environ()109 response = Response()110 self.assertEqual(response.cache, None)111 def test_urljoin(self):112 self.assertEqual(Response.urljoin('https://asdf.com', 'something'), 'https://asdf.com/something')113 self.assertEqual(Response.urljoin('https://asdf.com', '/something'), 'https://asdf.com/something')114 self.assertEqual(Response.urljoin('https://asdf.com/', 'something'), 'https://asdf.com/something')115 self.assertEqual(Response.urljoin('https://asdf.com/', '/something'), 'https://asdf.com/something')116 def test_timeout_set_and_used(self):117 # ensure that the timeout is set on the Response intance118 timeout_seconds = 2119 response = Response(config_location='microsoftbotframework/tests/test_files/test_auth_disable.yaml',120 timeout_seconds=timeout_seconds)121 self.assertEqual(response.timeout_seconds, timeout_seconds)122 response_url = 'https://www.google.com/'123 # ensure that we don't hit a timeout on the below request124 method = 'get'125 requests_response = response._request(response_url, method, response_json=None)126 # throw timeout exception if we set it too low on _request127 timeout_seconds = 0.01128 response = Response(config_location='microsoftbotframework/tests/test_files/test_auth_disable.yaml',129 timeout_seconds=timeout_seconds)130 with self.assertRaises(Timeout):131 response._request(response_url, method, response_json=None)132 # throw timeout exception if we set it too low on _get_remote_auth_token133 response = Response(config_location='microsoftbotframework/tests/test_files/test_all_args.yaml',134 timeout_seconds=timeout_seconds)135 with self.assertRaises(Timeout):136 response._get_remote_auth_token()137 @patch('microsoftbotframework.response.requests.delete')138 @patch('microsoftbotframework.response.requests.post')139 @patch('microsoftbotframework.response.requests.get')140 def test_request_raises_exceptions(self, mock_get, mock_post, mock_delete):141 """142 This test ensures that the timeout_seconds is set correctly, and that requests exceptions are raised by143 the _request method144 """145 self._clear_environ()146 timeout_seconds = 2147 response = Response(config_location='microsoftbotframework/tests/test_files/test_auth_disable.yaml',148 timeout_seconds=timeout_seconds)149 response_url = 'https://asdf.com/'150 method_mockmethod_pairs = [('get', mock_get), ('post', mock_post), ('delete', mock_delete)]151 for method, mockmethod in method_mockmethod_pairs:152 # ConnectionError case153 mock_return_value = self._mock_response(status_code=None, raise_for_status=ConnectionError())154 mockmethod.return_value = mock_return_value155 with self.assertRaises(ConnectionError):156 response._request(response_url, method, response_json=None)157 # HTTPError case158 mock_return_value = self._mock_response(status_code=404, raise_for_status=HTTPError())159 mockmethod.return_value = mock_return_value160 with self.assertRaises(HTTPError):161 response._request(response_url, method, response_json=None)162 # Timeout case163 mock_return_value = self._mock_response(status_code=None, raise_for_status=Timeout())164 mockmethod.return_value = mock_return_value165 with self.assertRaises(Timeout):166 response._request(response_url, method, response_json=None)167 @patch('microsoftbotframework.response.requests.post')168 def test_get_remote_auth_token_raises_exceptions(self, mock_post):169 """170 This test ensures that the timeout_seconds is set correctly, and that requests exceptions are raised by171 the _get_remote_auth_token method172 """173 self._clear_environ()174 timeout_seconds = 2175 response = Response(config_location='microsoftbotframework/tests/test_files/test_all_args.yaml',176 timeout_seconds=timeout_seconds)177 response_url = 'https://asdf.com/'178 # ConnectionError case179 mock_return_value = self._mock_response(status_code=None, raise_for_status=ConnectionError())180 mock_post.return_value = mock_return_value181 with self.assertRaises(ConnectionError):182 response._get_remote_auth_token()183 # HTTPError case184 mock_return_value = self._mock_response(status_code=404, raise_for_status=HTTPError())185 mock_post.return_value = mock_return_value186 with self.assertRaises(HTTPError):187 response._get_remote_auth_token()188 # Timeout case189 mock_return_value = self._mock_response(status_code=None, raise_for_status=Timeout())190 mock_post.return_value = mock_return_value191 with self.assertRaises(Timeout):...

Full Screen

Full Screen

test_command.py

Source:test_command.py Github

copy

Full Screen

...14 self.region = None15 self.profile = None16 @patch("samcli.commands.package.command.click")17 @patch("samcli.commands.package.package_context.PackageContext")18 def test_all_args(self, package_command_context, click_mock):19 context_mock = Mock()20 package_command_context.return_value.__enter__.return_value = context_mock21 do_cli(22 template_file=self.template_file,23 s3_bucket=self.s3_bucket,24 s3_prefix=self.s3_prefix,25 kms_key_id=self.kms_key_id,26 output_template_file=self.output_template_file,27 use_json=self.use_json,28 force_upload=self.force_upload,29 metadata=self.metadata,30 region=self.region,31 profile=self.profile,32 )...

Full Screen

Full Screen

test_kwargs.py

Source:test_kwargs.py Github

copy

Full Screen

...38def test_dictionary_args():39 assert (40 kwargs_lab.args_as_dictionary(link_color='red', back_color='yellow') ==41 {'link_color': 'red', 'back_color': 'yellow'})42def test_all_args():43 assert (44 kwargs_lab.all_args('red', 'yellow', key1='value1', key2='value2') ==...

Full Screen

Full Screen

args.py

Source:args.py Github

copy

Full Screen

...4function. Python's creators have really mastered all the many ways5arguments are passed to functions making them all just work.6* Positional arguments with no default are required7'''8def test_all_args(one,two,foo='bar',*args,**kwargs):9 print()10 print('one: {}'.format(one))11 print('two: {}'.format(two))12 print('foo: {}'.format(foo))13 print('args: {}'.format(args))14 print('kwargs: {}'.format(kwargs))15def test_kwargs(**kwargs):16 print()17 print('kwargs: {}'.format(kwargs))18mydictionary = {"bar":100,"spam":"gross"}19demo_args = [20 '1',21 '1,2',22 '\'1\',2',...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run SeleniumLibrary automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful