Fix documents app view tests. Update code to match code style. PEP8 fixes.
This commit is contained in:
@@ -43,7 +43,6 @@ permission_document_version_revert = namespace.add_permission(
|
||||
permission_document_view = namespace.add_permission(
|
||||
name='document_view', label=_('View documents')
|
||||
)
|
||||
|
||||
permission_empty_trash = namespace.add_permission(
|
||||
name='document_empty_trash', label=_('Empty trash')
|
||||
)
|
||||
@@ -51,7 +50,6 @@ permission_empty_trash = namespace.add_permission(
|
||||
setup_namespace = PermissionNamespace(
|
||||
'documents_setup', label=_('Documents setup')
|
||||
)
|
||||
|
||||
permission_document_type_create = setup_namespace.add_permission(
|
||||
name='document_type_create', label=_('Create document types')
|
||||
)
|
||||
|
||||
@@ -36,7 +36,8 @@ TEST_NON_ASCII_COMPRESSED_DOCUMENT_FILENAME = 'I18N_title_áéíóúüñÑ.png.z
|
||||
TEST_NON_ASCII_DOCUMENT_FILENAME = 'I18N_title_áéíóúüñÑ.png'
|
||||
TEST_OFFICE_DOCUMENT = 'simple_2_page_document.doc'
|
||||
TEST_SMALL_DOCUMENT_FILENAME = 'title_page.png'
|
||||
TEST_SMALL_DOCUMENT_CHECKSUM = 'efa10e6cc21f83078aaa94d5cbe51de67b51af706143bafc7fd6d4c02124879a'
|
||||
TEST_SMALL_DOCUMENT_CHECKSUM = 'efa10e6cc21f83078aaa94d5cbe51de67b51af706143b\
|
||||
afc7fd6d4c02124879a'
|
||||
|
||||
# File paths
|
||||
TEST_COMPRESSED_DOCUMENT_PATH = os.path.join(
|
||||
|
||||
@@ -42,10 +42,16 @@ class DocumentTypeAPITestCase(APITestCase):
|
||||
def test_document_type_create(self):
|
||||
self.assertEqual(DocumentType.objects.all().count(), 0)
|
||||
|
||||
self.client.post(reverse('rest_api:documenttype-list'), {'label': TEST_DOCUMENT_TYPE})
|
||||
self.client.post(
|
||||
reverse('rest_api:documenttype-list'), data={
|
||||
'label': TEST_DOCUMENT_TYPE
|
||||
}
|
||||
)
|
||||
|
||||
self.assertEqual(DocumentType.objects.all().count(), 1)
|
||||
self.assertEqual(DocumentType.objects.all().first().label, TEST_DOCUMENT_TYPE)
|
||||
self.assertEqual(
|
||||
DocumentType.objects.all().first().label, TEST_DOCUMENT_TYPE
|
||||
)
|
||||
|
||||
def test_document_type_edit_via_put(self):
|
||||
document_type = DocumentType.objects.create(label=TEST_DOCUMENT_TYPE)
|
||||
@@ -112,8 +118,9 @@ class DocumentAPITestCase(APITestCase):
|
||||
|
||||
document_data = loads(document_response.content)
|
||||
|
||||
self.assertEqual(document_response.status_code, status.HTTP_201_CREATED)
|
||||
|
||||
self.assertEqual(
|
||||
document_response.status_code, status.HTTP_201_CREATED
|
||||
)
|
||||
self.assertEqual(Document.objects.count(), 1)
|
||||
|
||||
document = Document.objects.first()
|
||||
@@ -140,7 +147,9 @@ class DocumentAPITestCase(APITestCase):
|
||||
file_object=File(file_object),
|
||||
)
|
||||
|
||||
self.client.delete(reverse('rest_api:document-detail', args=(document.pk,)))
|
||||
self.client.delete(
|
||||
reverse('rest_api:document-detail', args=(document.pk,))
|
||||
)
|
||||
|
||||
self.assertEqual(Document.objects.count(), 0)
|
||||
self.assertEqual(Document.trash.count(), 1)
|
||||
@@ -156,7 +165,9 @@ class DocumentAPITestCase(APITestCase):
|
||||
self.assertEqual(Document.objects.count(), 0)
|
||||
self.assertEqual(Document.trash.count(), 1)
|
||||
|
||||
self.client.delete(reverse('rest_api:deleteddocument-detail', args=(document.pk,)))
|
||||
self.client.delete(
|
||||
reverse('rest_api:deleteddocument-detail', args=(document.pk,))
|
||||
)
|
||||
|
||||
self.assertEqual(Document.trash.count(), 0)
|
||||
|
||||
@@ -168,7 +179,9 @@ class DocumentAPITestCase(APITestCase):
|
||||
|
||||
document.delete()
|
||||
|
||||
self.client.post(reverse('rest_api:deleteddocument-restore', args=(document.pk,)))
|
||||
self.client.post(
|
||||
reverse('rest_api:deleteddocument-restore', args=(document.pk,))
|
||||
)
|
||||
|
||||
self.assertEqual(Document.trash.count(), 0)
|
||||
self.assertEqual(Document.objects.count(), 1)
|
||||
@@ -273,5 +286,5 @@ class DocumentAPITestCase(APITestCase):
|
||||
|
||||
del(buf)
|
||||
|
||||
#def test_document_set_document_type(self):
|
||||
# TODO: def test_document_set_document_type(self):
|
||||
# pass
|
||||
|
||||
@@ -144,7 +144,9 @@ class OfficeDocumentTestCase(TestCase):
|
||||
|
||||
def test_document_creation(self):
|
||||
self.assertEqual(self.document.file_mimetype, 'application/msword')
|
||||
self.assertEqual(self.document.file_mime_encoding, 'application/mswordbinary')
|
||||
self.assertEqual(
|
||||
self.document.file_mime_encoding, 'application/mswordbinary'
|
||||
)
|
||||
self.assertEqual(
|
||||
self.document.checksum,
|
||||
'03a7e9071d2c6ae05a6588acd7dff1d890fac2772cf61abd470c9ffa6ef71f03'
|
||||
|
||||
@@ -8,20 +8,19 @@ from django.core.urlresolvers import reverse
|
||||
from django.test.client import Client
|
||||
from django.test import TestCase, override_settings
|
||||
|
||||
from ..literals import DEFAULT_DELETE_PERIOD, DEFAULT_DELETE_TIME_UNIT
|
||||
from ..models import DeletedDocument, Document, DocumentType
|
||||
|
||||
from .literals import (
|
||||
TEST_ADMIN_PASSWORD, TEST_ADMIN_USERNAME, TEST_ADMIN_EMAIL,
|
||||
TEST_SMALL_DOCUMENT_PATH, TEST_DOCUMENT_TYPE
|
||||
)
|
||||
from ..models import DeletedDocument, Document, DocumentType
|
||||
|
||||
TEST_DOCUMENT_TYPE_EDITED_LABEL = 'test document type edited label'
|
||||
|
||||
|
||||
@override_settings(OCR_AUTO_OCR=False)
|
||||
class DocumentsViewsFunctionalTestCase(TestCase):
|
||||
"""
|
||||
Functional tests to make sure all the moving parts after creating a
|
||||
document from the frontend are working correctly
|
||||
"""
|
||||
|
||||
class DocumentsViewsTestCase(TestCase):
|
||||
def setUp(self):
|
||||
self.document_type = DocumentType.objects.create(
|
||||
label=TEST_DOCUMENT_TYPE
|
||||
@@ -94,62 +93,74 @@ class DocumentsViewsFunctionalTestCase(TestCase):
|
||||
response, 'roperties for document', status_code=200
|
||||
)
|
||||
|
||||
def test_document_type_views(self):
|
||||
# Check that there are no document types
|
||||
response = self.client.get(reverse('documents:document_type_list'))
|
||||
self.assertContains(response, 'Total: 1', status_code=200)
|
||||
|
||||
# Create a document type
|
||||
@override_settings(OCR_AUTO_OCR=False)
|
||||
class DocumentTypeViewsTestCase(TestCase):
|
||||
def setUp(self):
|
||||
self.admin_user = User.objects.create_superuser(
|
||||
username=TEST_ADMIN_USERNAME, email=TEST_ADMIN_EMAIL,
|
||||
password=TEST_ADMIN_PASSWORD
|
||||
)
|
||||
self.client = Client()
|
||||
# Login the admin user
|
||||
logged_in = self.client.login(
|
||||
username=TEST_ADMIN_USERNAME, password=TEST_ADMIN_PASSWORD
|
||||
)
|
||||
self.assertTrue(logged_in)
|
||||
self.assertTrue(self.admin_user.is_authenticated())
|
||||
|
||||
def tearDown(self):
|
||||
self.admin_user.delete()
|
||||
|
||||
def test_document_type_create_view(self):
|
||||
response = self.client.post(
|
||||
reverse('documents:document_type_create'),
|
||||
{'name': 'test document type 2'}, follow=True
|
||||
data={
|
||||
'label': TEST_DOCUMENT_TYPE,
|
||||
'delete_time_period': DEFAULT_DELETE_PERIOD,
|
||||
'delete_time_unit': DEFAULT_DELETE_TIME_UNIT
|
||||
}, follow=True
|
||||
)
|
||||
#TODO: FIX
|
||||
# self.assertContains(response, 'successfully', status_code=200)
|
||||
|
||||
# Check that there are two document types
|
||||
response = self.client.get(reverse('documents:document_type_list'))
|
||||
#TODO: FIX self.assertContains(response, 'Total: 2', status_code=200)
|
||||
self.assertContains(response, 'successfully', status_code=200)
|
||||
|
||||
self.assertEqual(self.document_type.label, TEST_DOCUMENT_TYPE)
|
||||
self.assertEqual(DocumentType.objects.count(), 1)
|
||||
self.assertEqual(
|
||||
DocumentType.objects.first().label, TEST_DOCUMENT_TYPE
|
||||
)
|
||||
|
||||
def test_document_type_delete_view(self):
|
||||
document_type = DocumentType.objects.create(
|
||||
label=TEST_DOCUMENT_TYPE
|
||||
)
|
||||
|
||||
# Edit the document type
|
||||
response = self.client.post(
|
||||
reverse(
|
||||
'documents:document_type_edit', args=(self.document_type.pk,)
|
||||
), data={'name': TEST_DOCUMENT_TYPE + 'partial'}, follow=True
|
||||
'documents:document_type_delete', args=(document_type.pk,)
|
||||
), follow=True
|
||||
)
|
||||
#TODO: FIX
|
||||
# self.assertContains(
|
||||
# response, 'Document type edited successfully', status_code=200
|
||||
#)
|
||||
|
||||
# Reload document type model data
|
||||
#self.document_type = DocumentType.objects.get(
|
||||
# pk=self.document_type.pk
|
||||
#)
|
||||
#TODO: FIX#
|
||||
#self.assertEqual(
|
||||
# self.document_type.name, TEST_DOCUMENT_TYPE + 'partial'
|
||||
#)
|
||||
self.assertContains(response, 'successfully', status_code=200)
|
||||
self.assertEqual(DocumentType.objects.count(), 0)
|
||||
|
||||
# Delete the document type
|
||||
#response = self.client.post(
|
||||
# reverse(
|
||||
# 'documents:document_type_delete', args=(self.document_type.pk,)
|
||||
# ), follow=True
|
||||
#)
|
||||
#TODO: FIX#
|
||||
# self.assertContains(
|
||||
# response, 'Document type: {0} deleted successfully'.format(
|
||||
# self.document_type.name
|
||||
# ), status_code=200
|
||||
#)
|
||||
def test_document_type_edit_view(self):
|
||||
document_type = DocumentType.objects.create(
|
||||
label=TEST_DOCUMENT_TYPE
|
||||
)
|
||||
|
||||
# Check that there are no document types
|
||||
#response = self.client.get(reverse('documents:document_type_list'))
|
||||
#TODO: FIX self.assertEqual(response.status_code, 200)
|
||||
#TODO: FIX
|
||||
#self.assertContains(
|
||||
# response, 'ocument types (0)', status_code=200
|
||||
#)
|
||||
response = self.client.post(
|
||||
reverse(
|
||||
'documents:document_type_edit', args=(document_type.pk,)
|
||||
), data={
|
||||
'label': TEST_DOCUMENT_TYPE_EDITED_LABEL,
|
||||
'delete_time_period': DEFAULT_DELETE_PERIOD,
|
||||
'delete_time_unit': DEFAULT_DELETE_TIME_UNIT
|
||||
}, follow=True
|
||||
)
|
||||
|
||||
self.assertContains(response, 'successfully', status_code=200)
|
||||
|
||||
self.assertEqual(
|
||||
DocumentType.objects.first().label,
|
||||
TEST_DOCUMENT_TYPE_EDITED_LABEL
|
||||
)
|
||||
|
||||
@@ -385,6 +385,21 @@ class DocumentTypeListView(SingleObjectListView):
|
||||
}
|
||||
|
||||
|
||||
class DocumentTypeCreateView(SingleObjectCreateView):
|
||||
fields = (
|
||||
'label', 'trash_time_period', 'trash_time_unit', 'delete_time_period',
|
||||
'delete_time_unit'
|
||||
)
|
||||
model = DocumentType
|
||||
post_action_redirect = reverse_lazy('documents:document_type_list')
|
||||
view_permission = permission_document_type_create
|
||||
|
||||
def get_extra_context(self):
|
||||
return {
|
||||
'title': _('Create document type'),
|
||||
}
|
||||
|
||||
|
||||
class DocumentTypeDeleteView(SingleObjectDeleteView):
|
||||
model = DocumentType
|
||||
post_action_redirect = reverse_lazy('documents:document_type_list')
|
||||
@@ -414,21 +429,6 @@ class DocumentTypeEditView(SingleObjectEditView):
|
||||
}
|
||||
|
||||
|
||||
class DocumentTypeCreateView(SingleObjectCreateView):
|
||||
fields = (
|
||||
'label', 'trash_time_period', 'trash_time_unit', 'delete_time_period',
|
||||
'delete_time_unit'
|
||||
)
|
||||
model = DocumentType
|
||||
post_action_redirect = reverse_lazy('documents:document_type_list')
|
||||
view_permission = permission_document_type_create
|
||||
|
||||
def get_extra_context(self):
|
||||
return {
|
||||
'title': _('Create document type'),
|
||||
}
|
||||
|
||||
|
||||
class DocumentTypeFilenameListView(SingleObjectListView):
|
||||
model = DocumentType
|
||||
view_permission = permission_document_type_view
|
||||
|
||||
Reference in New Issue
Block a user