Пример #1
0
 def test_render_file3(self):
   '''Test raw flag with mimetype override'''
   result = shortcuts.render_file('raw.html',
                                  self.repo, self.rev3, '/text.txt',
                                  file_mimetype='text/x-csrc',
                                  raw=True)
   self.assertEqual('text/x-csrc', result['Content-Type'])
Пример #2
0
 def test_render_file7(self):
   '''Test the textfilter parameter'''
   def textfilter(contents, path, mimetype):
     self.assertIsInstance(contents, basestring)
     self.assertEqual('/text.txt', path)
     self.assertEqual('text/plain', mimetype)
     return 'test - ' + contents
   response = shortcuts.render_file('raw.html',
                                    self.repo, self.rev3, '/text.txt',
                                    textfilter=textfilter)
   content = response.content.decode('utf8')
   self.assertEqual('test - hello\n\n', content)
Пример #3
0
 def test_render_file6(self):
   '''The `catch_endcoding_errors` argument handles encoding errors.'''
   result = shortcuts.render_file('raw.html',
                                  self.repo, self.rev3, '/encoding.txt',
                                  catch_encoding_errors=True)
   self.assertEqual('text/plain', result['Content-Type'])
Пример #4
0
 def test_render_file5(self):
   '''Encoding errors are properly raised.'''
   with self.assertRaises(DjangoUnicodeDecodeError):
     shortcuts.render_file('raw.html',
                           self.repo, self.rev3, '/encoding.txt')
Пример #5
0
 def test_render_file4(self):
   '''Non-text files get passed through raw.'''
   result = shortcuts.render_file('raw.html',
                                  self.repo, self.rev3, '/binary.gz')
   self.assertEqual('application/octet-stream', result['Content-Type'])
Пример #6
0
 def test_render_file2(self):
   '''Raw argument adds mimetype and returns the file.'''
   result = shortcuts.render_file('raw.html',
                                  self.repo, self.rev3, '/text.txt',
                                  raw=True)
   self.assertEqual('text/plain', result['Content-Type'])
Пример #7
0
 def test_render_file1(self):
   '''Basic text gets rendered into the template'''
   result = shortcuts.render_file('raw.html',
                                  self.repo, self.rev3, '/text.txt')
   self.assertEqual('text/html; charset=utf-8', result['Content-Type'])