def test_it(self): from kotti.request import Request from zope.interface import providedBy, implementedBy req = Request({}) req.set_property(lambda x: 'exists', 'marker', reify=True) assert providedBy(req) == implementedBy(Request) assert req.marker == 'exists'
def test_it(self): from kotti.request import Request from zope.interface import providedBy, implementedBy req = Request({}) req._set_properties({'marker': 'exists'}) assert providedBy(req) == implementedBy(Request) assert req.marker == 'exists'
def test_request_has_permission(self): from kotti.request import Request permission, context = object(), object() args = [] def has_permission_fake(self, permission, context=None): args.append((permission, context)) assert self.environ['authz_context'] == context with patch('kotti.request.BaseRequest.has_permission', new=has_permission_fake): request = Request.blank('/') request.has_permission(permission, context) assert args == [(permission, context)]
def test_request_has_permission(self): from kotti.request import Request permission, context = object(), object() args = [] def has_permission_fake(self, permission, context=None): args.append((permission, context)) assert self.environ['authz_context'] == context with patch('kotti.request.pyramid.request.Request.has_permission', new=has_permission_fake): request = Request.blank('/') request.has_permission(permission, context) assert args == [(permission, context)]
def children_with_permission( self, request: Request, permission: str = "view" ) -> "List[Node]": """ Return only those children for which the user initiating the request has the asked permission. :param request: current request :type request: :class:`kotti.request.Request` :param permission: The permission for which you want the allowed children :type permission: str :result: List of child nodes :rtype: list """ return [c for c in self.children if request.has_permission(permission, c)]
def children_with_permission(self, request: Request, permission: str = "view") -> "List[Node]": """ Return only those children for which the user initiating the request has the asked permission. :param request: current request :type request: :class:`kotti.request.Request` :param permission: The permission for which you want the allowed children :type permission: str :result: List of child nodes :rtype: list """ return [ c for c in self.children if request.has_permission(permission, c) ]
def sub(match): infos = match.groupdict() if infos['selfclosing'] is None and infos['content'] is None: return '<div class="alert alert-error">{0}</div>'.format( localizer.translate( _("Snippet tag '${name}' not closed", mapping=dict(name=infos['name'])))) if infos['escapeopen'] and infos['escapeclose']: return ''.join(( infos['escapeopen'], infos['name'], infos['arguments'], infos['selfclosing'], infos['escapeclose'])) arguments = {} last_key = None for arg in infos['arguments'].split(' '): if '=' in arg: key, value = arg.split('=') key = key.strip() value = value.strip() arguments[key] = value last_key = key elif last_key is not None: arguments[last_key] = "%s %s" % (arguments[last_key], arg) arguments['body'] = infos['content'] snippet_request = Request.blank( request.path + '/snippet-%s' % infos['name'], base_url=request.application_url, POST=urllib.urlencode(arguments), query_string=urllib.urlencode(arguments), referrer=request.url, headers=request.headers) snippet_request.registry = request.registry result = render_view(context, snippet_request, 'snippet-%s' % infos['name']) if result is None: return '<div class="alert alert-error">{0}</div>'.format( localizer.translate( _("No snippet with name '${name}' registered.", mapping=dict(name=infos['name'])))) return result.decode('utf8')