diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/test_shell.py | 16 | ||||
-rw-r--r-- | tests/unit/test_utils.py | 26 |
2 files changed, 40 insertions, 2 deletions
diff --git a/tests/unit/test_shell.py b/tests/unit/test_shell.py index 40881c2..3f077dc 100644 --- a/tests/unit/test_shell.py +++ b/tests/unit/test_shell.py @@ -1402,7 +1402,7 @@ class TestShell(unittest.TestCase): "secret_key"] swiftclient.shell.main(argv) temp_url.assert_called_with( - '/v1/AUTH_account/c/o', 60, 'secret_key', 'GET', absolute=False) + '/v1/AUTH_account/c/o', "60", 'secret_key', 'GET', absolute=False) @mock.patch('swiftclient.shell.generate_temp_url', return_value='') def test_absolute_expiry_temp_url(self, temp_url): @@ -1410,7 +1410,7 @@ class TestShell(unittest.TestCase): "secret_key", "--absolute"] swiftclient.shell.main(argv) temp_url.assert_called_with( - '/v1/AUTH_account/c/o', 60, 'secret_key', 'GET', absolute=True) + '/v1/AUTH_account/c/o', "60", 'secret_key', 'GET', absolute=True) def test_temp_url_output(self): argv = ["", "tempurl", "GET", "60", "/v1/a/c/o", @@ -1428,6 +1428,18 @@ class TestShell(unittest.TestCase): expected = "http://saio:8080%s" % expected self.assertEqual(expected, output.out) + def test_temp_url_error_output(self): + expected = 'path must be full path to an object e.g. /v1/a/c/o\n' + for bad_path in ('/v1/a/c', 'v1/a/c/o', '/v1/a/c/', '/v1/a//o', + 'http://saio/v1/a/c', 'http://v1/a/c/o'): + argv = ["", "tempurl", "GET", "60", bad_path, + "secret_key", "--absolute"] + with CaptureOutput(suppress_systemexit=True) as output: + swiftclient.shell.main(argv) + self.assertEqual(expected, output.err, + 'Expected %r but got %r for path %r' % + (expected, output.err, bad_path)) + @mock.patch('swiftclient.service.Connection') def test_capabilities(self, connection): argv = ["", "capabilities"] diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index 949c3e1..d2f6494 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -180,6 +180,32 @@ class TestTempURL(unittest.TestCase): self.assertEqual(exc_manager.exception.args[0], 'seconds must be a positive integer') + def test_generate_temp_url_bad_path(self): + with self.assertRaises(ValueError) as exc_manager: + u.generate_temp_url('/v1/a/c', 60, self.key, self.method) + self.assertEqual(exc_manager.exception.args[0], + 'path must be full path to an object e.g. /v1/a/c/o') + + with self.assertRaises(ValueError) as exc_manager: + u.generate_temp_url('v1/a/c/o', 60, self.key, self.method) + self.assertEqual(exc_manager.exception.args[0], + 'path must be full path to an object e.g. /v1/a/c/o') + + with self.assertRaises(ValueError) as exc_manager: + u.generate_temp_url('blah/v1/a/c/o', 60, self.key, self.method) + self.assertEqual(exc_manager.exception.args[0], + 'path must be full path to an object e.g. /v1/a/c/o') + + with self.assertRaises(ValueError) as exc_manager: + u.generate_temp_url('/v1//c/o', 60, self.key, self.method) + self.assertEqual(exc_manager.exception.args[0], + 'path must be full path to an object e.g. /v1/a/c/o') + + with self.assertRaises(ValueError) as exc_manager: + u.generate_temp_url('/v1/a/c/', 60, self.key, self.method) + self.assertEqual(exc_manager.exception.args[0], + 'path must be full path to an object e.g. /v1/a/c/o') + class TestTempURLUnicodePathAndKey(TestTempURL): url = u'/v1/\u00e4/c/\u00f3' |