Skip to content

Commit

Permalink
Merge branch 'release-0.6.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
sneakypete81 committed Dec 8, 2013
2 parents 4deceb6 + acce9f5 commit f497adc
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
Trovebox Python Library Changelog
=================================

v0.6.1
======
* Perform user expansion when uploading files from the CLI (#59, #70)
* Remove redundant import (#67, #69)
* Functional test improvements (#68)

v0.6
======
* Support for many additional API endpoints (#56, #65)
Expand Down
1 change: 1 addition & 0 deletions tests/functional/test_photos.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def test_delete_upload(self):
self._delete_all()
self._create_test_photos()

@unittest.skip("This test doesn't work if the server is behind a cache")
def test_delete_source(self):
""" Test that photo source files can be deleted """
# Upload a new (duplicate) public photo
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import unicode_literals
import os
import sys
import shutil
import mock
try:
import StringIO as io # Python2
Expand Down Expand Up @@ -77,6 +78,35 @@ def test_post_files(self, _, mock_trovebox):
self.assertEqual(list(files.keys()), ["photo"])
self.assertEqual(files["photo"].name, self.test_file)

@mock.patch.object(trovebox.main.trovebox, "Trovebox")
@mock.patch('sys.stdout', new_callable=io.StringIO)
def test_post_files_with_user_expansion(self, _, mock_trovebox):
"""
Check that files are posted correctly when specified relative
to the '~' user directory
"""
post = mock_trovebox.return_value.post
user_file = "~/.trovebox_temporary_file"
expanded_file = os.path.expanduser(user_file)
shutil.copy(self.test_file, expanded_file)
try:
main(["-X", "POST", "-F", "photo=@%s" % user_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, expanded_file)
finally:
os.remove(expanded_file)

@mock.patch.object(trovebox.main.trovebox, "Trovebox")
@mock.patch('sys.stdout', new_callable=io.StringIO)
def test_post_missing_files(self, _, mock_trovebox):
"""Check that missing files cause an exception"""
post = mock_trovebox.return_value.post
with self.assertRaises(IOError):
main(["-X", "POST", "-F", "photo=@%s.missing" % self.test_file])

@mock.patch.object(sys, "exit", raise_exception)
@mock.patch('sys.stderr', new_callable=io.StringIO)
def test_unknown_arg(self, mock_stderr):
Expand Down
2 changes: 1 addition & 1 deletion trovebox/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""Current version string"""
__version__ = "0.6"
__version__ = "0.6.1"
5 changes: 1 addition & 4 deletions trovebox/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
"""
from __future__ import unicode_literals
import os
import io
try:
from configparser import ConfigParser # Python3
except ImportError:
from ConfigParser import SafeConfigParser as ConfigParser # Python2
try:
import io # Python3
except ImportError: # pragma: no cover
import StringIO as io # Python2

class Auth(object):
"""OAuth secrets"""
Expand Down
5 changes: 2 additions & 3 deletions trovebox/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,8 @@ def extract_files(params):
files = {}
updated_params = {}
for name in params:
if (name == "photo" and params[name].startswith("@") and
os.path.isfile(os.path.expanduser(params[name][1:]))):
files[name] = open(params[name][1:], 'rb')
if name == "photo" and params[name].startswith("@"):
files[name] = open(os.path.expanduser(params[name][1:]), 'rb')
else:
updated_params[name] = params[name]

Expand Down

0 comments on commit f497adc

Please sign in to comment.