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'])
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)
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'])
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')
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'])
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'])
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'])