def test_attachment_filename_false(self): response = real_sendfile(HttpRequest(), self._get_readme(), attachment=True, attachment_filename=False) self.assertTrue(response is not None) self.assertEqual('attachment', response['Content-Disposition'])
def test_attachment(self): response = real_sendfile(HttpRequest(), self._get_readme(), attachment=True) self.assertTrue(response is not None) self.assertEqual('attachment; filename="testfile.txt"', response['Content-Disposition'])
def test_location_header_containing_unicode(self): filepath = self.ensure_file('péter_là_gueule.txt') response = real_sendfile(HttpRequest(), filepath) self.assertTrue(response is not None) s = '/private/péter_là_gueule.txt' if six.PY2: s = s.encode("utf-8") self.assertEqual(s, unquote(response['Location']))
def test_attachment_filename_unicode(self): response = real_sendfile(HttpRequest(), self._get_readme(), attachment=True, attachment_filename='test’s.txt') self.assertTrue(response is not None) self.assertEqual( 'attachment; filename="tests.txt"; filename*=UTF-8\'\'test%E2%80%99s.txt', response['Content-Disposition'])
def test_set_encoding(self): response = real_sendfile(HttpRequest(), self._get_readme(), encoding='utf8') self.assertTrue(response is not None) self.assertEqual('utf8', response['Content-Encoding'])
def test_set_mimetype(self): response = real_sendfile(HttpRequest(), self._get_readme(), mimetype='text/plain') self.assertTrue(response is not None) self.assertEqual('text/plain', response['Content-Type'])
def test_sendfile(self): response = real_sendfile(HttpRequest(), self._get_readme()) self.assertTrue(response is not None) self.assertEqual('text/plain', response['Content-Type']) self.assertEqual(self._get_readme(), smart_str(response.content))
def test_404(self): try: real_sendfile(HttpRequest(), 'fhdsjfhjk.txt') except Http404: pass
def test_correct_url_in_location_header(self): filepath = self.ensure_file('readme.txt') response = real_sendfile(HttpRequest(), filepath) self.assertTrue(response is not None) self.assertEqual('/private/readme.txt', response['Location'])
def test_correct_url_in_xaccelredirect_header(self): filepath = self.ensure_file('readme.txt') response = real_sendfile(HttpRequest(), filepath) self.assertTrue(response is not None) self.assertEqual('/private/readme.txt', response['X-Accel-Redirect'])
def test_xsendfile_header_containing_unicode(self): filepath = self.ensure_file('péter_là_gueule.txt') response = real_sendfile(HttpRequest(), filepath) self.assertTrue(response is not None) self.assertEqual(smart_str(filepath), response['X-Sendfile'])
def test_correct_file_in_xsendfile_header(self): filepath = self.ensure_file('readme.txt') response = real_sendfile(HttpRequest(), filepath) self.assertTrue(response is not None) self.assertEqual(filepath, response['X-Sendfile'])