aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPat Ferate <pferate+github@gmail.com>2016-07-18 12:14:11 -0700
committerPat Ferate <pferate+github@gmail.com>2016-07-19 06:45:42 -0700
commita7cddf20a668be0369f797d9093629fb3dc0c270 (patch)
treea1c9de3d66069569f8c3c7f3f246ff2da7a22103 /tests
parent00afef9eb0b9af44cd462b5c1928737239e49bc0 (diff)
downloadoauth2client-a7cddf20a668be0369f797d9093629fb3dc0c270.tar.gz
Update string formatters to new style
Changing `%` style string formatters to `.format()`. Leaving `logging` strings in old style for Python 2 compatibility. Resolves: Issue #541
Diffstat (limited to 'tests')
-rw-r--r--tests/contrib/test_devshell.py7
-rw-r--r--tests/test_client.py24
-rw-r--r--tests/test_tools.py3
3 files changed, 19 insertions, 15 deletions
diff --git a/tests/contrib/test_devshell.py b/tests/contrib/test_devshell.py
index 4e5ff72..e685134 100644
--- a/tests/contrib/test_devshell.py
+++ b/tests/contrib/test_devshell.py
@@ -109,7 +109,8 @@ class Test_SendRecv(unittest2.TestCase):
sock.recv(6).decode.assert_called_once_with()
data = CREDENTIAL_INFO_REQUEST_JSON
- msg = _to_bytes('%s\n%s' % (len(data), data), encoding='utf-8')
+ msg = _to_bytes('{0}\n{1}'.format(len(data), data),
+ encoding='utf-8')
expected_sock_calls = [
mock.call.recv(6), # From the set-up above
mock.call.connect(('localhost', non_zero_port)),
@@ -167,7 +168,7 @@ class _AuthReferenceServer(threading.Thread):
if resp_buffer != CREDENTIAL_INFO_REQUEST_JSON:
self.bad_request = True
l = len(self.response)
- s.sendall(('%d\n%s' % (l, self.response)).encode())
+ s.sendall('{0}\n{1}'.format(l, self.response).encode())
finally:
# Will fail if s is None, but these tests never encounter
# that scenario.
@@ -183,7 +184,7 @@ class DevshellCredentialsTests(unittest2.TestCase):
def test_bad_message_to_mock_server(self):
request_content = CREDENTIAL_INFO_REQUEST_JSON + 'extrastuff'
request_message = _to_bytes(
- '%d\n%s' % (len(request_content), request_content))
+ '{0}\n{1}'.format(len(request_content), request_content))
response_message = 'foobar'
with _AuthReferenceServer(response_message) as auth_server:
self.assertFalse(auth_server.bad_request)
diff --git a/tests/test_client.py b/tests/test_client.py
index d57dacf..338c46e 100644
--- a/tests/test_client.py
+++ b/tests/test_client.py
@@ -1279,7 +1279,7 @@ class BasicCredentialsTests(unittest2.TestCase):
'status': int(http_client.BAD_REQUEST),
})
content = u'Bad request'
- error_msg = 'Invalid response %s.' % (int(response.status),)
+ error_msg = 'Invalid response {0}.'.format(int(response.status))
self._do_refresh_request_test_helper(response, content, error_msg)
def test__do_refresh_request_basic_failure(self):
@@ -1287,7 +1287,7 @@ class BasicCredentialsTests(unittest2.TestCase):
'status': int(http_client.INTERNAL_SERVER_ERROR),
})
content = u'{}'
- error_msg = 'Invalid response %s.' % (int(response.status),)
+ error_msg = 'Invalid response {0}.'.format(int(response.status))
self._do_refresh_request_test_helper(response, content, error_msg)
def test__do_refresh_request_failure_w_json_error(self):
@@ -1318,7 +1318,7 @@ class BasicCredentialsTests(unittest2.TestCase):
'error': base_error,
'error_description': error_desc,
})
- error_msg = '%s: %s' % (base_error, error_desc)
+ error_msg = '{0}: {1}'.format(base_error, error_desc)
self._do_refresh_request_test_helper(response, content, error_msg)
@mock.patch('oauth2client.client.logger')
@@ -1371,7 +1371,7 @@ class BasicCredentialsTests(unittest2.TestCase):
'status': http_client.BAD_REQUEST,
})
content = u'Bad request'
- error_msg = 'Invalid response %s.' % (response.status,)
+ error_msg = 'Invalid response {0}.'.format(response.status)
self._do_revoke_test_helper(response, content, error_msg)
def test__do_revoke_basic_failure(self):
@@ -1379,7 +1379,7 @@ class BasicCredentialsTests(unittest2.TestCase):
'status': http_client.INTERNAL_SERVER_ERROR,
})
content = u'{}'
- error_msg = 'Invalid response %s.' % (response.status,)
+ error_msg = 'Invalid response {0}.'.format(response.status)
self._do_revoke_test_helper(response, content, error_msg)
def test__do_revoke_failure_w_json_error(self):
@@ -1455,7 +1455,7 @@ class BasicCredentialsTests(unittest2.TestCase):
'status': http_client.BAD_REQUEST,
})
content = u'Bad request'
- error_msg = 'Invalid response %s.' % (response.status,)
+ error_msg = 'Invalid response {0}.'.format(response.status)
self._do_retrieve_scopes_test_helper(response, content, error_msg)
def test__do_retrieve_scopes_basic_failure(self):
@@ -1463,7 +1463,7 @@ class BasicCredentialsTests(unittest2.TestCase):
'status': http_client.INTERNAL_SERVER_ERROR,
})
content = u'{}'
- error_msg = 'Invalid response %s.' % (response.status,)
+ error_msg = 'Invalid response {0}.'.format(response.status)
self._do_retrieve_scopes_test_helper(response, content, error_msg)
def test__do_retrieve_scopes_failure_w_json_error(self):
@@ -1824,14 +1824,14 @@ class OAuth2WebServerFlowTest(unittest2.TestCase):
def test_step1_get_device_and_user_codes_non_json_failure(self):
status = int(http_client.BAD_REQUEST)
content = 'Nope not JSON.'
- error_msg = 'Invalid response %s.' % (status,)
+ error_msg = 'Invalid response {0}.'.format(status)
self._step1_get_device_and_user_codes_fail_helper(status, content,
error_msg)
def test_step1_get_device_and_user_codes_basic_failure(self):
status = int(http_client.INTERNAL_SERVER_ERROR)
content = b'{}'
- error_msg = 'Invalid response %s.' % (status,)
+ error_msg = 'Invalid response {0}.'.format(status)
self._step1_get_device_and_user_codes_fail_helper(status, content,
error_msg)
@@ -1839,7 +1839,8 @@ class OAuth2WebServerFlowTest(unittest2.TestCase):
status = int(http_client.BAD_GATEWAY)
base_error = 'ZOMG user codes failure.'
content = json.dumps({'error': base_error})
- error_msg = 'Invalid response %s. Error: %s' % (status, base_error)
+ error_msg = 'Invalid response {0}. Error: {1}'.format(status,
+ base_error)
self._step1_get_device_and_user_codes_fail_helper(status, content,
error_msg)
@@ -2163,7 +2164,8 @@ class FlowFromCachedClientsecrets(unittest2.TestCase):
filename = object()
cache = object()
- err_msg = 'This OAuth 2.0 flow is unsupported: %r' % (client_type,)
+ err_msg = ('This OAuth 2.0 flow is unsupported: '
+ '{0!r}'.format(client_type))
with self.assertRaisesRegexp(client.UnknownClientSecretsFlowError,
err_msg):
flow_from_clientsecrets(filename, None, cache=cache)
diff --git a/tests/test_tools.py b/tests/test_tools.py
index 69c28ca..8a86324 100644
--- a/tests/test_tools.py
+++ b/tests/test_tools.py
@@ -40,7 +40,8 @@ class TestClientRedirectServer(unittest2.TestCase):
httpd = tools.ClientRedirectServer(('localhost', 0),
tools.ClientRedirectHandler)
code = 'foo'
- url = 'http://localhost:%i?code=%s' % (httpd.server_address[1], code)
+ url = 'http://localhost:{0}?code={1}'.format(
+ httpd.server_address[1], code)
t = threading.Thread(target=httpd.handle_request)
t.setDaemon(True)
t.start()