Backport test improvements
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,5 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.test import override_settings
|
||||
|
||||
from mayan.apps.documents.tests import GenericDocumentTestCase
|
||||
|
||||
from ..models import SmartLink
|
||||
@@ -9,16 +7,15 @@ from ..models import SmartLink
|
||||
from .literals import TEST_SMART_LINK_LABEL, TEST_SMART_LINK_DYNAMIC_LABEL
|
||||
|
||||
|
||||
@override_settings(OCR_AUTO_OCR=False)
|
||||
class SmartLinkTestCase(GenericDocumentTestCase):
|
||||
def test_dynamic_label(self):
|
||||
smart_link = SmartLink.objects.create(
|
||||
label=TEST_SMART_LINK_LABEL,
|
||||
dynamic_label=TEST_SMART_LINK_DYNAMIC_LABEL
|
||||
)
|
||||
smart_link.document_types.add(self.document_type)
|
||||
smart_link.document_types.add(self.test_document_type)
|
||||
|
||||
self.assertEqual(
|
||||
smart_link.get_dynamic_label(document=self.document),
|
||||
self.document.label
|
||||
smart_link.get_dynamic_label(document=self.test_document),
|
||||
self.test_document.label
|
||||
)
|
||||
|
||||
@@ -16,138 +16,137 @@ from .literals import (
|
||||
|
||||
|
||||
class SmartLinkViewTestCase(GenericDocumentViewTestCase):
|
||||
def setUp(self):
|
||||
super(SmartLinkViewTestCase, self).setUp()
|
||||
self.login_user()
|
||||
|
||||
def test_smart_link_create_view_no_permission(self):
|
||||
response = self.post(
|
||||
'linking:smart_link_create', data={
|
||||
def _request_test_smart_link_create_view(self):
|
||||
return self.post(
|
||||
viewname='linking:smart_link_create', data={
|
||||
'label': TEST_SMART_LINK_LABEL
|
||||
}
|
||||
)
|
||||
|
||||
def test_smart_link_create_view_no_permission(self):
|
||||
response = self._request_test_smart_link_create_view()
|
||||
self.assertEquals(response.status_code, 403)
|
||||
|
||||
self.assertEqual(SmartLink.objects.count(), 0)
|
||||
|
||||
def test_smart_link_create_view_with_permission(self):
|
||||
self.role.permissions.add(
|
||||
permission_smart_link_create.stored_permission
|
||||
)
|
||||
self.grant_permission(permission=permission_smart_link_create)
|
||||
|
||||
response = self._request_test_smart_link_create_view()
|
||||
self.assertEqual(response.status_code, 302)
|
||||
|
||||
response = self.post(
|
||||
'linking:smart_link_create', data={
|
||||
'label': TEST_SMART_LINK_LABEL
|
||||
}, follow=True
|
||||
)
|
||||
self.assertContains(response, text='created', status_code=200)
|
||||
self.assertEqual(SmartLink.objects.count(), 1)
|
||||
self.assertEqual(
|
||||
SmartLink.objects.first().label, TEST_SMART_LINK_LABEL
|
||||
)
|
||||
|
||||
def test_smart_link_delete_view_no_permission(self):
|
||||
smart_link = SmartLink.objects.create(label=TEST_SMART_LINK_LABEL)
|
||||
|
||||
response = self.post(
|
||||
'linking:smart_link_delete', args=(smart_link.pk,)
|
||||
def _request_test_smart_link_delete_view(self):
|
||||
return self.post(
|
||||
viewname='linking:smart_link_delete', kwargs={
|
||||
'pk': self.test_smart_link.pk
|
||||
}
|
||||
)
|
||||
|
||||
def _create_test_smart_link(self):
|
||||
self.test_smart_link = SmartLink.objects.create(
|
||||
label=TEST_SMART_LINK_LABEL
|
||||
)
|
||||
|
||||
def test_smart_link_delete_view_no_permission(self):
|
||||
self._create_test_smart_link()
|
||||
|
||||
response = self._request_test_smart_link_delete_view()
|
||||
self.assertEqual(response.status_code, 403)
|
||||
|
||||
self.assertEqual(SmartLink.objects.count(), 1)
|
||||
|
||||
def test_smart_link_delete_view_with_permission(self):
|
||||
self.role.permissions.add(
|
||||
permission_smart_link_delete.stored_permission
|
||||
)
|
||||
self._create_test_smart_link()
|
||||
self.grant_permission(permission=permission_smart_link_delete)
|
||||
|
||||
smart_link = SmartLink.objects.create(label=TEST_SMART_LINK_LABEL)
|
||||
response = self._request_test_smart_link_delete_view()
|
||||
self.assertEqual(response.status_code, 302)
|
||||
|
||||
response = self.post(
|
||||
'linking:smart_link_delete', args=(smart_link.pk,), follow=True
|
||||
)
|
||||
|
||||
self.assertContains(response, text='deleted', status_code=200)
|
||||
self.assertEqual(SmartLink.objects.count(), 0)
|
||||
|
||||
def test_smart_link_edit_view_no_permission(self):
|
||||
smart_link = SmartLink.objects.create(label=TEST_SMART_LINK_LABEL)
|
||||
|
||||
response = self.post(
|
||||
'linking:smart_link_edit', args=(smart_link.pk,), data={
|
||||
def _request_test_smart_link_edit_view(self):
|
||||
return self.post(
|
||||
viewname='linking:smart_link_edit', kwargs={
|
||||
'pk': self.test_smart_link.pk
|
||||
}, data={
|
||||
'label': TEST_SMART_LINK_LABEL_EDITED
|
||||
}
|
||||
)
|
||||
|
||||
def test_smart_link_edit_view_no_permission(self):
|
||||
self._create_test_smart_link()
|
||||
|
||||
response = self._request_test_smart_link_edit_view()
|
||||
self.assertEqual(response.status_code, 403)
|
||||
smart_link = SmartLink.objects.get(pk=smart_link.pk)
|
||||
self.assertEqual(smart_link.label, TEST_SMART_LINK_LABEL)
|
||||
|
||||
self.test_smart_link.refresh_from_db()
|
||||
self.assertEqual(self.test_smart_link.label, TEST_SMART_LINK_LABEL)
|
||||
|
||||
def test_smart_link_edit_view_with_permission(self):
|
||||
self.role.permissions.add(
|
||||
permission_smart_link_edit.stored_permission
|
||||
)
|
||||
self._create_test_smart_link()
|
||||
|
||||
smart_link = SmartLink.objects.create(label=TEST_SMART_LINK_LABEL)
|
||||
self.grant_permission(permission=permission_smart_link_edit)
|
||||
|
||||
response = self.post(
|
||||
'linking:smart_link_edit', args=(smart_link.pk,), data={
|
||||
'label': TEST_SMART_LINK_LABEL_EDITED
|
||||
}, follow=True
|
||||
)
|
||||
response = self._request_test_smart_link_edit_view()
|
||||
self.assertEqual(response.status_code, 302)
|
||||
|
||||
smart_link = SmartLink.objects.get(pk=smart_link.pk)
|
||||
self.assertContains(response, text='update', status_code=200)
|
||||
self.assertEqual(smart_link.label, TEST_SMART_LINK_LABEL_EDITED)
|
||||
self.test_smart_link.refresh_from_db()
|
||||
self.assertEqual(self.test_smart_link.label, TEST_SMART_LINK_LABEL_EDITED)
|
||||
|
||||
def setup_smart_links(self):
|
||||
smart_link = SmartLink.objects.create(
|
||||
self.test_smart_link = SmartLink.objects.create(
|
||||
label=TEST_SMART_LINK_LABEL,
|
||||
dynamic_label=TEST_SMART_LINK_DYNAMIC_LABEL
|
||||
)
|
||||
smart_link.document_types.add(self.document_type)
|
||||
self.test_smart_link.document_types.add(self.test_document_type)
|
||||
|
||||
smart_link_2 = SmartLink.objects.create(
|
||||
self.test_smart_link_2 = SmartLink.objects.create(
|
||||
label=TEST_SMART_LINK_LABEL,
|
||||
dynamic_label=TEST_SMART_LINK_DYNAMIC_LABEL
|
||||
)
|
||||
smart_link_2.document_types.add(self.document_type)
|
||||
self.test_smart_link_2.document_types.add(self.test_document_type)
|
||||
|
||||
def _request_test_smart_link_document_instances_view(self):
|
||||
return self.get(
|
||||
viewname='linking:smart_link_instances_for_document',
|
||||
kwargs={'pk': self.test_document.pk}
|
||||
)
|
||||
|
||||
def test_document_smart_link_list_view_no_permission(self):
|
||||
self.setup_smart_links()
|
||||
|
||||
self.role.permissions.add(
|
||||
permission_document_view.stored_permission
|
||||
self.grant_access(
|
||||
obj=self.test_document, permission=permission_document_view
|
||||
)
|
||||
|
||||
response = self.get(
|
||||
'linking:smart_link_instances_for_document',
|
||||
args=(self.document.pk,)
|
||||
)
|
||||
response = self._request_test_smart_link_document_instances_view()
|
||||
# Text must appear 2 times, only for the windows title and template
|
||||
# heading. The two smart links are not shown.
|
||||
|
||||
self.assertContains(
|
||||
response, text=self.document.label, count=2, status_code=200
|
||||
response, text=self.test_document.label, count=2, status_code=200
|
||||
)
|
||||
|
||||
def test_document_smart_link_list_view_with_permission(self):
|
||||
self.setup_smart_links()
|
||||
|
||||
self.role.permissions.add(
|
||||
permission_smart_link_view.stored_permission
|
||||
self.grant_access(
|
||||
obj=self.test_smart_link, permission=permission_smart_link_view
|
||||
)
|
||||
|
||||
self.role.permissions.add(
|
||||
permission_document_view.stored_permission
|
||||
self.grant_access(
|
||||
obj=self.test_smart_link_2, permission=permission_smart_link_view
|
||||
)
|
||||
|
||||
response = self.get(
|
||||
'linking:smart_link_instances_for_document',
|
||||
args=(self.document.pk,)
|
||||
self.grant_access(
|
||||
obj=self.test_document, permission=permission_document_view
|
||||
)
|
||||
|
||||
response = self._request_test_smart_link_document_instances_view()
|
||||
# Text must appear 4 times: 2 for the windows title and template
|
||||
# heading, plus 2 for the test.
|
||||
|
||||
self.assertContains(
|
||||
response, text=self.document.label, count=4, status_code=200
|
||||
response, text=self.test_document.label, count=4, status_code=200
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user