Renamed OpenPhoto to Trovebox
This commit is contained in:
parent
57b593d245
commit
6f70330994
30 changed files with 368 additions and 365 deletions
|
@ -11,8 +11,8 @@ try:
|
|||
except ImportError:
|
||||
import unittest
|
||||
|
||||
import openphoto
|
||||
from openphoto.main import main
|
||||
import trovebox
|
||||
from trovebox.main import main
|
||||
|
||||
class TestException(Exception):
|
||||
pass
|
||||
|
@ -23,53 +23,53 @@ def raise_exception(_):
|
|||
class TestCli(unittest.TestCase):
|
||||
test_file = os.path.join("tests", "unit", "data", "test_file.txt")
|
||||
|
||||
@mock.patch.object(openphoto.main.openphoto, "OpenPhoto")
|
||||
@mock.patch.object(trovebox.main.trovebox, "Trovebox")
|
||||
@mock.patch('sys.stdout', new_callable=io.StringIO)
|
||||
def test_defaults(self, _, mock_openphoto):
|
||||
def test_defaults(self, _, mock_trovebox):
|
||||
"""Check that the default behaviour is correct"""
|
||||
get = mock_openphoto.return_value.get
|
||||
get = mock_trovebox.return_value.get
|
||||
main([])
|
||||
mock_openphoto.assert_called_with(config_file=None)
|
||||
mock_trovebox.assert_called_with(config_file=None)
|
||||
get.assert_called_with("/photos/list.json", process_response=False)
|
||||
|
||||
@mock.patch.object(openphoto.main.openphoto, "OpenPhoto")
|
||||
@mock.patch.object(trovebox.main.trovebox, "Trovebox")
|
||||
@mock.patch('sys.stdout', new_callable=io.StringIO)
|
||||
def test_config(self, _, mock_openphoto):
|
||||
def test_config(self, _, mock_trovebox):
|
||||
"""Check that a config file can be specified"""
|
||||
main(["--config=test"])
|
||||
mock_openphoto.assert_called_with(config_file="test")
|
||||
mock_trovebox.assert_called_with(config_file="test")
|
||||
|
||||
@mock.patch.object(openphoto.main.openphoto, "OpenPhoto")
|
||||
@mock.patch.object(trovebox.main.trovebox, "Trovebox")
|
||||
@mock.patch('sys.stdout', new_callable=io.StringIO)
|
||||
def test_get(self, mock_stdout, mock_openphoto):
|
||||
def test_get(self, mock_stdout, mock_trovebox):
|
||||
"""Check that the get operation is working"""
|
||||
get = mock_openphoto.return_value.get
|
||||
get = mock_trovebox.return_value.get
|
||||
get.return_value = "Result"
|
||||
main(["-X", "GET", "-h", "test_host", "-e", "test_endpoint", "-F",
|
||||
"field1=1", "-F", "field2=2"])
|
||||
mock_openphoto.assert_called_with(host="test_host")
|
||||
mock_trovebox.assert_called_with(host="test_host")
|
||||
get.assert_called_with("test_endpoint", field1="1", field2="2",
|
||||
process_response=False)
|
||||
self.assertEqual(mock_stdout.getvalue(), "Result\n")
|
||||
|
||||
@mock.patch.object(openphoto.main.openphoto, "OpenPhoto")
|
||||
@mock.patch.object(trovebox.main.trovebox, "Trovebox")
|
||||
@mock.patch('sys.stdout', new_callable=io.StringIO)
|
||||
def test_post(self, mock_stdout, mock_openphoto):
|
||||
def test_post(self, mock_stdout, mock_trovebox):
|
||||
"""Check that the post operation is working"""
|
||||
post = mock_openphoto.return_value.post
|
||||
post = mock_trovebox.return_value.post
|
||||
post.return_value = "Result"
|
||||
main(["-X", "POST", "-h", "test_host", "-e", "test_endpoint", "-F",
|
||||
"field1=1", "-F", "field2=2"])
|
||||
mock_openphoto.assert_called_with(host="test_host")
|
||||
mock_trovebox.assert_called_with(host="test_host")
|
||||
post.assert_called_with("test_endpoint", field1="1", field2="2",
|
||||
files={}, process_response=False)
|
||||
self.assertEqual(mock_stdout.getvalue(), "Result\n")
|
||||
|
||||
@mock.patch.object(openphoto.main.openphoto, "OpenPhoto")
|
||||
@mock.patch.object(trovebox.main.trovebox, "Trovebox")
|
||||
@mock.patch('sys.stdout', new_callable=io.StringIO)
|
||||
def test_post_files(self, _, mock_openphoto):
|
||||
def test_post_files(self, _, mock_trovebox):
|
||||
"""Check that files are posted correctly"""
|
||||
post = mock_openphoto.return_value.post
|
||||
post = mock_trovebox.return_value.post
|
||||
main(["-X", "POST", "-F", "photo=@%s" % self.test_file])
|
||||
# It's not possible to directly compare the file object,
|
||||
# so check it manually
|
||||
|
@ -104,7 +104,7 @@ class TestCli(unittest.TestCase):
|
|||
mock_stdout.getvalue())
|
||||
self.assertIn("To get your credentials", mock_stdout.getvalue())
|
||||
|
||||
@mock.patch.object(openphoto.main.openphoto, "OpenPhoto")
|
||||
@mock.patch.object(trovebox.main.trovebox, "Trovebox")
|
||||
@mock.patch('sys.stdout', new_callable=io.StringIO)
|
||||
def test_verbose(self, mock_stdout, _):
|
||||
"""Check that the verbose option is working"""
|
||||
|
@ -112,11 +112,11 @@ class TestCli(unittest.TestCase):
|
|||
self.assertIn("Method: GET", mock_stdout.getvalue())
|
||||
self.assertIn("Endpoint: /photos/list.json", mock_stdout.getvalue())
|
||||
|
||||
@mock.patch.object(openphoto.main.openphoto, "OpenPhoto")
|
||||
@mock.patch.object(trovebox.main.trovebox, "Trovebox")
|
||||
@mock.patch('sys.stdout', new_callable=io.StringIO)
|
||||
def test_pretty_print(self, mock_stdout, mock_openphoto):
|
||||
def test_pretty_print(self, mock_stdout, mock_trovebox):
|
||||
"""Check that the pretty-print option is working"""
|
||||
get = mock_openphoto.return_value.get
|
||||
get = mock_trovebox.return_value.get
|
||||
get.return_value = '{"test":1}'
|
||||
main(["-p"])
|
||||
self.assertEqual(mock_stdout.getvalue(), '{\n "test":1\n}\n')
|
||||
|
@ -125,5 +125,5 @@ class TestCli(unittest.TestCase):
|
|||
def test_version(self, mock_stdout):
|
||||
"""Check that the version string is correctly printed"""
|
||||
main(["--version"])
|
||||
self.assertEqual(mock_stdout.getvalue(), openphoto.__version__ + "\n")
|
||||
self.assertEqual(mock_stdout.getvalue(), trovebox.__version__ + "\n")
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue