Add tests for unicode filename uploads
This commit is contained in:
parent
7e889ee3b0
commit
d6d84f4e0b
4 changed files with 63 additions and 0 deletions
BIN
tests/data/test_ünicode_photo.jpg
Normal file
BIN
tests/data/test_ünicode_photo.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
|
@ -121,6 +121,27 @@ class TestPhotos(test_base.TestBase):
|
||||||
photos[1].delete()
|
photos[1].delete()
|
||||||
self.photos[0].update(permission=False)
|
self.photos[0].update(permission=False)
|
||||||
|
|
||||||
|
# Unicode filename upload not working due to frontend bug 1433
|
||||||
|
@unittest.expectedFailure
|
||||||
|
def test_upload_unicode_filename(self):
|
||||||
|
"""Test that a photo with a unicode filename can be uploaded"""
|
||||||
|
ret_val = self.client.photo.upload(u"tests/data/test_\xfcnicode_photo.jpg",
|
||||||
|
title=self.TEST_TITLE)
|
||||||
|
# Check that there are now four photos
|
||||||
|
self.photos = self.client.photos.list()
|
||||||
|
self.assertEqual(len(self.photos), 4)
|
||||||
|
|
||||||
|
# Check that the upload return value was correct
|
||||||
|
pathOriginals = [photo.pathOriginal for photo in self.photos]
|
||||||
|
self.assertIn(ret_val.pathOriginal, pathOriginals)
|
||||||
|
|
||||||
|
# Delete the photo
|
||||||
|
ret_val.delete()
|
||||||
|
|
||||||
|
# Check that it's gone
|
||||||
|
self.photos = self.client.photos.list()
|
||||||
|
self.assertEqual(len(self.photos), 3)
|
||||||
|
|
||||||
def test_update(self):
|
def test_update(self):
|
||||||
""" Update a photo by editing the title """
|
""" Update a photo by editing the title """
|
||||||
title = "\xfcmlaut" # umlauted umlaut
|
title = "\xfcmlaut" # umlauted umlaut
|
||||||
|
|
1
tests/unit/data/ünicode_test_file.txt
Normal file
1
tests/unit/data/ünicode_test_file.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Test File
|
|
@ -23,6 +23,8 @@ def raise_exception(_):
|
||||||
|
|
||||||
class TestCli(unittest.TestCase):
|
class TestCli(unittest.TestCase):
|
||||||
test_file = os.path.join("tests", "unit", "data", "test_file.txt")
|
test_file = os.path.join("tests", "unit", "data", "test_file.txt")
|
||||||
|
test_unicode_file = os.path.join("tests", "unit", "data",
|
||||||
|
"\xfcnicode_test_file.txt")
|
||||||
|
|
||||||
@mock.patch.object(trovebox.main.trovebox, "Trovebox")
|
@mock.patch.object(trovebox.main.trovebox, "Trovebox")
|
||||||
@mock.patch('sys.stdout', new_callable=io.StringIO)
|
@mock.patch('sys.stdout', new_callable=io.StringIO)
|
||||||
|
@ -107,6 +109,45 @@ class TestCli(unittest.TestCase):
|
||||||
with self.assertRaises(IOError):
|
with self.assertRaises(IOError):
|
||||||
main(["-X", "POST", "-F", "photo=@%s.missing" % self.test_file])
|
main(["-X", "POST", "-F", "photo=@%s.missing" % self.test_file])
|
||||||
|
|
||||||
|
@mock.patch.object(trovebox.main.trovebox, "Trovebox")
|
||||||
|
@mock.patch('sys.stdout', new_callable=io.StringIO)
|
||||||
|
def test_post_unicode_files(self, _, mock_trovebox):
|
||||||
|
"""Check that unicode filenames are posted correctly"""
|
||||||
|
post = mock_trovebox.return_value.post
|
||||||
|
|
||||||
|
# Python 2.x provides encoded commandline arguments
|
||||||
|
file_param = "photo=@%s" % self.test_unicode_file
|
||||||
|
if sys.version < '3':
|
||||||
|
file_param = file_param.encode(sys.getfilesystemencoding())
|
||||||
|
|
||||||
|
main(["-X", "POST", "-F", "photo=@%s" % self.test_unicode_file])
|
||||||
|
# It's not possible to directly compare the file object,
|
||||||
|
# so check it manually
|
||||||
|
files = post.call_args[1]["files"]
|
||||||
|
self.assertEqual(list(files.keys()), ["photo"])
|
||||||
|
self.assertEqual(files["photo"].name, self.test_unicode_file)
|
||||||
|
|
||||||
|
@unittest.skipIf(sys.version >= '3',
|
||||||
|
"Python3 only uses unicode commandline arguments")
|
||||||
|
@mock.patch('trovebox.main.sys.getfilesystemencoding')
|
||||||
|
@mock.patch.object(trovebox.main.trovebox, "Trovebox")
|
||||||
|
@mock.patch('sys.stdout', new_callable=io.StringIO)
|
||||||
|
def test_post_utf8_files(self, _, mock_trovebox, mock_getfilesystemencoding):
|
||||||
|
"""Check that utf-8 encoded filenames are posted correctly"""
|
||||||
|
post = mock_trovebox.return_value.post
|
||||||
|
# Make the system think its filesystemencoding is utf-8
|
||||||
|
mock_getfilesystemencoding.return_value = "utf-8"
|
||||||
|
|
||||||
|
file_param = "photo=@%s" % self.test_unicode_file
|
||||||
|
file_param = file_param.encode("utf-8")
|
||||||
|
|
||||||
|
main(["-X", "POST", "-F", file_param])
|
||||||
|
# It's not possible to directly compare the file object,
|
||||||
|
# so check it manually
|
||||||
|
files = post.call_args[1]["files"]
|
||||||
|
self.assertEqual(list(files.keys()), ["photo"])
|
||||||
|
self.assertEqual(files["photo"].name, self.test_unicode_file)
|
||||||
|
|
||||||
@mock.patch.object(sys, "exit", raise_exception)
|
@mock.patch.object(sys, "exit", raise_exception)
|
||||||
@mock.patch('sys.stderr', new_callable=io.StringIO)
|
@mock.patch('sys.stderr', new_callable=io.StringIO)
|
||||||
def test_unknown_arg(self, mock_stderr):
|
def test_unknown_arg(self, mock_stderr):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue