Add unicode filename test for the StagingFile class.
This commit is contained in:
@@ -53,7 +53,9 @@ class StagingFile(object):
|
||||
).decode('utf8')
|
||||
else:
|
||||
self.filename = filename
|
||||
self.encoded_filename = base64.urlsafe_b64encode(filename.encode('utf8'))
|
||||
self.encoded_filename = base64.urlsafe_b64encode(
|
||||
filename.encode('utf8')
|
||||
)
|
||||
|
||||
def __unicode__(self):
|
||||
return unicode(self.filename)
|
||||
|
||||
34
mayan/apps/sources/tests/test_classes.py
Normal file
34
mayan/apps/sources/tests/test_classes.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
from documents.tests import TEST_NON_ASCII_DOCUMENT_PATH
|
||||
|
||||
from ..classes import StagingFile
|
||||
|
||||
|
||||
class StagingFileTestCase(TestCase):
|
||||
def test_unicode_staging_file(self):
|
||||
temporary_directory = tempfile.mkdtemp()
|
||||
shutil.copy(TEST_NON_ASCII_DOCUMENT_PATH, temporary_directory)
|
||||
|
||||
filename = os.path.basename(TEST_NON_ASCII_DOCUMENT_PATH)
|
||||
|
||||
class MockStagingFolder(object):
|
||||
self.folder_path = temporary_directory
|
||||
|
||||
staging_file_1 = StagingFile(
|
||||
staging_folder=MockStagingFolder(),
|
||||
filename=filename
|
||||
)
|
||||
|
||||
staging_file_2 = StagingFile(
|
||||
staging_folder=MockStagingFolder(),
|
||||
encoded_filename=staging_file_1.encoded_filename
|
||||
)
|
||||
|
||||
self.assertEqual(filename, staging_file_2.filename)
|
||||
Reference in New Issue
Block a user