def email_default_context(): class NoEmailViewPerm(MockPerm): def has_permission(self, action, realm_or_resource=None, id=False, version=False): return action != 'EMAIL_VIEW' __contains__ = has_permission context = RenderingContext(Resource('wiki', 'WikiStart'), href=Href('/'), perm=NoEmailViewPerm()) context.req = None # 1.0 FIXME .req shouldn't be required by formatter return context
def test_run_html_formatter(self): wiki_content = "!WikiSyntax" page = self.create_wiki("Dummy wiki", wiki_content) from trac.mimeview.api import RenderingContext context = RenderingContext( page.resource, href=Href('/'), perm=MockPerm(), ) context.req = None # 1.0 FIXME .req shouldn't be required by formatter format_to_html(self.env, context, wiki_content)
def email_default_context(): class NoEmailViewPerm(MockPerm): def has_permission(self, action, realm_or_resource=None, id=False, version=False): return action != 'EMAIL_VIEW' __contains__ = has_permission context = RenderingContext(Resource('wiki', 'WikiStart'), href=Href('/'), perm=NoEmailViewPerm()) context.req = None # 0.13 FIXME .req shouldn't be required by formatter return context
def test_plain_text_content(self): """Render simple plain text content.""" mimeview = Mimeview(self.env) req = MockRequest(self.env) context = RenderingContext(Resource('wiki', 'readme.txt')) context.req = req content = io.BytesIO("""\ Some text. """) rendered = mimeview.render(context, 'text/plain', content) self.assertEqual('<div class="code"><pre>Some text.\n</pre></div>', str(rendered))
def web_context(req, resource=None, id=False, version=False, parent=False, absurls=False): """Create a rendering context from a request. The `perm` and `href` properties of the context will be initialized from the corresponding properties of the request object. >>> from trac.test import Mock, MockPerm >>> req = Mock(href=Mock(), perm=MockPerm()) >>> context = web_context(req) >>> context.href is req.href True >>> context.perm is req.perm True :param req: the HTTP request object :param resource: the `Resource` object or realm :param id: the resource identifier :param version: the resource version :param absurls: whether URLs generated by the ``href`` object should be absolute (including the protocol scheme and host name) :return: a new rendering context :rtype: `RenderingContext` :since: version 1.0 """ if req: href = req.abs_href if absurls else req.href perm = req.perm else: href = None perm = None self = RenderingContext(Resource(resource, id=id, version=version, parent=parent), href=href, perm=perm) self.req = req return self