Split tests into tests for models, views and API, very good recommendation from Two Scoops of Django by @pydanny and @audreyr.
This commit is contained in:
@@ -12,7 +12,11 @@ from .models import Index, IndexInstanceNode, IndexTemplateNode
|
||||
|
||||
class IndexTestCase(TestCase):
|
||||
def setUp(self):
|
||||
self.document_type = DocumentType.objects.create(name=TEST_DOCUMENT_TYPE)
|
||||
self.document_type = DocumentType.objects.create(label=TEST_DOCUMENT_TYPE)
|
||||
|
||||
ocr_settings = self.document_type.ocr_settings
|
||||
ocr_settings.auto_ocr = False
|
||||
ocr_settings.save()
|
||||
|
||||
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
|
||||
self.document = self.document_type.new_document(file_object=File(file_object))
|
||||
@@ -7,6 +7,7 @@ from django.core.files.base import File
|
||||
from django.test import TestCase
|
||||
|
||||
from documents.models import Document, DocumentType
|
||||
from documents.test_models import TEST_DOCUMENT_TYPE
|
||||
from django_gpg.literals import SIGNATURE_STATE_VALID
|
||||
from django_gpg.runtime import gpg
|
||||
|
||||
@@ -20,7 +21,7 @@ TEST_KEY_FILE = os.path.join(settings.BASE_DIR, 'contrib', 'sample_documents', '
|
||||
|
||||
class DocumentTestCase(TestCase):
|
||||
def setUp(self):
|
||||
self.document_type = DocumentType.objects.create(name='test doc type')
|
||||
self.document_type = DocumentType.objects.create(label=TEST_DOCUMENT_TYPE)
|
||||
|
||||
ocr_settings = self.document_type.ocr_settings
|
||||
ocr_settings.auto_ocr = False
|
||||
@@ -8,7 +8,7 @@ from .permissions import permission_document_view
|
||||
|
||||
document_search = SearchModel('documents', 'Document', permission=permission_document_view, serializer_string='documents.serializers.DocumentSerializer')
|
||||
|
||||
document_search.add_model_field(field='document_type__name', label=_('Document type'))
|
||||
document_search.add_model_field(field='document_type__label', label=_('Document type'))
|
||||
document_search.add_model_field(field='versions__mimetype', label=_('MIME type'))
|
||||
document_search.add_model_field(field='label', label=_('Label'))
|
||||
document_search.add_model_field(field='description', label=_('Description'))
|
||||
|
||||
108
mayan/apps/documents/test_api.py
Normal file
108
mayan/apps/documents/test_api.py
Normal file
@@ -0,0 +1,108 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from json import loads
|
||||
import os
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.files import File
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.test.client import Client
|
||||
from django.test import TestCase
|
||||
|
||||
from rest_framework import status
|
||||
from rest_framework.test import APIClient
|
||||
|
||||
from .models import Document, DocumentType
|
||||
from .test_models import (
|
||||
TEST_ADMIN_PASSWORD, TEST_ADMIN_USERNAME, TEST_ADMIN_EMAIL,
|
||||
TEST_SMALL_DOCUMENT_FILENAME, TEST_NON_ASCII_DOCUMENT_FILENAME,
|
||||
TEST_NON_ASCII_COMPRESSED_DOCUMENT_FILENAME, TEST_DOCUMENT_PATH,
|
||||
TEST_SIGNED_DOCUMENT_PATH, TEST_SMALL_DOCUMENT_PATH,
|
||||
TEST_NON_ASCII_DOCUMENT_PATH, TEST_NON_ASCII_COMPRESSED_DOCUMENT_PATH,
|
||||
TEST_DOCUMENT_DESCRIPTION, TEST_DOCUMENT_TYPE
|
||||
)
|
||||
|
||||
|
||||
class DocumentAPICreateDocumentTestCase(TestCase):
|
||||
"""
|
||||
Functional test to make sure all the moving parts to create a document from
|
||||
the API are working correctly
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
self.admin_user = User.objects.create_superuser(username=TEST_ADMIN_USERNAME, email=TEST_ADMIN_EMAIL, password=TEST_ADMIN_PASSWORD)
|
||||
self.document_type = DocumentType.objects.create(label=TEST_DOCUMENT_TYPE)
|
||||
|
||||
ocr_settings = self.document_type.ocr_settings
|
||||
ocr_settings.auto_ocr = False
|
||||
ocr_settings.save()
|
||||
|
||||
def test_uploading_a_document_using_token_auth(self):
|
||||
# Get the an user token
|
||||
token_client = APIClient()
|
||||
response = token_client.post(reverse('auth_token_obtain'), {'username': TEST_ADMIN_USERNAME, 'password': TEST_ADMIN_PASSWORD})
|
||||
|
||||
# Be able to get authentication token
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
# Make sure a token was returned
|
||||
self.assertTrue('token' in response.content)
|
||||
|
||||
token = loads(response.content)['token']
|
||||
|
||||
# Create a new client to simulate a different request
|
||||
document_client = APIClient()
|
||||
|
||||
# Create a blank document with no token in the header
|
||||
# TODO: Fix, must not be able to create the document with API token
|
||||
# with open(TEST_SMALL_DOCUMENT_PATH) as file_descriptor:
|
||||
# response = document_client.post(reverse('document-list'), {'document_type': self.document_type.pk, 'file': file_descriptor})
|
||||
|
||||
# Make sure toke authentication is working, should fail
|
||||
# TODO: FIX failing test: self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
|
||||
|
||||
document_client.credentials(HTTP_AUTHORIZATION='Token ' + token)
|
||||
|
||||
# Create a blank document
|
||||
with open(TEST_SMALL_DOCUMENT_PATH) as file_descriptor:
|
||||
document_response = document_client.post(reverse('document-list'), {'document_type': self.document_type.pk, 'file': file_descriptor})
|
||||
|
||||
self.assertEqual(document_response.status_code, status.HTTP_201_CREATED)
|
||||
|
||||
# The document was created in the DB?
|
||||
self.assertEqual(Document.objects.count(), 1)
|
||||
|
||||
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})
|
||||
|
||||
# Make sure the document uploaded correctly
|
||||
document = Document.objects.first()
|
||||
self.failUnlessEqual(document.exists(), True)
|
||||
self.failUnlessEqual(document.size, 272213)
|
||||
|
||||
self.failUnlessEqual(document.file_mimetype, 'application/pdf')
|
||||
self.failUnlessEqual(document.file_mime_encoding, 'binary')
|
||||
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 = reverse('document-detail', args=[Document.objects.first().pk])
|
||||
|
||||
response = document_client.post(document_url, {'description': 'edited test document'})
|
||||
|
||||
# self.assertTrue(document.description, 'edited test document')
|
||||
|
||||
# Make sure we can delete the document via the API
|
||||
response = document_client.delete(document_url)
|
||||
|
||||
# The document was deleted from the the DB?
|
||||
self.assertEqual(Document.objects.count(), 0)
|
||||
|
||||
def tearDown(self):
|
||||
self.document_type.delete()
|
||||
68
mayan/apps/documents/test_models.py
Normal file
68
mayan/apps/documents/test_models.py
Normal file
@@ -0,0 +1,68 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from json import loads
|
||||
import os
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.files import File
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.test.client import Client
|
||||
from django.test import TestCase
|
||||
|
||||
from rest_framework import status
|
||||
from rest_framework.test import APIClient
|
||||
|
||||
from .models import Document, DocumentType
|
||||
|
||||
TEST_ADMIN_PASSWORD = 'test_admin_password'
|
||||
TEST_ADMIN_USERNAME = 'test_admin'
|
||||
TEST_ADMIN_EMAIL = 'admin@admin.com'
|
||||
TEST_SMALL_DOCUMENT_FILENAME = 'title_page.png'
|
||||
TEST_NON_ASCII_DOCUMENT_FILENAME = 'I18N_title_áéíóúüñÑ.png'
|
||||
TEST_NON_ASCII_COMPRESSED_DOCUMENT_FILENAME = 'I18N_title_áéíóúüñÑ.png.zip'
|
||||
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_SMALL_DOCUMENT_PATH = os.path.join(settings.BASE_DIR, 'contrib', 'sample_documents', TEST_SMALL_DOCUMENT_FILENAME)
|
||||
TEST_NON_ASCII_DOCUMENT_PATH = os.path.join(settings.BASE_DIR, 'contrib', 'sample_documents', TEST_NON_ASCII_DOCUMENT_FILENAME)
|
||||
TEST_NON_ASCII_COMPRESSED_DOCUMENT_PATH = os.path.join(settings.BASE_DIR, 'contrib', 'sample_documents', TEST_NON_ASCII_COMPRESSED_DOCUMENT_FILENAME)
|
||||
TEST_DOCUMENT_DESCRIPTION = 'test description'
|
||||
TEST_DOCUMENT_TYPE = 'test_document_type'
|
||||
|
||||
|
||||
class DocumentTestCase(TestCase):
|
||||
def setUp(self):
|
||||
self.document_type = DocumentType.objects.create(label=TEST_DOCUMENT_TYPE)
|
||||
|
||||
ocr_settings = self.document_type.ocr_settings
|
||||
ocr_settings.auto_ocr = False
|
||||
ocr_settings.save()
|
||||
|
||||
with open(TEST_DOCUMENT_PATH) as file_object:
|
||||
self.document = self.document_type.new_document(file_object=File(file_object), label='mayan_11_1.pdf')
|
||||
|
||||
def test_document_creation(self):
|
||||
self.failUnlessEqual(self.document_type.label, TEST_DOCUMENT_TYPE)
|
||||
|
||||
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.label, 'mayan_11_1.pdf')
|
||||
self.failUnlessEqual(self.document.checksum, 'c637ffab6b8bb026ed3784afdb07663fddc60099853fae2be93890852a69ecf3')
|
||||
self.failUnlessEqual(self.document.page_count, 47)
|
||||
|
||||
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
|
||||
self.document.new_version(file_object=File(file_object))
|
||||
|
||||
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
|
||||
self.document.new_version(file_object=File(file_object), comment='test comment 1')
|
||||
|
||||
self.failUnlessEqual(self.document.versions.count(), 3)
|
||||
|
||||
def tearDown(self):
|
||||
self.document.delete()
|
||||
self.document_type.delete()
|
||||
99
mayan/apps/documents/test_views.py
Normal file
99
mayan/apps/documents/test_views.py
Normal file
@@ -0,0 +1,99 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from json import loads
|
||||
import os
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.files import File
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.test.client import Client
|
||||
from django.test import TestCase
|
||||
|
||||
from rest_framework import status
|
||||
from rest_framework.test import APIClient
|
||||
|
||||
from .models import Document, DocumentType
|
||||
from .test_models import (
|
||||
TEST_ADMIN_PASSWORD, TEST_ADMIN_USERNAME, TEST_ADMIN_EMAIL,
|
||||
TEST_SMALL_DOCUMENT_FILENAME, TEST_NON_ASCII_DOCUMENT_FILENAME,
|
||||
TEST_NON_ASCII_COMPRESSED_DOCUMENT_FILENAME, TEST_DOCUMENT_PATH,
|
||||
TEST_SIGNED_DOCUMENT_PATH, TEST_SMALL_DOCUMENT_PATH,
|
||||
TEST_NON_ASCII_DOCUMENT_PATH, TEST_NON_ASCII_COMPRESSED_DOCUMENT_PATH,
|
||||
TEST_DOCUMENT_DESCRIPTION, TEST_DOCUMENT_TYPE
|
||||
)
|
||||
|
||||
|
||||
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 WebFormSource
|
||||
from sources.literals import SOURCE_CHOICE_WEB_FORM
|
||||
|
||||
DocumentType.objects.all().delete() # Clean up <orphan document type>
|
||||
self.document_type = DocumentType.objects.create(label=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
|
||||
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_SMALL_DOCUMENT_PATH) as file_descriptor:
|
||||
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.assertContains(response, 'Total: 1', status_code=200)
|
||||
|
||||
# test document simple view
|
||||
response = self.client.get(reverse('documents:document_properties', args=[self.document.pk]))
|
||||
self.assertContains(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
|
||||
response = self.client.post(reverse('documents:document_type_create'), {'name': 'test document type 2'}, 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.assertEqual(self.document_type.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)
|
||||
#TODO: FIX self.assertContains(response, 'Document type edited successfully', status_code=200)
|
||||
|
||||
# Reload document type model data
|
||||
self.document = DocumentType.objects.get(pk=self.document.pk)
|
||||
#TODO: FIX self.assertEqual(self.document_type.name, TEST_DOCUMENT_TYPE + 'partial')
|
||||
|
||||
# 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)
|
||||
|
||||
# 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)
|
||||
@@ -1,223 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from json import loads
|
||||
import os
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.files import File
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.test.client import Client
|
||||
from django.test import TestCase
|
||||
|
||||
from rest_framework import status
|
||||
from rest_framework.test import APIClient
|
||||
|
||||
from .models import Document, DocumentType
|
||||
|
||||
TEST_ADMIN_PASSWORD = 'test_admin_password'
|
||||
TEST_ADMIN_USERNAME = 'test_admin'
|
||||
TEST_ADMIN_EMAIL = 'admin@admin.com'
|
||||
TEST_SMALL_DOCUMENT_FILENAME = 'title_page.png'
|
||||
TEST_NON_ASCII_DOCUMENT_FILENAME = 'I18N_title_áéíóúüñÑ.png'
|
||||
TEST_NON_ASCII_COMPRESSED_DOCUMENT_FILENAME = 'I18N_title_áéíóúüñÑ.png.zip'
|
||||
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_SMALL_DOCUMENT_PATH = os.path.join(settings.BASE_DIR, 'contrib', 'sample_documents', TEST_SMALL_DOCUMENT_FILENAME)
|
||||
TEST_NON_ASCII_DOCUMENT_PATH = os.path.join(settings.BASE_DIR, 'contrib', 'sample_documents', TEST_NON_ASCII_DOCUMENT_FILENAME)
|
||||
TEST_NON_ASCII_COMPRESSED_DOCUMENT_PATH = os.path.join(settings.BASE_DIR, 'contrib', 'sample_documents', TEST_NON_ASCII_COMPRESSED_DOCUMENT_FILENAME)
|
||||
TEST_DOCUMENT_DESCRIPTION = 'test description'
|
||||
TEST_DOCUMENT_TYPE = 'test_document_type'
|
||||
|
||||
|
||||
class DocumentTestCase(TestCase):
|
||||
def setUp(self):
|
||||
self.document_type = DocumentType.objects.create(name='test doc type')
|
||||
|
||||
ocr_settings = self.document_type.ocr_settings
|
||||
ocr_settings.auto_ocr = False
|
||||
ocr_settings.save()
|
||||
|
||||
with open(TEST_DOCUMENT_PATH) as file_object:
|
||||
self.document = self.document_type.new_document(file_object=File(file_object), label='mayan_11_1.pdf')
|
||||
|
||||
def test_document_creation(self):
|
||||
self.failUnlessEqual(self.document_type.name, 'test doc type')
|
||||
|
||||
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.label, 'mayan_11_1.pdf')
|
||||
self.failUnlessEqual(self.document.checksum, 'c637ffab6b8bb026ed3784afdb07663fddc60099853fae2be93890852a69ecf3')
|
||||
self.failUnlessEqual(self.document.page_count, 47)
|
||||
|
||||
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
|
||||
self.document.new_version(file_object=File(file_object))
|
||||
|
||||
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
|
||||
self.document.new_version(file_object=File(file_object), comment='test comment 1')
|
||||
|
||||
self.failUnlessEqual(self.document.versions.count(), 3)
|
||||
|
||||
def tearDown(self):
|
||||
self.document.delete()
|
||||
self.document_type.delete()
|
||||
|
||||
|
||||
class DocumentAPICreateDocumentTestCase(TestCase):
|
||||
"""
|
||||
Functional test to make sure all the moving parts to create a document from
|
||||
the API are working correctly
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
self.admin_user = User.objects.create_superuser(username=TEST_ADMIN_USERNAME, email=TEST_ADMIN_EMAIL, password=TEST_ADMIN_PASSWORD)
|
||||
self.document_type = DocumentType.objects.create(name='test doc type')
|
||||
|
||||
ocr_settings = self.document_type.ocr_settings
|
||||
ocr_settings.auto_ocr = False
|
||||
ocr_settings.save()
|
||||
|
||||
def test_uploading_a_document_using_token_auth(self):
|
||||
# Get the an user token
|
||||
token_client = APIClient()
|
||||
response = token_client.post(reverse('auth_token_obtain'), {'username': TEST_ADMIN_USERNAME, 'password': TEST_ADMIN_PASSWORD})
|
||||
|
||||
# Be able to get authentication token
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
# Make sure a token was returned
|
||||
self.assertTrue('token' in response.content)
|
||||
|
||||
token = loads(response.content)['token']
|
||||
|
||||
# Create a new client to simulate a different request
|
||||
document_client = APIClient()
|
||||
|
||||
# Create a blank document with no token in the header
|
||||
# TODO: Fix, must not be able to create the document with API token
|
||||
# with open(TEST_SMALL_DOCUMENT_PATH) as file_descriptor:
|
||||
# response = document_client.post(reverse('document-list'), {'document_type': self.document_type.pk, 'file': file_descriptor})
|
||||
|
||||
# Make sure toke authentication is working, should fail
|
||||
# TODO: FIX failing test: self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
|
||||
|
||||
document_client.credentials(HTTP_AUTHORIZATION='Token ' + token)
|
||||
|
||||
# Create a blank document
|
||||
with open(TEST_SMALL_DOCUMENT_PATH) as file_descriptor:
|
||||
document_response = document_client.post(reverse('document-list'), {'document_type': self.document_type.pk, 'file': file_descriptor})
|
||||
|
||||
self.assertEqual(document_response.status_code, status.HTTP_201_CREATED)
|
||||
|
||||
# The document was created in the DB?
|
||||
self.assertEqual(Document.objects.count(), 1)
|
||||
|
||||
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})
|
||||
|
||||
# Make sure the document uploaded correctly
|
||||
document = Document.objects.first()
|
||||
self.failUnlessEqual(document.exists(), True)
|
||||
self.failUnlessEqual(document.size, 272213)
|
||||
|
||||
self.failUnlessEqual(document.file_mimetype, 'application/pdf')
|
||||
self.failUnlessEqual(document.file_mime_encoding, 'binary')
|
||||
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 = reverse('document-detail', args=[Document.objects.first().pk])
|
||||
|
||||
response = document_client.post(document_url, {'description': 'edited test document'})
|
||||
|
||||
# self.assertTrue(document.description, 'edited test document')
|
||||
|
||||
# Make sure we can delete the document via the API
|
||||
response = document_client.delete(document_url)
|
||||
|
||||
# The document was deleted from the the DB?
|
||||
self.assertEqual(Document.objects.count(), 0)
|
||||
|
||||
def tearDown(self):
|
||||
self.document_type.delete()
|
||||
|
||||
|
||||
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 WebFormSource
|
||||
from sources.literals import SOURCE_CHOICE_WEB_FORM
|
||||
|
||||
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
|
||||
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_SMALL_DOCUMENT_PATH) as file_descriptor:
|
||||
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.assertContains(response, 'Total: 1', status_code=200)
|
||||
|
||||
# test document simple view
|
||||
response = self.client.get(reverse('documents:document_properties', args=[self.document.pk]))
|
||||
self.assertContains(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
|
||||
response = self.client.post(reverse('documents:document_type_create'), {'name': 'test document type 2'}, 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.assertEqual(self.document_type.name, 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)
|
||||
#TODO: FIX self.assertContains(response, 'Document type edited successfully', status_code=200)
|
||||
|
||||
# Reload document type model data
|
||||
self.document = DocumentType.objects.get(pk=self.document.pk)
|
||||
#TODO: FIX self.assertEqual(self.document_type.name, TEST_DOCUMENT_TYPE + 'partial')
|
||||
|
||||
# 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)
|
||||
|
||||
# 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)
|
||||
48
mayan/apps/dynamic_search/test_models.py
Normal file
48
mayan/apps/dynamic_search/test_models.py
Normal file
@@ -0,0 +1,48 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.files.base import File
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.test.client import Client
|
||||
from django.test import TestCase
|
||||
|
||||
from documents.models import Document, DocumentType
|
||||
from documents.search import document_search
|
||||
from documents.tests import (
|
||||
TEST_ADMIN_PASSWORD, TEST_ADMIN_USERNAME, TEST_ADMIN_EMAIL,
|
||||
TEST_DOCUMENT_PATH, TEST_DOCUMENT_TYPE, TEST_SMALL_DOCUMENT_PATH
|
||||
)
|
||||
|
||||
|
||||
class DocumentSearchTestCase(TestCase):
|
||||
def setUp(self):
|
||||
self.admin_user = User.objects.create_superuser(username=TEST_ADMIN_USERNAME, email=TEST_ADMIN_EMAIL, password=TEST_ADMIN_PASSWORD)
|
||||
self.document_type = DocumentType.objects.create(label=TEST_DOCUMENT_TYPE)
|
||||
|
||||
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
|
||||
self.document = self.document_type.new_document(file_object=File(file_object), label='mayan_11_1.pdf')
|
||||
|
||||
def test_simple_search_after_related_name_change(self):
|
||||
"""
|
||||
Test that simple search works after related_name changes to
|
||||
document versions and document version pages
|
||||
"""
|
||||
|
||||
model_list, result_set, elapsed_time = document_search.search({'q': 'Mayan'}, user=self.admin_user)
|
||||
self.assertEqual(len(result_set), 1)
|
||||
self.assertEqual(list(model_list), [self.document])
|
||||
|
||||
def test_advanced_search_after_related_name_change(self):
|
||||
# Test versions__filename
|
||||
model_list, result_set, elapsed_time = document_search.search({'label': self.document.label}, user=self.admin_user)
|
||||
self.assertEqual(len(result_set), 1)
|
||||
self.assertEqual(list(model_list), [self.document])
|
||||
|
||||
# Test versions__mimetype
|
||||
model_list, result_set, elapsed_time = document_search.search({'versions__mimetype': self.document.file_mimetype}, user=self.admin_user)
|
||||
self.assertEqual(len(result_set), 1)
|
||||
self.assertEqual(list(model_list), [self.document])
|
||||
|
||||
def tearDown(self):
|
||||
self.document.delete()
|
||||
self.document_type.delete()
|
||||
@@ -14,40 +14,6 @@ from documents.tests import (
|
||||
)
|
||||
|
||||
|
||||
class DocumentSearchTestCase(TestCase):
|
||||
def setUp(self):
|
||||
self.admin_user = User.objects.create_superuser(username=TEST_ADMIN_USERNAME, email=TEST_ADMIN_EMAIL, password=TEST_ADMIN_PASSWORD)
|
||||
self.document_type = DocumentType.objects.create(name=TEST_DOCUMENT_TYPE)
|
||||
|
||||
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
|
||||
self.document = self.document_type.new_document(file_object=File(file_object), label='mayan_11_1.pdf')
|
||||
|
||||
def test_simple_search_after_related_name_change(self):
|
||||
"""
|
||||
Test that simple search works after related_name changes to
|
||||
document versions and document version pages
|
||||
"""
|
||||
|
||||
model_list, result_set, elapsed_time = document_search.search({'q': 'Mayan'}, user=self.admin_user)
|
||||
self.assertEqual(len(result_set), 1)
|
||||
self.assertEqual(list(model_list), [self.document])
|
||||
|
||||
def test_advanced_search_after_related_name_change(self):
|
||||
# Test versions__filename
|
||||
model_list, result_set, elapsed_time = document_search.search({'label': self.document.label}, user=self.admin_user)
|
||||
self.assertEqual(len(result_set), 1)
|
||||
self.assertEqual(list(model_list), [self.document])
|
||||
|
||||
# Test versions__mimetype
|
||||
model_list, result_set, elapsed_time = document_search.search({'versions__mimetype': self.document.file_mimetype}, user=self.admin_user)
|
||||
self.assertEqual(len(result_set), 1)
|
||||
self.assertEqual(list(model_list), [self.document])
|
||||
|
||||
def tearDown(self):
|
||||
self.document.delete()
|
||||
self.document_type.delete()
|
||||
|
||||
|
||||
class Issue46TestCase(TestCase):
|
||||
"""
|
||||
Functional tests to make sure issue 46 is fixed
|
||||
@@ -63,7 +29,7 @@ class Issue46TestCase(TestCase):
|
||||
|
||||
self.document_count = 30
|
||||
|
||||
self.document_type = DocumentType.objects.create(name='test doc type')
|
||||
self.document_type = DocumentType.objects.create(label=TEST_DOCUMENT_TYPE)
|
||||
|
||||
# Upload 30 instances of the same test document
|
||||
for i in range(self.document_count):
|
||||
@@ -11,6 +11,7 @@ from authentication.tests import (
|
||||
TEST_ADMIN_EMAIL, TEST_ADMIN_PASSWORD, TEST_ADMIN_USERNAME
|
||||
)
|
||||
from documents.models import Document, DocumentType
|
||||
from documents.test_models import TEST_DOCUMENT_TYPE
|
||||
|
||||
from .models import Folder
|
||||
|
||||
@@ -19,7 +20,7 @@ TEST_DOCUMENT_PATH = os.path.join(settings.BASE_DIR, 'contrib', 'sample_document
|
||||
|
||||
class FolderTestCase(TestCase):
|
||||
def setUp(self):
|
||||
self.document_type = DocumentType.objects.create(name='test doc type')
|
||||
self.document_type = DocumentType.objects.create(label=TEST_DOCUMENT_TYPE)
|
||||
|
||||
with open(TEST_DOCUMENT_PATH) as file_object:
|
||||
self.document = self.document_type.new_document(file_object=File(file_object))
|
||||
@@ -9,7 +9,7 @@ from documents.tests import TEST_SMALL_DOCUMENT_PATH, TEST_DOCUMENT_TYPE
|
||||
|
||||
class DocumentOCRTestCase(TransactionTestCase):
|
||||
def setUp(self):
|
||||
self.document_type = DocumentType.objects.create(name=TEST_DOCUMENT_TYPE)
|
||||
self.document_type = DocumentType.objects.create(label=TEST_DOCUMENT_TYPE)
|
||||
|
||||
ocr_settings = self.document_type.ocr_settings
|
||||
ocr_settings.auto_ocr = False
|
||||
@@ -30,7 +30,7 @@ class UploadDocumentTestCase(TestCase):
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
self.document_type = DocumentType.objects.create(name=TEST_DOCUMENT_TYPE)
|
||||
self.document_type = DocumentType.objects.create(label=TEST_DOCUMENT_TYPE)
|
||||
ocr_settings = self.document_type.ocr_settings
|
||||
ocr_settings.auto_ocr = False
|
||||
ocr_settings.save()
|
||||
@@ -7,6 +7,7 @@ from django.core.files.base import File
|
||||
from django.test import TestCase
|
||||
|
||||
from documents.models import Document, DocumentType
|
||||
from documents.test_models import TEST_DOCUMENT_TYPE
|
||||
|
||||
from .literals import COLOR_RED
|
||||
from .models import Tag
|
||||
@@ -16,7 +17,7 @@ TEST_DOCUMENT_PATH = os.path.join(settings.BASE_DIR, 'contrib', 'sample_document
|
||||
|
||||
class TagTestCase(TestCase):
|
||||
def setUp(self):
|
||||
self.document_type = DocumentType(name='test doc type')
|
||||
self.document_type = DocumentType(label=TEST_DOCUMENT_TYPE)
|
||||
self.document_type.save()
|
||||
|
||||
self.document = Document(
|
||||
Reference in New Issue
Block a user