Fix documents app view tests. Update code to match code style. PEP8 fixes.

This commit is contained in:
Roberto Rosario
2015-10-19 01:54:37 -04:00
parent bfe621ba89
commit 64faa0ca15
6 changed files with 105 additions and 80 deletions

View File

@@ -43,7 +43,6 @@ permission_document_version_revert = namespace.add_permission(
permission_document_view = namespace.add_permission( permission_document_view = namespace.add_permission(
name='document_view', label=_('View documents') name='document_view', label=_('View documents')
) )
permission_empty_trash = namespace.add_permission( permission_empty_trash = namespace.add_permission(
name='document_empty_trash', label=_('Empty trash') name='document_empty_trash', label=_('Empty trash')
) )
@@ -51,7 +50,6 @@ permission_empty_trash = namespace.add_permission(
setup_namespace = PermissionNamespace( setup_namespace = PermissionNamespace(
'documents_setup', label=_('Documents setup') 'documents_setup', label=_('Documents setup')
) )
permission_document_type_create = setup_namespace.add_permission( permission_document_type_create = setup_namespace.add_permission(
name='document_type_create', label=_('Create document types') name='document_type_create', label=_('Create document types')
) )

View File

@@ -36,7 +36,8 @@ TEST_NON_ASCII_COMPRESSED_DOCUMENT_FILENAME = 'I18N_title_áéíóúüñÑ.png.z
TEST_NON_ASCII_DOCUMENT_FILENAME = 'I18N_title_áéíóúüñÑ.png' TEST_NON_ASCII_DOCUMENT_FILENAME = 'I18N_title_áéíóúüñÑ.png'
TEST_OFFICE_DOCUMENT = 'simple_2_page_document.doc' TEST_OFFICE_DOCUMENT = 'simple_2_page_document.doc'
TEST_SMALL_DOCUMENT_FILENAME = 'title_page.png' TEST_SMALL_DOCUMENT_FILENAME = 'title_page.png'
TEST_SMALL_DOCUMENT_CHECKSUM = 'efa10e6cc21f83078aaa94d5cbe51de67b51af706143bafc7fd6d4c02124879a' TEST_SMALL_DOCUMENT_CHECKSUM = 'efa10e6cc21f83078aaa94d5cbe51de67b51af706143b\
afc7fd6d4c02124879a'
# File paths # File paths
TEST_COMPRESSED_DOCUMENT_PATH = os.path.join( TEST_COMPRESSED_DOCUMENT_PATH = os.path.join(

View File

@@ -42,10 +42,16 @@ class DocumentTypeAPITestCase(APITestCase):
def test_document_type_create(self): def test_document_type_create(self):
self.assertEqual(DocumentType.objects.all().count(), 0) 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().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): def test_document_type_edit_via_put(self):
document_type = DocumentType.objects.create(label=TEST_DOCUMENT_TYPE) document_type = DocumentType.objects.create(label=TEST_DOCUMENT_TYPE)
@@ -112,8 +118,9 @@ class DocumentAPITestCase(APITestCase):
document_data = loads(document_response.content) 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) self.assertEqual(Document.objects.count(), 1)
document = Document.objects.first() document = Document.objects.first()
@@ -140,7 +147,9 @@ class DocumentAPITestCase(APITestCase):
file_object=File(file_object), 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.objects.count(), 0)
self.assertEqual(Document.trash.count(), 1) self.assertEqual(Document.trash.count(), 1)
@@ -156,7 +165,9 @@ class DocumentAPITestCase(APITestCase):
self.assertEqual(Document.objects.count(), 0) self.assertEqual(Document.objects.count(), 0)
self.assertEqual(Document.trash.count(), 1) 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) self.assertEqual(Document.trash.count(), 0)
@@ -168,7 +179,9 @@ class DocumentAPITestCase(APITestCase):
document.delete() 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.trash.count(), 0)
self.assertEqual(Document.objects.count(), 1) self.assertEqual(Document.objects.count(), 1)
@@ -273,5 +286,5 @@ class DocumentAPITestCase(APITestCase):
del(buf) del(buf)
#def test_document_set_document_type(self): # TODO: def test_document_set_document_type(self):
# pass # pass

View File

@@ -144,7 +144,9 @@ class OfficeDocumentTestCase(TestCase):
def test_document_creation(self): def test_document_creation(self):
self.assertEqual(self.document.file_mimetype, 'application/msword') 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.assertEqual(
self.document.checksum, self.document.checksum,
'03a7e9071d2c6ae05a6588acd7dff1d890fac2772cf61abd470c9ffa6ef71f03' '03a7e9071d2c6ae05a6588acd7dff1d890fac2772cf61abd470c9ffa6ef71f03'

View File

@@ -8,20 +8,19 @@ from django.core.urlresolvers import reverse
from django.test.client import Client from django.test.client import Client
from django.test import TestCase, override_settings 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 ( from .literals import (
TEST_ADMIN_PASSWORD, TEST_ADMIN_USERNAME, TEST_ADMIN_EMAIL, TEST_ADMIN_PASSWORD, TEST_ADMIN_USERNAME, TEST_ADMIN_EMAIL,
TEST_SMALL_DOCUMENT_PATH, TEST_DOCUMENT_TYPE 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) @override_settings(OCR_AUTO_OCR=False)
class DocumentsViewsFunctionalTestCase(TestCase): class DocumentsViewsTestCase(TestCase):
"""
Functional tests to make sure all the moving parts after creating a
document from the frontend are working correctly
"""
def setUp(self): def setUp(self):
self.document_type = DocumentType.objects.create( self.document_type = DocumentType.objects.create(
label=TEST_DOCUMENT_TYPE label=TEST_DOCUMENT_TYPE
@@ -94,62 +93,74 @@ class DocumentsViewsFunctionalTestCase(TestCase):
response, 'roperties for document', status_code=200 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( response = self.client.post(
reverse('documents:document_type_create'), 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 self.assertContains(response, 'successfully', status_code=200)
response = self.client.get(reverse('documents:document_type_list'))
#TODO: FIX self.assertContains(response, 'Total: 2', 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( response = self.client.post(
reverse( reverse(
'documents:document_type_edit', args=(self.document_type.pk,) 'documents:document_type_delete', args=(document_type.pk,)
), data={'name': TEST_DOCUMENT_TYPE + 'partial'}, follow=True ), follow=True
) )
#TODO: FIX
# self.assertContains(
# response, 'Document type edited successfully', status_code=200
#)
# Reload document type model data self.assertContains(response, 'successfully', status_code=200)
#self.document_type = DocumentType.objects.get( self.assertEqual(DocumentType.objects.count(), 0)
# pk=self.document_type.pk
#)
#TODO: FIX#
#self.assertEqual(
# self.document_type.name, TEST_DOCUMENT_TYPE + 'partial'
#)
# Delete the document type def test_document_type_edit_view(self):
#response = self.client.post( document_type = DocumentType.objects.create(
# reverse( label=TEST_DOCUMENT_TYPE
# '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
#)
# Check that there are no document types response = self.client.post(
#response = self.client.get(reverse('documents:document_type_list')) reverse(
#TODO: FIX self.assertEqual(response.status_code, 200) 'documents:document_type_edit', args=(document_type.pk,)
#TODO: FIX ), data={
#self.assertContains( 'label': TEST_DOCUMENT_TYPE_EDITED_LABEL,
# response, 'ocument types (0)', status_code=200 '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
)

View File

@@ -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): class DocumentTypeDeleteView(SingleObjectDeleteView):
model = DocumentType model = DocumentType
post_action_redirect = reverse_lazy('documents:document_type_list') 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): class DocumentTypeFilenameListView(SingleObjectListView):
model = DocumentType model = DocumentType
view_permission = permission_document_type_view view_permission = permission_document_type_view