Add functional document views test

This commit is contained in:
Roberto Rosario
2014-08-26 22:52:32 -04:00
parent adf4291ea4
commit 65ecb28c76

View File

@@ -22,6 +22,7 @@ TEST_ADMIN_EMAIL = 'admin@admin.com'
TEST_DOCUMENT_PATH = os.path.join(settings.BASE_DIR, 'contrib', 'sample_documents', 'mayan_11_1.pdf')
TEST_SIGNED_DOCUMENT_PATH = os.path.join(settings.BASE_DIR, 'contrib', 'sample_documents', 'mayan_11_1.pdf.gpg')
TEST_DOCUMENT_DESCRIPTION = 'test description'
TEST_DOCUMENT_TYPE = 'test_document_type'
class DocumentTestCase(TestCase):
@@ -278,3 +279,82 @@ class DocumentAPICreateDocumentTestCase(TestCase):
# The document was deleted from the the DB?
self.assertEqual(Document.objects.count(), 0)
class DocumentsViewsFunctionalTestCase(TestCase):
"""
Functional tests to make sure all the moving parts after creating a
document from the frontend are working correctly
"""
def setUp(self):
from sources.models import WebForm
from sources.literals import SOURCE_CHOICE_WEB_FORM
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())
# Create new webform source
response = self.client.post(reverse('setup_source_create', args=[SOURCE_CHOICE_WEB_FORM]), {'title': 'test', 'uncompress': 'n', 'enabled': True})
self.assertEqual(WebForm.objects.count(), 1)
# Upload the test document
with open(TEST_DOCUMENT_PATH) as file_descriptor:
response = self.client.post(reverse('upload_interactive'), {'file': file_descriptor})
self.assertEqual(Document.objects.count(), 1)
self.document = Document.objects.first()
def test_document_view(self):
response = self.client.get(reverse('document_list'))
self.assertEqual(response.status_code, 200)
self.assertTrue('List of documents (1)' in response.content)
# test document simple view
response = self.client.get(reverse('document_view_simple', args=[self.document.pk]))
self.assertEqual(response.status_code, 200)
self.assertTrue('Details for: mayan_11_1.pdf' in response.content)
# test document advanced view
response = self.client.get(reverse('document_view_advanced', args=[self.document.pk]))
self.assertEqual(response.status_code, 200)
self.assertTrue('Document properties for: mayan_11_1.pdf' in response.content)
def test_document_type_views(self):
# Check that there are no document types
response = self.client.get(reverse('document_type_list'))
self.assertEqual(response.status_code, 200)
self.assertTrue('List of document types (0)' in response.content)
# Create a document type
response = self.client.post(reverse('document_type_create'), data={'name': TEST_DOCUMENT_TYPE}, follow=True)
self.assertEqual(response.status_code, 200)
self.assertTrue('Document type created successfully' in response.content)
# Check that there is one document types
response = self.client.get(reverse('document_type_list'))
self.assertEqual(response.status_code, 200)
self.assertTrue('List of document types (1)' in response.content)
document_type = DocumentType.objects.first()
self.assertEqual(document_type.name, TEST_DOCUMENT_TYPE)
# Edit the document type
response = self.client.post(reverse('document_type_edit', args=[document_type.pk]), data={'name': TEST_DOCUMENT_TYPE + 'partial'}, follow=True)
self.assertEqual(response.status_code, 200)
self.assertTrue('Document type edited successfully' in response.content)
document_type = DocumentType.objects.first()
self.assertEqual(document_type.name, TEST_DOCUMENT_TYPE + 'partial')
# Delete the document type
response = self.client.post(reverse('document_type_delete', args=[document_type.pk]), follow=True)
self.assertEqual(response.status_code, 200)
self.assertTrue('Document type: {0} deleted successfully'.format(document_type.name) in response.content)
# Check that there are no document types
response = self.client.get(reverse('document_type_list'))
self.assertEqual(response.status_code, 200)
self.assertTrue('List of document types (0)' in response.content)