How to use handle_http_error method in mailosaur-python

Best Python code snippet using mailosaur-python_python

test_request_dispatching.py

Source:test_request_dispatching.py Github

copy

Full Screen

1from unittest.mock import Mock2import pytest3from ariadne import GraphQLMiddleware4from ariadne.exceptions import HttpMethodNotAllowedError5def test_request_to_app_root_path_is_forwarded(app_mock, middleware):6 middleware({"PATH_INFO": "/"}, Mock())7 assert app_mock.called8def test_request_to_app_sub_path_is_forwarded(app_mock, middleware):9 middleware({"PATH_INFO": "/something/"}, Mock())10 assert app_mock.called11def test_request_to_graphql_path_is_handled(app_mock, middleware):12 middleware.handle_request = Mock()13 middleware({"PATH_INFO": "/graphql/"}, Mock())14 assert middleware.handle_request.called15 assert not app_mock.called16def test_request_to_graphql_server_root_path_is_handled(server):17 server.handle_request = Mock()18 server({"PATH_INFO": "/"}, Mock())19 assert server.handle_request.called20def test_request_to_graphql_server_sub_path_is_handled(server):21 server.handle_request = Mock()22 server({"PATH_INFO": "/something/"}, Mock())23 assert server.handle_request.called24def test_app_exceptions_are_not_handled(app_mock, type_defs):25 exception = Exception("Test exception")26 app_mock = Mock(side_effect=exception)27 middleware = GraphQLMiddleware(app_mock, type_defs=type_defs, resolvers={})28 middleware.handle_request = Mock()29 with pytest.raises(Exception) as excinfo:30 middleware({"PATH_INFO": "/"}, Mock())31 assert excinfo.value is exception32 assert not middleware.handle_request.called33def test_get_handler_is_called_for_for_get_request(34 middleware, middleware_request, start_response35):36 middleware_request["REQUEST_METHOD"] = "GET"37 middleware.handle_get = Mock()38 middleware(middleware_request, start_response)39 middleware.handle_get.assert_called_once_with(start_response)40def test_post_handler_is_called_for_for_post_request(41 middleware, middleware_request, start_response42):43 middleware_request["REQUEST_METHOD"] = "POST"44 middleware.handle_post = Mock()45 middleware(middleware_request, start_response)46 middleware.handle_post.assert_called_once_with(middleware_request, start_response)47def test_http_not_allowed_error_is_thrown_for_delete_request(48 middleware, middleware_request, start_response49):50 middleware_request["REQUEST_METHOD"] = "DELETE"51 middleware.handle_http_error = Mock()52 middleware(middleware_request, start_response)53 assert middleware.handle_http_error.call_count == 154 called_with_args = middleware.handle_http_error.call_args[0]55 assert len(called_with_args) == 256 assert isinstance(called_with_args[0], HttpMethodNotAllowedError)57 assert called_with_args[1] == start_response58def test_http_not_allowed_error_is_thrown_for_head_request(59 middleware, middleware_request, start_response60):61 middleware_request["REQUEST_METHOD"] = "HEAD"62 middleware.handle_http_error = Mock()63 middleware(middleware_request, start_response)64 assert middleware.handle_http_error.call_count == 165 called_with_args = middleware.handle_http_error.call_args[0]66 assert len(called_with_args) == 267 assert isinstance(called_with_args[0], HttpMethodNotAllowedError)68 assert called_with_args[1] == start_response69def test_http_not_allowed_error_is_thrown_for_patch_request(70 middleware, middleware_request, start_response71):72 middleware_request["REQUEST_METHOD"] = "PATCH"73 middleware.handle_http_error = Mock()74 middleware(middleware_request, start_response)75 assert middleware.handle_http_error.call_count == 176 called_with_args = middleware.handle_http_error.call_args[0]77 assert len(called_with_args) == 278 assert isinstance(called_with_args[0], HttpMethodNotAllowedError)79 assert called_with_args[1] == start_response80def test_http_not_allowed_error_is_thrown_for_put_request(81 middleware, middleware_request, start_response82):83 middleware_request["REQUEST_METHOD"] = "PUT"84 middleware.handle_http_error = Mock()85 middleware(middleware_request, start_response)86 assert middleware.handle_http_error.call_count == 187 called_with_args = middleware.handle_http_error.call_args[0]88 assert len(called_with_args) == 289 assert isinstance(called_with_args[0], HttpMethodNotAllowedError)90 assert called_with_args[1] == start_response91def test_http_not_allowed_error_is_thrown_for_options_request(92 middleware, middleware_request, start_response93):94 middleware_request["REQUEST_METHOD"] = "OPTIONS"95 middleware.handle_http_error = Mock()96 middleware(middleware_request, start_response)97 assert middleware.handle_http_error.call_count == 198 called_with_args = middleware.handle_http_error.call_args[0]99 assert len(called_with_args) == 2100 assert isinstance(called_with_args[0], HttpMethodNotAllowedError)...

Full Screen

Full Screen

repo.py

Source:repo.py Github

copy

Full Screen

...45 self.private = False46 if "tree/master" in self.repo_name:47 self.__subdir_scrape(auth_token)48 else:49 repo_meta = handle_http_error(self.repo_name, github.get_repo_metadata, auth_token)50 if repo_meta is None:51 self.scraped = False52 return53 self.__assign_metadata_fields(repo_meta)54 self.scraped = True55 self.files = handle_http_error(self.repo_name, github.get_file_tree, auth_token)56 self.readme = handle_http_error(self.repo_name, github.get_readme, auth_token)57 def __assign_metadata_fields(self, repo_meta):58 self.stars = repo_meta["stars"]59 self.lang = repo_meta["lang"]60 self.forks = repo_meta["forks"]61 def __subdir_scrape(self, auth_token=None):62 """Given repo url defines a subdirectory of a repo"""63 tree_master = "/tree/master"64 if tree_master in self.repo_name:65 super_repo_name = self.repo_name.split(tree_master)[0]66 repo_meta = handle_http_error(super_repo_name, github.get_repo_metadata, auth_token)67 if repo_meta is None:68 self.scraped = False69 return70 self.__assign_metadata_fields(repo_meta)71 self.scraped = True72 self.files = handle_http_error(self.repo_name, github.get_sub_dir, auth_token)73 if self.files:74 readmes = [file for file in self.files if "README.md" == file.name]75 if len(readmes):76 url = readmes[0].url77 self.readme = github.get_readme(self.repo_name,SESSION, auth_token=auth_token, url=url)78def handle_http_error(repo_name, request_method, auth_token):79 try:80 return request_method(repo_name, SESSION, auth_token=auth_token)81 except requests.HTTPError as err:82 print(err)83 if err.response.status_code == 403:84 if not auth_token:85 print("WARNING: No auth-token specified. Rate Limit will be exceeded easily.")86 elif err.response.status_code == 404:...

Full Screen

Full Screen

test_middleware.py

Source:test_middleware.py Github

copy

Full Screen

...3from helpers import errors4async def handler_func(request, *args, **kwargs):5 exc = request6 raise exc("Test exception")7async def handle_http_error(*args, **kwargs):8 return kwargs.get('status', None)9async def test_error_middleware_500():10 with mock.patch('app.middlewares.handle_http_error', handle_http_error):11 res = await middlewares.error_middleware(request=Exception, handler=handler_func)12 assert res == 50013async def test_error_middleware_400():14 with mock.patch('app.middlewares.handle_http_error', handle_http_error):15 res = await middlewares.error_middleware(request=errors.BadRequest, handler=handler_func)16 assert res == 40017async def test_error_middleware_404():18 with mock.patch('app.middlewares.handle_http_error', handle_http_error):19 res = await middlewares.error_middleware(request=errors.RecordNotFound, handler=handler_func)20 assert res == 40421async def test_error_middleware_403():...

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 mailosaur-python 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