Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion testapp/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
Django>=1.11
Django>=3.2.23,<=4.2.9
coverage
pyclamd
six
coverage==3.7.1
python-magic>=0.4.15
python-magic-bin>=0.4.14
19 changes: 19 additions & 0 deletions testapp/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
'django.contrib.messages',
'django.contrib.staticfiles',
'attachments',
'bootstrap',
'testapp',
]

Expand All @@ -26,6 +27,24 @@
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'OPTIONS': {
'context_processors': [
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.static',
'django.template.context_processors.request',
'django.contrib.messages.context_processors.messages',
],
'loaders': [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
],
},
},
]

ROOT_URLCONF = 'testapp.urls'

WSGI_APPLICATION = 'testapp.wsgi.application'
Expand Down
35 changes: 35 additions & 0 deletions testapp/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from attachments.utils import session, url_filename

from .models import Document
from .utils import get_storage

import io

Expand Down Expand Up @@ -41,3 +42,37 @@ def test_upload(self):
upload = sess.uploads.get()
self.assertEqual(upload.file_name, att.name)
self.assertEqual(upload.file_size, len(att_data))

def test_delete(self):
att_data = b'some data'
request = RequestFactory().get('/test/page/')
sess = session(request)
att = io.BytesIO(att_data)
att.name = 'testfile'
response = self.client.post('/attachments/%s/' % sess.uuid, {'attachment': att})
upload = sess.uploads.get()
response = self.client.post(f'/attachments/delete/upload/{sess.uuid}/{upload.upload_id}', {'attachment': att})
self.assertEqual(response.json(), {'ok': True})

def test_download(self):
storage = get_storage()
att_data = b'some data'
request = RequestFactory().get('/test/page/')
sess = session(request)
att = io.BytesIO(att_data)
att.name = 'testfile'
response = self.client.post(f'/attachments/download/{att.id}/{att.name}', {'attachment': att})
self.assertEqual(
response.json(),
{'X-Sendfile': att.file_path,
'Content-Length': storage.size(att.file_path),
'Content-Disposition': 'attachment; filename="%s"' % att.name})

def test_update_attachment(self):
att_data = b'some data'
request = RequestFactory().get('/test/page/')
sess = session(request)
att = io.BytesIO(att_data)
att.name = 'testfile'
response = self.client.post(f'/attachments/update/{att.id}', {'attachment': att})
self.assertEqual(response.json(), {'ok': True})