How to use wrapper_method method in autotest

Best Python code snippet using autotest_python

test_decorators.py

Source:test_decorators.py Github

copy

Full Screen

...7from django_scoped_permissions.tests.factories import UserFactory, CompanyFactory8class TestGqlHasScopedPermissions(TestCase):9 def test__simple_scope_check_with_permission__permits(self):10 @gql_has_scoped_permissions("scope1:scope2")11 def wrapper_method(self, info):12 pass13 user = UserFactory.create()14 perm = ScopedPermission.objects.create(scope="scope1:scope2")15 user.scoped_permissions.add(perm)16 info = Dict()17 info.context.user = user18 wrapper_method(None, info)19 def test__simple_scope_check_without_permission__fails(self):20 @gql_has_scoped_permissions("scope1:scope2")21 def wrapper_method(self, info):22 pass23 user = UserFactory.create()24 perm = ScopedPermission.objects.create(scope="scope3")25 user.scoped_permissions.add(perm)26 info = Dict()27 info.context.user = user28 with self.assertRaises(PermissionDenied):29 wrapper_method(None, info)30 def test_expand_from_context__check_with_organization__succeeds(self):31 @gql_has_scoped_permissions("company:{context.company.id}:read")32 def wrapper_method(self, info):33 pass34 user = UserFactory.create()35 perm = ScopedPermission.objects.create(scope="company:1")36 user.scoped_permissions.add(perm)37 info = Dict()38 info.context.user = user39 info.context.company = CompanyFactory.create()40 wrapper_method(None, info)41 def test__multiple_permisions__becomes_or_statement_by_default(self):42 @gql_has_scoped_permissions("scope1", "scope2")43 def wrapper_method(self, info):44 pass45 user = UserFactory.create()46 perm = ScopedPermission.objects.create(scope="scope1")47 user.scoped_permissions.add(perm)48 info = Dict()49 info.context.user = user50 info.context.company = CompanyFactory.create()51 wrapper_method(None, info)52 user.scoped_permissions.all().delete()53 perm = ScopedPermission.objects.create(scope="scope2")54 user.scoped_permissions.add(perm)55 wrapper_method(None, info)56 with self.assertRaises(PermissionDenied):57 user.scoped_permissions.all().delete()58 perm = ScopedPermission.objects.create(scope="scope3")59 user.scoped_permissions.add(perm)60 wrapper_method(None, info)61 def test__with_guard__uses_guard(self):62 @gql_has_scoped_permissions(ScopedPermissionGuard("scope1"))63 def wrapper_method(self, info):64 pass65 user = UserFactory.create()66 perm = ScopedPermission.objects.create(scope="scope1")67 user.scoped_permissions.add(perm)68 info = Dict()69 info.context.user = user70 info.context.company = CompanyFactory.create()71 wrapper_method(None, info)72 def test__with_verb_and_scope__uses_verb_and_scope(self):73 @gql_has_scoped_permissions(scope="scope1", verb="verb")74 def wrapper_method(self, info):75 pass76 user = UserFactory.create()77 perm = ScopedPermission.objects.create(scope="scope1:verb")78 user.scoped_permissions.add(perm)79 info = Dict()80 info.context.user = user81 info.context.company = CompanyFactory.create()82 wrapper_method(None, info)83 user.scoped_permissions.all().delete()84 perm = ScopedPermission.objects.create(scope="verb")85 user.scoped_permissions.add(perm)86 wrapper_method(None, info)87 def test__with_verb_and_scope__uses_verb_and_scope(self):88 @gql_has_scoped_permissions(scope="scope1", verb="verb")89 def wrapper_method(self, info):90 pass91 user = UserFactory.create()92 perm = ScopedPermission.objects.create(scope="scope1:verb")93 user.scoped_permissions.add(perm)94 info = Dict()95 info.context.user = user96 info.context.company = CompanyFactory.create()97 wrapper_method(None, info)98 user.scoped_permissions.all().delete()99 perm = ScopedPermission.objects.create(scope="verb")100 user.scoped_permissions.add(perm)101 wrapper_method(None, info)102 def test__complex_permission_guard_combination__uses_guard(self):103 # Matches when a user has scope1 and not scope2:read (or just read) OR104 # when the user has scope2:scope3 xor scope4105 @gql_has_scoped_permissions(106 (107 ScopedPermissionGuard("scope1")108 & ~ScopedPermissionGuard(scope="scope2", verb="read")109 )110 | (ScopedPermissionGuard("scope2:scope3") ^ ScopedPermissionGuard("scope4"))111 )112 def wrapper_method(self, info):113 pass114 user = UserFactory.create()115 perm = ScopedPermission.objects.create(scope="scope1")116 user.scoped_permissions.add(perm)117 info = Dict()118 info.context.user = user119 info.context.company = CompanyFactory.create()120 wrapper_method(None, info)121 user.scoped_permissions.all().delete()122 perm = ScopedPermission.objects.create(scope="scope2:scope3")123 user.scoped_permissions.add(perm)124 wrapper_method(None, info)125 user.scoped_permissions.all().delete()126 perm = ScopedPermission.objects.create(scope="scope4")127 user.scoped_permissions.add(perm)128 wrapper_method(None, info)129 with self.assertRaises(PermissionDenied):130 user.scoped_permissions.all().delete()131 perm = ScopedPermission.objects.create(scope="scope1")132 perm = ScopedPermission.objects.create(scope="scope2:read")133 user.scoped_permissions.add(perm)134 wrapper_method(None, info)135 with self.assertRaises(PermissionDenied):136 user.scoped_permissions.all().delete()137 user.add_or_create_permission("scope1")138 user.add_or_create_permission("read")...

Full Screen

Full Screen

exception_process.py

Source:exception_process.py Github

copy

Full Screen

...5from .utils import get_ip_address6IP = get_ip_address()7def stats_wrapper(func):8 @wraps(func)9 def wrapper_method(*args, **kwds):10 try:11 return func(*args, **kwds)12 except Exception:13 traceback.print_exc()14 return wrapper_method15def parse_method_wrapper(func):16 @wraps(func)17 def wrapper_method(*args, **kwds):18 self = args[0]19 response = args[1]20 try:21 return func(*args, **kwds)22 except Exception:23 msg = "Error heppened in %s method. Error:%s"%(func.__name__, traceback.format_exc())24 self.logger.error(msg)25 self.crawler.stats.set_failed_download(26 response.meta, "%s \n heppened in %s of %s"%(traceback.format_exc(), func.__name__, IP))27 return wrapper_method28def parse_next_method_wrapper(func):29 @wraps(func)30 def wrapper_method(*args, **kwds):31 self = args[0]32 response = args[1]33 k = response.meta.get("next_key", "unknow")34 try:35 return func(*args, **kwds)36 except Exception:37 msg = "Error heppened in %s method. Error:%s"%(func.__name__, traceback.format_exc())38 self.logger.error(msg)39 item = response.meta.get("item_half", {})40 self.crawler.stats.set_failed_download(41 response.meta, "%s \n heppened in %s of %s product_id: %s," %42 (traceback.format_exc(), func.__name__, IP, item.get("product_id", "unknow"), ), k)43 return wrapper_method44def next_request_method_wrapper(func):45 @wraps(func)46 def wrapper_method(*args, **kwds):47 self = args[0]48 try:49 return func(*args, **kwds)50 except Exception:51 msg = "error heppened in %s method. Error:%s" % (func.__name__, traceback.format_exc())52 self.logger.error(msg)53 if self.present_item:54 meta = self.present_item["meta"] if self.present_item.get("meta") else self.present_item55 else:56 meta = {"crawlid": "next_request_unknow", "url": "unknow"}57 if meta.get("callback") == "parse":58 self.spider.crawler.stats.inc_total_pages(crawlid=meta['crawlid'])59 self.spider.crawler.stats.set_failed_download(meta, "%s \n heppened in %s of %s" % (60 traceback.format_exc(), func.__name__, IP))61 return wrapper_method62def enqueue_request_method_wrapper(func):63 @wraps(func)64 def wrapper_method(*args, **kwds):65 self = args[0]66 request = args[1]67 try:68 return func(*args, **kwds)69 except Exception:70 if request.meta.get("callback") == "parse":71 self.spider.crawler.stats.inc_total_pages(crawlid=request.meta['crawlid'])72 msg = "error heppened in %s method of %s. Error:%s"%(func.__name__, IP, traceback.format_exc())73 self.spider.crawler.stats.set_failed_download(request.meta, "%s \n heppened in %s of %s" % (74 traceback.format_exc(), func.__name__, IP))75 self.logger.error(msg)76 return wrapper_method77def process_requset_method_wrapper(func):78 @wraps(func)79 def wrapper_method(*args, **kwds):80 self = args[0]81 request = kwds.get("request")82 spider = kwds.get("spider")83 try:84 return func(*args, **kwds)85 except Exception as e:86 spider.logger.error("error heppened in process_request method of %s in %s. Error:%s, processing %s," % (87 self.__class__.__name__, IP, traceback.format_exc(), request.url))88 spider.crawler.stats.set_failed_download(request.meta, str(e))89 raise IgnoreRequest(e)90 return wrapper_method91def process_response_method_wrapper(func):92 @wraps(func)93 def wrapper_method(*args, **kwds):94 self = args[0]95 request = kwds.get("request")96 response = kwds.get("response")97 spider = kwds.get("spider")98 try:99 return func(*args, **kwds)100 except Exception as e:101 spider.logger.error("error heppened in process_response method of %s in %s. Error:%s, processing %s," % (102 self.__class__.__name__, IP, traceback.format_exc(), response.url))103 spider.crawler.stats.set_failed_download(request.meta, str(e))104 raise IgnoreRequest(e)105 return wrapper_method106def process_exception_method_wrapper(func):107 @wraps(func)108 def wrapper_method(*args, **kwds):109 self = args[0]110 request = kwds.get("request")111 exception = kwds.get("exception")112 spider = kwds.get("spider")113 try:114 return func(*args, **kwds)115 except Exception as e:116 spider.logger.error("error heppened in process_exception method of %s in %s, deal with exception %s. Error:%s, processing %s," % (117 self.__class__.__name__, IP, "%s:%s"%(exception.__class__.__name__, exception), traceback.format_exc(), request.url))118 if isinstance(e, IgnoreRequest):119 spider.crawler.stats.set_failed_download(request.meta, str(e))120 raise IgnoreRequest(e)...

Full Screen

Full Screen

hello.py

Source:hello.py Github

copy

Full Screen

1from flask import Flask2app = Flask(__name__)3def make_bold(function):4 def wrapper_method():5 string = function()6 return f"<b>{string}</b>"7 return wrapper_method8def make_emphasis(function):9 def wrapper_method():10 string = function()11 return f"<em>{string}</em>"12 return wrapper_method13def make_underlined(function):14 def wrapper_method():15 string = function()16 return f"<u>{string}</u>"17 return wrapper_method18@app.route('/')19def hello_world():20 return 'Hello, World!'21# Different routes using the app.route decorator:22@app.route("/bye")23@make_bold24@make_emphasis25@make_underlined26def bye():27 return "Bye!"28# Creating variable paths and convertinf hte path to a specified data type...

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 autotest 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