internal_client: Require that request_tries be positive

This way the error is obvious and at initialization time, rather than being
an UnboundLocalError that waits until you actually make requests.

Change-Id: I4c8dafe34fcfea354b254b9137f31184cbd6a762
This commit is contained in:
Tim Burke 2018-10-05 17:51:00 +00:00
parent 1ce22e81a1
commit 3770f3f228
2 changed files with 11 additions and 6 deletions

View File

@ -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

View File

@ -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)