Update tests

This commit is contained in:
Roberto Rosario
2014-12-09 03:18:16 -04:00
parent af51acebf5
commit 9b83c3bd3e
3 changed files with 23 additions and 108 deletions

View File

@@ -6,7 +6,6 @@ from django.conf import settings
from django.core.files.base import File
from django.test import TestCase
from documents.literals import VERSION_UPDATE_MAJOR
from documents.models import Document, DocumentType
from django_gpg.literals import SIGNATURE_STATE_VALID
from django_gpg.runtime import gpg
@@ -43,7 +42,6 @@ class DocumentTestCase(TestCase):
with open(TEST_SIGNED_DOCUMENT_PATH) as file_object:
new_version_data = {
'comment': 'test comment 1',
'version_update': VERSION_UPDATE_MAJOR,
}
self.document.new_version(file=File(file_object, name='mayan_11_1.pdf.gpg'), **new_version_data)
@@ -54,7 +52,6 @@ class DocumentTestCase(TestCase):
def test_detached_signatures(self):
new_version_data = {
'comment': 'test comment 2',
'version_update': VERSION_UPDATE_MAJOR,
}
with open(TEST_DOCUMENT_PATH) as file_object:
self.document.new_version(file=File(file_object), **new_version_data)

View File

@@ -13,7 +13,6 @@ from django.test import TestCase
from rest_framework import status
from rest_framework.test import APIClient
from .literals import VERSION_UPDATE_MAJOR
from .models import Document, DocumentType
TEST_ADMIN_PASSWORD = 'test_admin_password'
@@ -46,27 +45,19 @@ class DocumentTestCase(TestCase):
self.failUnlessEqual(self.document.checksum, 'c637ffab6b8bb026ed3784afdb07663fddc60099853fae2be93890852a69ecf3')
self.failUnlessEqual(self.document.page_count, 47)
self.failUnlessEqual(self.document.latest_version.get_formated_version(), '1.0.0')
# self.failUnlessEqual(self.document.has_detached_signature(), False)
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
new_version_data = {
'comment': 'test comment 1',
'version_update': VERSION_UPDATE_MAJOR,
}
self.document.new_version(file_object=File(file_object), **new_version_data)
self.document.new_version(file_object=File(file_object))
self.failUnlessEqual(self.document.latest_version.get_formated_version(), '2.0.0')
new_version_data = {
'comment': 'test comment 2',
'version_update': VERSION_UPDATE_MAJOR,
}
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
self.document.new_version(file_object=File(file_object), **new_version_data)
self.failUnlessEqual(self.document.latest_version.get_formated_version(), '3.0.0')
self.failUnlessEqual(self.document.versions.count(), 3)
def tearDown(self):
self.document.delete()
@@ -127,83 +118,6 @@ class DocumentSearchTestCase(TestCase):
self.document_type.delete()
class DocumentUploadFunctionalTestCase(TestCase):
"""
Functional test to make sure all the moving parts to create a document from
the frontend are working correctly
"""
def setUp(self):
self.document_type = DocumentType.objects.create(name='test doc type')
self.admin_user = User.objects.create_superuser(username=TEST_ADMIN_USERNAME, email=TEST_ADMIN_EMAIL, password=TEST_ADMIN_PASSWORD)
self.client = Client()
def test_upload_a_document(self):
from sources.models import WebFormSource
from sources.literals import SOURCE_CHOICE_WEB_FORM
# 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
self.client.post(reverse('sources:setup_source_create', args=[SOURCE_CHOICE_WEB_FORM]), {'title': 'test', 'uncompress': 'n', 'enabled': True})
self.assertEqual(WebFormSource.objects.count(), 1)
# Upload the test document
with open(TEST_DOCUMENT_PATH) as file_descriptor:
self.client.post(reverse('sources:upload_interactive'), {'file': file_descriptor, 'document_type_id': self.document_type.pk})
self.assertEqual(Document.objects.count(), 1)
self.document = Document.objects.all().first()
self.failUnlessEqual(self.document.exists(), True)
self.failUnlessEqual(self.document.size, 272213)
self.failUnlessEqual(self.document.file_mimetype, 'application/pdf')
self.failUnlessEqual(self.document.file_mime_encoding, 'binary')
self.failUnlessEqual(self.document.file_filename, 'mayan_11_1.pdf')
self.failUnlessEqual(self.document.checksum, 'c637ffab6b8bb026ed3784afdb07663fddc60099853fae2be93890852a69ecf3')
self.failUnlessEqual(self.document.page_count, 47)
# Delete the document
self.client.post(reverse('documents:document_delete', args=[self.document.pk]))
self.assertEqual(Document.objects.count(), 0)
def test_issue_25(self):
from sources.models import WebFormSource
from sources.literals import SOURCE_CHOICE_WEB_FORM
# 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
self.client.post(reverse('sources:setup_source_create', args=[SOURCE_CHOICE_WEB_FORM]), {'title': 'test', 'uncompress': 'n', 'enabled': True})
self.assertEqual(WebFormSource.objects.count(), 1)
# Upload the test document
with open(TEST_DOCUMENT_PATH) as file_descriptor:
self.client.post(reverse('sources:upload_interactive'), {'file': file_descriptor, 'label': 'test document', 'description': TEST_DOCUMENT_DESCRIPTION, 'document_type_id': self.document_type.pk})
self.assertEqual(Document.objects.count(), 1)
document = Document.objects.all().first()
# Test for issue 25 during creation
self.failUnlessEqual(document.description, TEST_DOCUMENT_DESCRIPTION)
# Reset description
document.description = ''
document.save()
self.failUnlessEqual(document.description, '')
# Test for issue 25 during editing
self.client.post(reverse('documents:document_edit', args=[document.pk]), {'description': TEST_DOCUMENT_DESCRIPTION})
# Fetch document again and test description
document = Document.objects.all().first()
self.failUnlessEqual(document.description, TEST_DOCUMENT_DESCRIPTION)
class DocumentAPICreateDocumentTestCase(TestCase):
"""
Functional test to make sure all the moving parts to create a document from
@@ -232,7 +146,7 @@ class DocumentAPICreateDocumentTestCase(TestCase):
# Create a blank document with no token in the header
with open(TEST_SMALL_DOCUMENT_PATH) as file_descriptor:
response = document_client.post(reverse('newdocument-view'), {'document_type': self.document_type, 'label': 'test document', 'file': file_descriptor})
response = document_client.post(reverse('newdocument-view'), {'document_type': self.document_type.pk, 'file': file_descriptor})
# Make sure toke authentication is working, should fail
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
@@ -241,13 +155,14 @@ class DocumentAPICreateDocumentTestCase(TestCase):
# Create a blank document
with open(TEST_SMALL_DOCUMENT_PATH) as file_descriptor:
document_response = document_client.post(reverse('newdocument-view'), {'document_type': self.document_type, 'label': 'test document', 'file': file_descriptor})
self.assertEqual(document_response.status_code, status.HTTP_201_CREATED)
document_response = document_client.post(reverse('newdocument-view'), {'document_type': self.document_type.pk, 'file': file_descriptor})
self.assertEqual(document_response.status_code, status.HTTP_202_ACCEPTED)
# The document was created in the DB?
self.assertEqual(Document.objects.count(), 1)
new_version_url = loads(document_response.content)['new_version']
new_version_url = reverse('document-new-version', args=[Document.objects.first().pk])
with open(TEST_DOCUMENT_PATH) as file_descriptor:
response = document_client.post(new_version_url, {'file': file_descriptor})
@@ -259,12 +174,12 @@ class DocumentAPICreateDocumentTestCase(TestCase):
self.failUnlessEqual(document.file_mimetype, 'application/pdf')
self.failUnlessEqual(document.file_mime_encoding, 'binary')
self.failUnlessEqual(document.file_filename, 'mayan_11_1.pdf')
self.failUnlessEqual(document.label, TEST_SMALL_DOCUMENT_FILENAME)
self.failUnlessEqual(document.checksum, 'c637ffab6b8bb026ed3784afdb07663fddc60099853fae2be93890852a69ecf3')
self.failUnlessEqual(document.page_count, 47)
# Make sure we can edit the document via the API
document_url = loads(document_response.content)['url']
document_url = reverse('document-detail', args=[Document.objects.first().pk])
response = document_client.post(document_url, {'description': 'edited test document'})
@@ -276,6 +191,9 @@ class DocumentAPICreateDocumentTestCase(TestCase):
# The document was deleted from the the DB?
self.assertEqual(Document.objects.count(), 0)
def tearDown(self):
self.document_type.delete()
class DocumentsViewsFunctionalTestCase(TestCase):
"""
@@ -287,7 +205,8 @@ class DocumentsViewsFunctionalTestCase(TestCase):
from sources.models import WebFormSource
from sources.literals import SOURCE_CHOICE_WEB_FORM
self.document_type = DocumentType.objects.create(name='test doc type')
DocumentType.objects.all().delete() # Clean up <orphan document type>
self.document_type = DocumentType.objects.create(name=TEST_DOCUMENT_TYPE)
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
@@ -300,10 +219,14 @@ class DocumentsViewsFunctionalTestCase(TestCase):
# Upload the test document
with open(TEST_SMALL_DOCUMENT_PATH) as file_descriptor:
self.client.post(reverse('sources:upload_interactive'), {'file': file_descriptor, 'document_type_id': self.document_type.pk})
self.client.post(reverse('sources:upload_interactive'), {'document-language': 'eng', 'source-file': file_descriptor, 'document_type_id': self.document_type.pk})
self.assertEqual(Document.objects.count(), 1)
self.document = Document.objects.first()
def tearDown(self):
self.document.delete()
self.document_type.delete()
def test_document_view(self):
response = self.client.get(reverse('documents:document_list'))
self.assertEqual(response.status_code, 200)
@@ -312,28 +235,24 @@ class DocumentsViewsFunctionalTestCase(TestCase):
# test document simple view
response = self.client.get(reverse('documents:document_properties', args=[self.document.pk]))
self.assertEqual(response.status_code, 200)
self.assertTrue('Details for' in response.content)
# test document advanced view
response = self.client.get(reverse('documents:document_view_advanced', args=[self.document.pk]))
self.assertEqual(response.status_code, 200)
self.assertTrue('ocument properties for' in response.content)
self.assertTrue('ocument properties' in response.content)
def test_document_type_views(self):
# Check that there are no document types
response = self.client.get(reverse('documents:document_type_list'))
self.assertEqual(response.status_code, 200)
self.assertTrue('ocument types (0)' in response.content)
self.assertTrue('ocument types (1)' in response.content)
# Create a document type
response = self.client.post(reverse('documents:document_type_create'), data={'name': TEST_DOCUMENT_TYPE}, follow=True)
print response.content
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('documents:document_type_list'))
self.assertEqual(response.status_code, 200)
self.assertTrue('ocument types (1)' in response.content)
self.assertTrue('Document types (2)' in response.content)
document_type = DocumentType.objects.first()
self.assertEqual(document_type.name, TEST_DOCUMENT_TYPE)

View File

@@ -7,7 +7,6 @@ from django.core.urlresolvers import reverse
from django.test.client import Client
from django.test import TestCase
from documents.literals import VERSION_UPDATE_MAJOR
from documents.models import Document, DocumentType
from sources.literals import SOURCE_CHOICE_WEB_FORM
from sources.models import WebFormSource