diff --git a/swift/common/internal_client.py b/swift/common/internal_client.py index 3d777b073f..303a1a91cf 100644 --- a/swift/common/internal_client.py +++ b/swift/common/internal_client.py @@ -145,6 +145,8 @@ class InternalClient(object): def __init__(self, conf_path, user_agent, request_tries, allow_modify_pipeline=False): + if request_tries < 1: + raise ValueError('request_tries must be positive') self.app = loadapp(conf_path, allow_modify_pipeline=allow_modify_pipeline) self.user_agent = user_agent diff --git a/test/unit/common/test_internal_client.py b/test/unit/common/test_internal_client.py index a1ee399740..180fb92dfd 100644 --- a/test/unit/common/test_internal_client.py +++ b/test/unit/common/test_internal_client.py @@ -290,17 +290,20 @@ class TestInternalClient(unittest.TestCase): conf_path = 'some_path' app = App(self, conf_path) - old_loadapp = internal_client.loadapp - internal_client.loadapp = app.load user_agent = 'some_user_agent' - request_tries = 'some_request_tries' + request_tries = 123 - try: + with mock.patch.object(internal_client, 'loadapp', app.load), \ + self.assertRaises(ValueError): + # First try with a bad arg + client = internal_client.InternalClient( + conf_path, user_agent, request_tries=0) + self.assertEqual(0, app.load_called) + + with mock.patch.object(internal_client, 'loadapp', app.load): client = internal_client.InternalClient( conf_path, user_agent, request_tries) - finally: - internal_client.loadapp = old_loadapp self.assertEqual(1, app.load_called) self.assertEqual(app, client.app)