Add signature deletion view tests.

This commit is contained in:
Roberto Rosario
2016-03-29 13:52:35 -04:00
parent b9d75e525f
commit 0783806fd1
3 changed files with 58 additions and 4 deletions

View File

@@ -217,3 +217,57 @@ class SignaturesViewTestCase(GenericDocumentViewTestCase):
assert_download_response(
self, response=response, content=signature.signature_file.read(),
)
def test_signature_delete_view_no_permission(self):
with open(TEST_KEY_FILE) as file_object:
Key.objects.create(key_data=file_object.read())
with open(TEST_DOCUMENT_PATH) as file_object:
document = self.document_type.new_document(
file_object=file_object
)
with open(TEST_SIGNATURE_FILE_PATH) as file_object:
signature = DetachedSignature.objects.create(
document_version=document.latest_version,
signature_file=File(file_object)
)
self.login(username=TEST_USER_USERNAME, password=TEST_USER_PASSWORD)
response = self.post(
'signatures:document_version_signature_delete',
args=(signature.pk,)
)
self.assertEqual(response.status_code, 403)
self.assertEqual(DetachedSignature.objects.count(), 1)
def test_signature_delete_view_with_permission(self):
with open(TEST_KEY_FILE) as file_object:
Key.objects.create(key_data=file_object.read())
with open(TEST_DOCUMENT_PATH) as file_object:
document = self.document_type.new_document(
file_object=file_object
)
with open(TEST_SIGNATURE_FILE_PATH) as file_object:
signature = DetachedSignature.objects.create(
document_version=document.latest_version,
signature_file=File(file_object)
)
self.login(username=TEST_USER_USERNAME, password=TEST_USER_PASSWORD)
self.role.permissions.add(
permission_document_version_signature_delete.stored_permission
)
response = self.post(
'signatures:document_version_signature_delete',
args=(signature.pk,), follow=True
)
self.assertContains(response, 'deleted', status_code=200)
self.assertEqual(DetachedSignature.objects.count(), 0)

View File

@@ -4,7 +4,7 @@ from django.conf.urls import patterns, url
from .views import (
DocumentVersionSignatureDeleteView, DocumentVersionSignatureDetailView,
DocumentSignatureDownloadView, DocumentVersionSignatureListView,
DocumentVersionSignatureDownloadView, DocumentVersionSignatureListView,
DocumentVersionSignatureUploadView
)
@@ -17,7 +17,7 @@ urlpatterns = patterns(
),
url(
r'^signature/(?P<pk>\d+)/download/$',
DocumentSignatureDownloadView.as_view(),
DocumentVersionSignatureDownloadView.as_view(),
name='document_version_signature_download'
),
url(

View File

@@ -73,7 +73,7 @@ class DocumentVersionSignatureDetailView(SingleObjectDetailView):
return SignatureBaseModel.objects.select_subclasses()
class DocumentSignatureDownloadView(SingleObjectDownloadView):
class DocumentVersionSignatureDownloadView(SingleObjectDownloadView):
model = DetachedSignature
object_permission = permission_document_version_signature_download
object_permission_related = 'document_version.document'
@@ -81,7 +81,7 @@ class DocumentSignatureDownloadView(SingleObjectDownloadView):
def get_file(self):
signature = self.get_object()
return DocumentSignatureDownloadView.VirtualFile(
return DocumentVersionSignatureDownloadView.VirtualFile(
signature.signature_file, name=unicode(signature)
)