Remove typecasting of file objects into Django's File class, not needed in Django >1.8.x.

This commit is contained in:
Roberto Rosario
2016-03-14 20:20:54 -04:00
parent f5d2ea7d9e
commit 9823202405
14 changed files with 36 additions and 50 deletions

View File

@@ -3,7 +3,6 @@ from __future__ import absolute_import, unicode_literals
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group
from django.core.exceptions import PermissionDenied
from django.core.files import File
from django.test import TestCase, override_settings
from documents.models import Document, DocumentType
@@ -32,17 +31,17 @@ class PermissionTestCase(TestCase):
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
self.document_1 = self.document_type_1.new_document(
file_object=File(file_object)
file_object=file_object
)
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
self.document_2 = self.document_type_1.new_document(
file_object=File(file_object)
file_object=file_object
)
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
self.document_3 = self.document_type_2.new_document(
file_object=File(file_object)
file_object=file_object
)
self.user = get_user_model().objects.create(

View File

@@ -4,7 +4,6 @@ import datetime
import time
from django.contrib.auth import get_user_model
from django.core.files import File
from django.test import TestCase, override_settings
from django.utils.timezone import now
@@ -35,7 +34,7 @@ class DocumentCheckoutTestCase(TestCase):
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
self.document = self.document_type.new_document(
file_object=File(file_object)
file_object=file_object
)
def tearDown(self):
@@ -66,7 +65,7 @@ class DocumentCheckoutTestCase(TestCase):
with self.assertRaises(NewDocumentVersionNotAllowed):
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
self.document.new_version(file_object=File(file_object))
self.document.new_version(file_object=file_object)
def test_checkin_in(self):
expiration_datetime = now() + datetime.timedelta(days=1)

View File

@@ -1,7 +1,6 @@
from __future__ import unicode_literals
from django.contrib.auth import get_user_model
from django.core.files import File
from django.core.urlresolvers import reverse
from django.test.client import Client
from django.test import TestCase
@@ -43,7 +42,7 @@ class DocumentStateViewTestCase(TestCase):
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
self.document = self.document_type.new_document(
file_object=File(file_object)
file_object=file_object
)
def tearDown(self):

View File

@@ -8,7 +8,6 @@ from json import loads
from django.contrib.auth import get_user_model
from django.core.files import File
from django.core.urlresolvers import reverse
from django.test import override_settings
from django.utils.six import BytesIO
@@ -152,7 +151,7 @@ class DocumentAPITestCase(APITestCase):
def test_document_move_to_trash(self):
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
document = self.document_type.new_document(
file_object=File(file_object),
file_object=file_object,
)
self.client.delete(
@@ -165,7 +164,7 @@ class DocumentAPITestCase(APITestCase):
def test_deleted_document_delete_from_trash(self):
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
document = self.document_type.new_document(
file_object=File(file_object),
file_object=file_object,
)
document.delete()
@@ -182,7 +181,7 @@ class DocumentAPITestCase(APITestCase):
def test_deleted_document_restore(self):
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
document = self.document_type.new_document(
file_object=File(file_object),
file_object=file_object,
)
document.delete()
@@ -197,7 +196,7 @@ class DocumentAPITestCase(APITestCase):
def test_document_new_version_upload(self):
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
document = self.document_type.new_document(
file_object=File(file_object),
file_object=file_object,
)
# Artifical delay since MySQL doesn't store microsecond data in
@@ -230,14 +229,14 @@ class DocumentAPITestCase(APITestCase):
def test_document_version_revert(self):
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
document = self.document_type.new_document(
file_object=File(file_object),
file_object=file_object,
)
# Needed by MySQL as milliseconds value is not store in timestamp field
time.sleep(1)
with open(TEST_DOCUMENT_PATH) as file_object:
document.new_version(file_object=File(file_object))
document.new_version(file_object=file_object)
self.assertEqual(document.versions.count(), 2)
@@ -256,7 +255,7 @@ class DocumentAPITestCase(APITestCase):
def test_document_download(self):
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
document = self.document_type.new_document(
file_object=File(file_object),
file_object=file_object,
)
response = self.client.get(
@@ -276,7 +275,7 @@ class DocumentAPITestCase(APITestCase):
def test_document_version_download(self):
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
document = self.document_type.new_document(
file_object=File(file_object),
file_object=file_object,
)
response = self.client.get(

View File

@@ -4,7 +4,6 @@ from __future__ import unicode_literals
import time
from django.core.files import File
from django.core.urlresolvers import reverse
from acls.models import AccessControlList
@@ -26,7 +25,7 @@ from .test_views import GenericDocumentViewTestCase
class DocumentsLinksTestCase(GenericDocumentViewTestCase):
def test_document_version_revert_link_no_permission(self):
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
self.document.new_version(file_object=File(file_object))
self.document.new_version(file_object=file_object)
self.assertTrue(self.document.versions.count(), 2)
@@ -44,7 +43,7 @@ class DocumentsLinksTestCase(GenericDocumentViewTestCase):
time.sleep(2)
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
self.document.new_version(file_object=File(file_object))
self.document.new_version(file_object=file_object)
self.assertTrue(self.document.versions.count(), 2)

View File

@@ -3,7 +3,6 @@ from __future__ import unicode_literals
from datetime import timedelta
import time
from django.core.files import File
from django.test import TestCase, override_settings
from ..exceptions import NewDocumentVersionNotAllowed
@@ -25,7 +24,7 @@ class DocumentTestCase(TestCase):
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'
file_object=file_object, label='mayan_11_1.pdf'
)
def tearDown(self):
@@ -48,11 +47,11 @@ class DocumentTestCase(TestCase):
def test_version_creation(self):
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
self.document.new_version(file_object=File(file_object))
self.document.new_version(file_object=file_object)
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
self.document.new_version(
file_object=File(file_object), comment='test comment 1'
file_object=file_object, comment='test comment 1'
)
self.assertEqual(self.document.versions.count(), 3)
@@ -144,7 +143,7 @@ class OfficeDocumentTestCase(TestCase):
with open(TEST_OFFICE_DOCUMENT_PATH) as file_object:
self.document = self.document_type.new_document(
file_object=File(file_object)
file_object=file_object
)
def tearDown(self):
@@ -171,7 +170,7 @@ class MultiPageTiffTestCase(TestCase):
with open(TEST_MULTI_PAGE_TIFF_PATH) as file_object:
self.document = self.document_type.new_document(
file_object=File(file_object)
file_object=file_object
)
def tearDown(self):
@@ -196,7 +195,7 @@ class DocumentVersionTestCase(TestCase):
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
self.document = self.document_type.new_document(
file_object=File(file_object)
file_object=file_object
)
def tearDown(self):
@@ -207,7 +206,7 @@ class DocumentVersionTestCase(TestCase):
with open(TEST_DOCUMENT_PATH) as file_object:
self.document.new_version(
file_object=File(file_object)
file_object=file_object
)
self.assertEqual(self.document.versions.count(), 2)
@@ -226,7 +225,7 @@ class DocumentVersionTestCase(TestCase):
with open(TEST_DOCUMENT_PATH) as file_object:
self.document.new_version(
file_object=File(file_object)
file_object=file_object
)
self.assertEqual(self.document.versions.count(), 2)
@@ -274,7 +273,7 @@ class NewVersionBlockTestCase(TestCase):
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
self.document = self.document_type.new_document(
file_object=File(file_object)
file_object=file_object
)
def tearDown(self):
@@ -314,4 +313,4 @@ class NewVersionBlockTestCase(TestCase):
with self.assertRaises(NewDocumentVersionNotAllowed):
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
self.document.new_version(file_object=File(file_object))
self.document.new_version(file_object=file_object)

View File

@@ -3,7 +3,6 @@
from __future__ import unicode_literals
from django.contrib.contenttypes.models import ContentType
from django.core.files import File
from django.test import override_settings
from django.utils.six import BytesIO
@@ -49,7 +48,7 @@ class GenericDocumentViewTestCase(GenericViewTestCase):
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'
file_object=file_object, label='mayan_11_1.pdf'
)
def tearDown(self):

View File

@@ -3,7 +3,6 @@ from __future__ import unicode_literals
from json import loads
from django.contrib.auth import get_user_model
from django.core.files import File
from django.core.urlresolvers import reverse
from django.test import override_settings
@@ -39,7 +38,7 @@ class SearchAPITestCase(APITestCase):
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
document = document_type.new_document(
file_object=File(file_object),
file_object=file_object,
)
response = self.client.get(

View File

@@ -1,7 +1,6 @@
from __future__ import unicode_literals
from django.contrib.auth import get_user_model
from django.core.files.base import File
from django.test import TestCase
from documents.models import DocumentType
@@ -24,7 +23,7 @@ class DocumentSearchTestCase(TestCase):
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'
file_object=file_object, label='mayan_11_1.pdf'
)
def tearDown(self):

View File

@@ -1,7 +1,6 @@
from __future__ import unicode_literals
from django.contrib.auth import get_user_model
from django.core.files.base import File
from django.core.urlresolvers import reverse
from django.test import TestCase
from django.test.client import Client
@@ -42,7 +41,7 @@ class Issue46TestCase(TestCase):
for i in range(self.document_count):
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
self.document_type.new_document(
file_object=File(file_object),
file_object=file_object,
label='test document',
)

View File

@@ -1,7 +1,6 @@
from __future__ import unicode_literals
from django.contrib.auth import get_user_model
from django.core.files import File
from django.core.urlresolvers import reverse
from django.test import override_settings
@@ -77,7 +76,7 @@ class FolderAPITestCase(APITestCase):
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
document = document_type.new_document(
file_object=File(file_object),
file_object=file_object,
)
self.client.post(
@@ -97,7 +96,7 @@ class FolderAPITestCase(APITestCase):
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
document = document_type.new_document(
file_object=File(file_object),
file_object=file_object,
)
folder.documents.add(document)

View File

@@ -1,7 +1,6 @@
from __future__ import unicode_literals
from django.contrib.auth import get_user_model
from django.core.files.base import File
from django.test import TestCase
from documents.models import DocumentType
@@ -23,7 +22,7 @@ class FolderTestCase(TestCase):
with open(TEST_DOCUMENT_PATH) as file_object:
self.document = self.document_type.new_document(
file_object=File(file_object)
file_object=file_object
)
self.user = get_user_model().objects.create_superuser(

View File

@@ -3,7 +3,6 @@ from __future__ import unicode_literals
import json
from django.contrib.auth import get_user_model
from django.core.files import File
from django.core.urlresolvers import reverse
from rest_framework import status
@@ -37,7 +36,7 @@ class OCRAPITestCase(APITestCase):
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
self.document = self.document_type.new_document(
file_object=File(file_object),
file_object=file_object,
)
def tearDown(self):

View File

@@ -1,7 +1,6 @@
from __future__ import unicode_literals
from django.contrib.auth import get_user_model
from django.core.files import File
from django.core.urlresolvers import reverse
from django.test import override_settings
@@ -89,7 +88,7 @@ class TagAPITestCase(APITestCase):
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
document = document_type.new_document(
file_object=File(file_object),
file_object=file_object,
)
self.client.post(
@@ -109,7 +108,7 @@ class TagAPITestCase(APITestCase):
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
document = document_type.new_document(
file_object=File(file_object),
file_object=file_object,
)
tag.documents.add(document)