Improved test coverage of form_signature

Added four new test cases to execute path of invalid arguments. This
improved test coverage of file specified from 80% to 91%.

Change-Id: I63c2e7bab3f01121301d78b687687208a58401c0
This commit is contained in:
Sarafraj Singh 2016-02-05 17:28:26 +00:00
parent ab448f2b6d
commit 13edc9a865

View File

@ -69,6 +69,42 @@ class TestFormSignature(unittest.TestCase):
usage = 'Syntax: swift-form-signature <path>'
self.assertTrue(usage in out.getvalue())
def test_invalid_filesize_arg(self):
out = StringIO()
key = 'secret squirrel'
with mock.patch('sys.stdout', out):
exitcode = form_signature.main([
'/path/to/swift-form-signature',
'/v1/a/c/o', '', '-1', '34', '3600', key])
self.assertNotEqual(exitcode, 0)
def test_invalid_filecount_arg(self):
out = StringIO()
key = 'secret squirrel'
with mock.patch('sys.stdout', out):
exitcode = form_signature.main([
'/path/to/swift-form-signature',
'/v1/a/c/o', '', '12', '-34', '3600', key])
self.assertNotEqual(exitcode, 0)
def test_invalid_path_arg(self):
out = StringIO()
key = 'secret squirrel'
with mock.patch('sys.stdout', out):
exitcode = form_signature.main([
'/path/to/swift-form-signature',
'/v1/a/', '', '12', '34', '3600', key])
self.assertNotEqual(exitcode, 0)
def test_invalid_seconds_arg(self):
out = StringIO()
key = 'secret squirrel'
with mock.patch('sys.stdout', out):
exitcode = form_signature.main([
'/path/to/swift-form-signature',
'/v1/a/c/o', '', '12', '34',
'-922337203685477580799999999999999', key])
self.assertNotEqual(exitcode, 0)
if __name__ == '__main__':
unittest.main()