Пример #1
0
 def test_default_output_encoding(self):
     info = dict(someval="someval")
     template = "gearshift.tests.simple"
     headers = {}
     # default encoding is utf-8
     val = view.render(info, template, headers=headers)
     assert headers.get('Content-Type') == 'text/html; charset=utf-8'
     # encoding can be changed and will be added to existing content type
     try:
         config.update({'kid.encoding': 'iso-8859-1'})
         headers['Content-Type'] = 'text/html'
         view.render(info, template, headers=headers)
         assert headers.get(
             'Content-Type') == 'text/html; charset=iso-8859-1'
     finally:
         config.update({'kid.encoding': 'utf-8'})
Пример #2
0
 def test_plain_format(self):
     info = dict(someval="dumbos")
     template = "gearshift.tests.simple"
     headers = {}
     plain = view.render(info, template, headers=headers, format='plain')
     assert headers.get('Content-Type') == 'text/plain; charset=utf-8'
     assert plain.strip() == ('This is the groovy test template.'
                              ' Paging all dumbos.')
     headers = {}
     text = view.render(info, template, headers=headers, format='text')
     assert headers.get('Content-Type') == 'text/plain; charset=utf-8'
     assert text == plain
     try:
         view.render(info, template, headers=headers, format='dumbo')
     except KeyError:
         pass
     else:
         assert False, "'dumbo' should not be accepted as format"
Пример #3
0
 def test_content_types(self):
     info = dict(someval="someval")
     template = "gearshift.tests.simple"
     headers = {}
     view.render(info, template, headers=headers)
     assert headers.get('Content-Type') == 'text/html; charset=utf-8'
     headers = {}
     view.render(info, template, headers=headers, format='html')
     assert headers.get('Content-Type') == 'text/html; charset=utf-8'
     headers = {}
     view.render(info, template, headers=headers, format='html-strict')
     assert headers.get('Content-Type') == 'text/html; charset=utf-8'
     headers = {}
     view.render(info, template, headers=headers, format='xhtml')
     assert headers.get('Content-Type') == 'text/html; charset=utf-8'
     headers = {}
     view.render(info, template, headers=headers, format='xhtml-strict')
     assert headers.get('Content-Type') == 'text/html; charset=utf-8'
     headers = {}
     view.render(info, template, headers=headers, format='xml')
     assert headers.get('Content-Type') == 'text/xml; charset=utf-8'
     headers = {}
     view.render(info, template, headers=headers, format='json')
     assert headers.get('Content-Type') == 'application/json'
     config.update({
         'global': {
             'tg.format_mime_types': {
                 'xhtml': 'application/xhtml+xml'
             }
         }
     })
     headers = {}
     view.render(info, template, headers=headers, format='xhtml')
     assert headers.get(
         'Content-Type') == 'application/xhtml+xml; charset=utf-8'
     headers = {}
     view.render(info, template, headers=headers, format='xhtml-strict')
     assert headers.get(
         'Content-Type') == 'application/xhtml+xml; charset=utf-8'
     config.update({'global': {'tg.format_mime_types': {}}})
Пример #4
0
 def test_UnicodeValueAppearingInATemplateIsFine(self):
     ustr = u"micro-eXtreme Programming ( µ XP): Embedding XP Within Standard Projects"
     info = dict(someval=ustr)
     val = view.render(info, template="gearshift.tests.simple")
     self.failUnless(u"Paging all " + ustr in val.decode("utf-8"))