def test_serve_attachment_model_no_permission_read(self):
     self.login()
     perm1 = Permission.objects.get(codename='read_attachment')
     self.user.user_permissions.add(perm1)
     request = RequestFactory().get('/fake-path')
     request.user = self.user
     with self.assertRaises(PermissionDenied):
         serve_attachment(request, str(self.attachment.attachment_file))
 def test_serve_attachment_model_nomapentity(self):
     obj = CityFactory.create(code=1)
     attachment = AttachmentFactory.create(content_object=obj)
     request = RequestFactory().get('/fake-path')
     request.user = User.objects.create_superuser('test', '*****@*****.**',
                                                  'booh')
     with self.assertRaises(Http404):
         serve_attachment(request, str(attachment.attachment_file))
示例#3
0
 def test_http_headers_inline(self):
     app_settings['SERVE_MEDIA_AS_ATTACHMENT'] = False
     request = RequestFactory().get('/fake-path')
     request.user = User.objects.create_superuser('test', '*****@*****.**', 'booh')
     response = serve_attachment(request, 'file.pdf', 'test_app', 'dummymodel', str(self.obj.pk))
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.content, b'')
     self.assertEqual(response['Content-Type'], 'application/pdf')
     self.assertFalse('Content-Disposition' in response)
     app_settings['SERVE_MEDIA_AS_ATTACHMENT'] = True
 def test_http_headers_inline(self):
     app_settings['SERVE_MEDIA_AS_ATTACHMENT'] = False
     request = RequestFactory().get('/fake-path')
     request.user = User.objects.create_superuser('test', '*****@*****.**', 'booh')
     response = serve_attachment(request, 'file.pdf', 'tests', 'dummymodel', '1')
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.content, '')
     self.assertEqual(response['Content-Type'], 'application/pdf')
     self.assertFalse('Content-Disposition' in response)
     app_settings['SERVE_MEDIA_AS_ATTACHMENT'] = True
示例#5
0
 def test_http_headers_attachment(self):
     app_settings['SENDFILE_HTTP_HEADER'] = 'X-Accel-Redirect'
     request = RequestFactory().get('/fake-path')
     request.user = User.objects.create_superuser('test', '*****@*****.**', 'booh')
     response = serve_attachment(request, 'file.pdf', 'test_app', 'dummymodel', str(self.obj.pk))
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.content, b'')
     self.assertEqual(response['X-Accel-Redirect'], '/media_secure/file.pdf')
     self.assertEqual(response['Content-Type'], 'application/pdf')
     self.assertEqual(response['Content-Disposition'], 'attachment; filename=file.pdf')
     app_settings['SENDFILE_HTTP_HEADER'] = None
 def test_http_headers_attachment(self):
     app_settings['SENDFILE_HTTP_HEADER'] = 'X-Accel-Redirect'
     request = RequestFactory().get('/fake-path')
     request.user = User.objects.create_superuser('test', '*****@*****.**', 'booh')
     response = serve_attachment(request, 'file.pdf', 'tests', 'dummymodel', '1')
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.content, '')
     self.assertEqual(response['X-Accel-Redirect'], '/media_secure/file.pdf')
     self.assertEqual(response['Content-Type'], 'application/pdf')
     self.assertEqual(response['Content-Disposition'], 'attachment; filename=file.pdf')
     app_settings['SENDFILE_HTTP_HEADER'] = None