Improve Python 3 support in the sources app.
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -3,7 +3,14 @@ from __future__ import unicode_literals
|
|||||||
import base64
|
import base64
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import urllib
|
|
||||||
|
try:
|
||||||
|
# Python 2
|
||||||
|
from urllib import unquote_plus
|
||||||
|
except ImportError:
|
||||||
|
# Python 3
|
||||||
|
from urllib.parse import unquote_plus
|
||||||
|
|
||||||
|
|
||||||
from django.core.files import File
|
from django.core.files import File
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
@@ -39,7 +46,7 @@ class StagingFile(object):
|
|||||||
if encoded_filename:
|
if encoded_filename:
|
||||||
self.encoded_filename = str(encoded_filename)
|
self.encoded_filename = str(encoded_filename)
|
||||||
self.filename = base64.urlsafe_b64decode(
|
self.filename = base64.urlsafe_b64decode(
|
||||||
urllib.unquote_plus(self.encoded_filename)
|
unquote_plus(self.encoded_filename)
|
||||||
).decode('utf8')
|
).decode('utf8')
|
||||||
else:
|
else:
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ class DocumentUploadTestCase(GenericDocumentViewTestCase):
|
|||||||
self.document.delete()
|
self.document.delete()
|
||||||
|
|
||||||
def _request_upload_wizard(self):
|
def _request_upload_wizard(self):
|
||||||
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
|
with open(TEST_SMALL_DOCUMENT_PATH, 'rb') as file_object:
|
||||||
return self.post(
|
return self.post(
|
||||||
'sources:upload_interactive', args=(self.source.pk,), data={
|
'sources:upload_interactive', args=(self.source.pk,), data={
|
||||||
'source-file': file_object,
|
'source-file': file_object,
|
||||||
@@ -82,7 +82,7 @@ class DocumentUploadTestCase(GenericDocumentViewTestCase):
|
|||||||
obj=self.document_type, permission=permission_document_create
|
obj=self.document_type, permission=permission_document_create
|
||||||
)
|
)
|
||||||
|
|
||||||
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
|
with open(TEST_SMALL_DOCUMENT_PATH, 'rb') as file_object:
|
||||||
response = self.post(
|
response = self.post(
|
||||||
'sources:upload_interactive', args=(self.source.pk,), data={
|
'sources:upload_interactive', args=(self.source.pk,), data={
|
||||||
'source-file': file_object,
|
'source-file': file_object,
|
||||||
@@ -142,7 +142,7 @@ class DocumentUploadIssueTestCase(GenericViewTestCase):
|
|||||||
self.assertEqual(WebFormSource.objects.count(), 1)
|
self.assertEqual(WebFormSource.objects.count(), 1)
|
||||||
|
|
||||||
# Upload the test document
|
# Upload the test document
|
||||||
with open(TEST_SMALL_DOCUMENT_PATH) as file_descriptor:
|
with open(TEST_SMALL_DOCUMENT_PATH, 'rb') as file_descriptor:
|
||||||
self.post(
|
self.post(
|
||||||
'sources:upload_interactive', data={
|
'sources:upload_interactive', data={
|
||||||
'document-language': 'eng', 'source-file': file_descriptor,
|
'document-language': 'eng', 'source-file': file_descriptor,
|
||||||
|
|||||||
Reference in New Issue
Block a user