Fix documents app view tests. Update code to match code style. PEP8 fixes.
This commit is contained in:
@@ -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
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user