def render_template(self, endpoint, **kwargs): try: return getcontent(endpoint, **kwargs) except TemplateNotFound: if ':' in endpoint: raise return getcontent('{0}:{1}'.format(self.component, endpoint), **kwargs)
def test_endpoint_template_variable(self): try: # had to switch the variable name, we are just identifying the problem # with this test c = getcontent('getcontent.html', __endpoint='foo') assert False except TypeError as e: msg_str = str(e) assert msg_str.startswith("getcontent() got multiple values for ") assert msg_str.endswith("'__endpoint'") c = getcontent('getcontent.html', endpoint='foo') assert c.primary == 'the endpoint: foo', c.primary
def test_page_methods_are_not_autoescaped(self): c = getcontent('nesting_content.html', endpoint='foo') body = c.primary # JS assert '// no & autoescape' in body, body # CSS assert '/* no & autoescape */' in body, body
def test_page_method_formatting(self): c = getcontent('nesting_content2.html') icss = '/* nesting_content2.css */\n' +\ ' \n' + \ ' /* nesting_content3.css */' css = '/* nesting_content2.css */\n\n/* nesting_content3.css */' ijs = '// nesting_content2.js\n' +\ ' \n' + \ ' // nesting_content3.js' js = '// nesting_content2.js\n\n// nesting_content3.js' # re-indent levels are set through the placeholder method c.page_css_ph() c.page_js_ph() assert icss == c.css_ph.content(), c.css_ph.content() assert ijs == c.js_ph.content(), repr(c.js_ph.content()) # re-indent levels are set through the placeholder method c.page_css_ph(reindent=None) c.page_js_ph(reindent=None) assert css == c.css_ph.content() assert js == c.js_ph.content(), repr(c.js_ph.content())
def test_context_variable_takes_precedence(self): user.name = 'foo' class MyUser(object): name = 'bar' c = getcontent('user_test.html', user=MyUser()) assert c.primary == 'user\'s name: bar', c.primary
def test_include_markdown(self): c = getcontent('include_mkdn.html') eq_( c.primary, """ <p>from <em>include_mkdn.mkdn</em></p> <p>from <em>include_mkdn.mkdn</em></p> """.lstrip())
def test_include_rst(self): c = getcontent('include_rst.html') eq_( c.primary, """ <p>from <em>include_rst.rst</em></p> <p>from <em>include_rst.rst</em></p> """.lstrip())
def test_direct_includes(self): c = getcontent('direct_include.html') body = c.primary assert 'nesting_content2.html' in body, body assert 'nesting_content3.html' in body, body assert '/* nesting_content2.css */' in body, body assert '// nesting_content2.js' in body assert '/* nesting_content3.css */' in body, body
def test_include_markdown(self): c = getcontent('include_mkdn.html') eq_( c.primary, """ <p>from <em>include_mkdn.mkdn</em></p> <p>from <em>include_mkdn.mkdn</em></p> """.lstrip() )
def test_super(self): """ test_super had a problem with the way we wrapped block rendering functions which resulted in super() not working """ c = getcontent('test_super.html') eq_(c.primary.strip(), 'The Title |')
def test_include_rst(self): c = getcontent('include_rst.html') eq_( c.primary, """ <p>from <em>include_rst.rst</em></p> <p>from <em>include_rst.rst</em></p> """.lstrip() )
def test_content_filter(self): def get_nesting_content2(): return getcontent('nesting_content2.html') c = getcontent('content_filter.html', get_nesting_content2=get_nesting_content2) body = c.primary assert 'content filter' in body, body assert 'nesting_content2.html' in body, body assert 'nesting_content3.html' in body, body assert '/* nesting_content2.css */' in body, body assert '// nesting_content2.js' in body assert '/* nesting_content3.css */' in body, body
def test_css_and_js_urls(self): c = getcontent('nesting_content.html', endpoint='foo') body = c.primary assert '/* nesting_content.css */' in body assert '// nesting_content.js' in body assert 'nesting_content.htmlnesting_content2.html' in body, body assert 'nesting_content2.html' in body, body assert 'nc2 arg1: foo' in body, body assert '/* nesting_content2.css */' in body, body assert body.count('nesting_content2.html') == 1, body assert 'nesting_content3.html' in body, body assert '/* nesting_content3.css */' in body, body
def test_script_and_link_tags(self): c = getcontent('nesting_content.html', endpoint='foo') body = c.primary assert '<link href="/static/linked_nesting_content.css" rel="stylesheet" ' \ 'type="text/css" />' in body, body assert '<script src="/static/linked_nesting_content.js" type="text/javascript">' \ '</script>' in body, body assert '<link href="static/linked_nesting_content_rel.css" rel="stylesheet" ' \ 'type="text/css" />' in body, body assert '<script src="static/linked_nesting_content_rel.js" type="text/javascript">' \ '</script>' in body, body assert '<link charset="utf-8" href="/static/linked_nesting_content3.css" media="print" ' \ 'rel="stylesheet" type="text/css" />' in body, body assert '<script src="/static/linked_nesting_content3.js" type="text/javascript">' \ '</script>' in body, body # make sure the template functions are returning empty strings and not # None assert 'None' not in body, body
def render_endpoint(self, endpoint, send_response=True): """ Render a template or Content object by endpoint: # look for a template file by endpoint, useful if you need a # template from another component: self.render_endpoint('othercomponent:some_template.html') # or if the view is component level and a template from the main # application is needed. self.render_endpoint('app_level.html') # a Content object can also be rendered by omitting an extension: self.render_endpoint('mycomponent:SomeContent') """ c = getcontent(endpoint, **self.template_vars) self.retval = c if send_response: self.send_response() return c
def get_nesting_content2(): return getcontent('nesting_content2.html')
def test_included_content_default_safe(self): c = getcontent('nesting_content.html', endpoint='foo') assert 'nc2 autoescape: & False' in c.primary, c.primary
def test_template_usage(self): c = getcontent('index.html', a='foo') assert c.primary == 'app index: foo', c.primary
def test_class_usage(self): c = getcontent('HelloWorld') assert c.primary == 'hello world', c.primary
def test_user_proxy_in_template(self): c = getcontent('user_proxy_test.html') # user is not authenticated, so we should see False twice assert 'False\nFalse' in c.primary
def test_include_markdown_not_found(self): getcontent('include_mkdn_nf.html')
def send_reset_password_email(user_obj): subject = '%s - User Password Reset' % (settings.name.full) body = getcontent('auth:password_reset_email.txt', user_obj=user_obj).primary email = EmailMessage(subject, body, None, [user_obj.email_address]) return send_email_or_log_error(email)
def default(self): self.retval = getcontent('tests:HwSnippet').primary
def test_in_request_usage(self): user.name = 'foo' c = getcontent('user_test.html') assert c.primary == 'user\'s name: foo', c.primary
def test_rg_usage(self): rg.test_prop = 'Testing Property' c = getcontent('rg_test.html') assert c.primary == 'rg.test_prop: Testing Property', c.primary
def default(self): self.assign('output', getcontent('tests:text_snippet.txt')) self.render_template(default_ext='txt')
def send_new_user_email(user_obj): subject = '%s - User Login Information' % (settings.name.full) body = getcontent('auth:new_user_email.txt', user_obj=user_obj).primary email = EmailMessage(subject, body, None, [user_obj.email_address]) return send_email_or_log_error(email)