Skip to content
This repository has been archived by the owner on Jan 18, 2025. It is now read-only.

Commit

Permalink
Adding Python 3.5 capability
Browse files Browse the repository at this point in the history
In Python 3.5, `http.HTTPStatus` was added, previously HTTP statuses were int.
Casting `http.HTTPStatus` as int to maintain backwards maintainability.
  • Loading branch information
pferate committed Jun 28, 2016
1 parent 5454867 commit b1fa8f4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
language: python
python: 2.7
sudo: false
# A hack to install 3.5, until Travis-CI includes it
matrix:
include:
- python: 3.5
env:
- TOX_ENV=py35
env:
matrix:
- TOX_ENV=py26
Expand Down
14 changes: 7 additions & 7 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1279,18 +1279,18 @@ def _do_refresh_request_test_helper(self, response, content,

def test__do_refresh_request_non_json_failure(self):
response = httplib2.Response({
'status': http_client.BAD_REQUEST,
'status': int(http_client.BAD_REQUEST),
})
content = u'Bad request'
error_msg = 'Invalid response %s.' % (response.status,)
error_msg = 'Invalid response %s.' % (int(response.status),)
self._do_refresh_request_test_helper(response, content, error_msg)

def test__do_refresh_request_basic_failure(self):
response = httplib2.Response({
'status': http_client.INTERNAL_SERVER_ERROR,
'status': int(http_client.INTERNAL_SERVER_ERROR),
})
content = u'{}'
error_msg = 'Invalid response %s.' % (response.status,)
error_msg = 'Invalid response %s.' % (int(response.status),)
self._do_refresh_request_test_helper(response, content, error_msg)

def test__do_refresh_request_failure_w_json_error(self):
Expand Down Expand Up @@ -1828,21 +1828,21 @@ def _step1_get_device_and_user_codes_fail_helper(self, status,
self.assertEqual(exc_manager.exception.args, (error_msg,))

def test_step1_get_device_and_user_codes_non_json_failure(self):
status = http_client.BAD_REQUEST
status = int(http_client.BAD_REQUEST)
content = 'Nope not JSON.'
error_msg = 'Invalid response %s.' % (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 = http_client.INTERNAL_SERVER_ERROR
status = int(http_client.INTERNAL_SERVER_ERROR)
content = b'{}'
error_msg = 'Invalid response %s.' % (status,)
self._step1_get_device_and_user_codes_fail_helper(status, content,
error_msg)

def test_step1_get_device_and_user_codes_failure_w_json_error(self):
status = http_client.BAD_GATEWAY
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)
Expand Down
16 changes: 8 additions & 8 deletions tests/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,13 @@ def test_token_refresh_store_expires_soon(self):
access_token = '1/3w'
token_response = {'access_token': access_token, 'expires_in': 3600}
http = HttpMockSequence([
({'status': str(http_client.UNAUTHORIZED)},
({'status': str(int(http_client.UNAUTHORIZED))},
b'Initial token expired'),
({'status': str(http_client.UNAUTHORIZED)},
({'status': str(int(http_client.UNAUTHORIZED))},
b'Store token expired'),
({'status': str(http_client.OK)},
({'status': str(int(http_client.OK))},
json.dumps(token_response).encode('utf-8')),
({'status': str(http_client.OK)},
({'status': str(int(http_client.OK))},
b'Valid response to original request')
])

Expand Down Expand Up @@ -196,13 +196,13 @@ def test_token_refresh_stream_body(self):
token_response = {'access_token': valid_access_token,
'expires_in': 3600}
http = HttpMockSequence([
({'status': str(http_client.UNAUTHORIZED)},
({'status': str(int(http_client.UNAUTHORIZED))},
b'Initial token expired'),
({'status': str(http_client.UNAUTHORIZED)},
({'status': str(int(http_client.UNAUTHORIZED))},
b'Store token expired'),
({'status': str(http_client.OK)},
({'status': str(int(http_client.OK))},
json.dumps(token_response).encode('utf-8')),
({'status': str(http_client.OK)}, 'echo_request_body')
({'status': str(int(http_client.OK))}, 'echo_request_body')
])

body = six.StringIO('streaming body')
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py26,py27,py33,py34,pypy,gae,cover
envlist = py26,py27,py33,py34,py35,pypy,gae,cover

[testenv]
basedeps = mock>=1.3.0
Expand Down

0 comments on commit b1fa8f4

Please sign in to comment.