Skip to content

Update travis.yml to fail on Pep8 errors #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@ python:
- '2.7'
- '3.4'
- '3.5'
fail_fast: true
before_install:
- pip install pycodestyle
install:
- if [[ "$TRAVIS_PYTHON_VERSION" == 2.6* ]]; then travis_retry pip install unittest2; fi
- if [[ "$TRAVIS_PYTHON_VERSION" == 2.6* ]]; then travis_retry pip uninstall -y pbr; fi
- if [[ "$TRAVIS_PYTHON_VERSION" == "3.2" ]]; then travis_retry pip install coverage==3.7.1; fi
- if [[ "$TRAVIS_PYTHON_VERSION" != "3.2" ]]; then travis_retry pip install coverage; fi
- python setup.py install
script:
# Run pycodestyle
- pycodestyle
- if [[ $TRAVIS_PYTHON_VERSION == '2.6' ]]; then unit2 discover; else python -m unittest discover; fi
notifications:
hipchat:
Expand Down
34 changes: 22 additions & 12 deletions python_http_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,12 @@ def _build_url(self, query_params):
if query_params:
url_values = urlencode(sorted(query_params.items()), True)
url = '{0}?{1}'.format(url, url_values)
url = (self._build_versioned_url(url) if self._version
else self.host + url)

if self._version:
url = self._build_versioned_url(url)
else:
url = self.host + url

return url

def _update_headers(self, request_headers):
Expand Down Expand Up @@ -208,18 +212,24 @@ def http_request(*_, **kwargs):
if 'request_body' not in kwargs:
data = None
else:
# Don't serialize to a JSON formatted str if
# we don't have a JSON Content-Type
content_type = self.request_headers.get('Content-Type')
if content_type is not None:
if content_type != 'application/json':
data = kwargs['request_body']

# Don't serialize to a JSON formatted str
# if we don't have a JSON Content-Type
if 'Content-Type' in self.request_headers:
if self.request_headers['Content-Type'] != 'application\
/json':
data = kwargs['request_body'].encode('utf-8')
else:
data = json.dumps(kwargs['request_body'])
data = json.dumps(
kwargs['request_body']).encode('utf-8')
else:
data = json.dumps(kwargs['request_body'])
data = data.encode('utf-8')
params = kwargs.get('query_params')
data = json.dumps(
kwargs['request_body']).encode('utf-8')
if 'query_params' in kwargs:
params = kwargs['query_params']
else:
params = None

opener = urllib.build_opener()
request = urllib.Request(self._build_url(params), data=data)
if self.request_headers:
Expand Down
1 change: 1 addition & 0 deletions tests/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,6 @@ def static_version():
version=3)
run_tested_code(client, 10)


dynamic_result = dynamic_version()
static_result = static_version()
30 changes: 17 additions & 13 deletions tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ def __init__(self, host, response_code):
Client.__init__(self, host)

def _make_request(self, opener, request):
if 200 <= self.response_code < 299: # if successsful code

if 200 <= self.response_code < 299: # if successsful code
return MockResponse(self.response_code)
else:
raise handle_error(MockException(self.response_code))
Expand All @@ -76,8 +77,8 @@ def setUp(self):
self.client = Client(host=self.host)
self.api_key = 'SENDGRID_API_KEY'
self.request_headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + self.api_key
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + self.api_key
}
self.client = Client(host=self.host,
request_headers=self.request_headers,
Expand Down Expand Up @@ -115,11 +116,13 @@ def test__build_url(self):
self.client._url_path = self.client._url_path + ['there']
self.client._url_path = self.client._url_path + [1]
self.client._version = 3
url = '{0}/v{1}{2}'.format(
self.host,
str(self.client._version),
'/here/there/1?hello=0&world=1&ztest=0&ztest=1')
query_params = {'hello': 0, 'world': 1, 'ztest': [0,1]}

url = '{0}/v{1}{2}'.format(self.host,
str(self.client._version),
'/here/there/1?hello=0&' +
'world=1&ztest=0&ztest=1')
query_params = {'hello': 0, 'world': 1, 'ztest': [0, 1]}

built_url = self.client._build_url(query_params)
self.assertEqual(built_url, url)

Expand Down Expand Up @@ -174,19 +177,20 @@ def test__getattr__(self):
self.assertEqual(r.status_code, 204)

mock_client.response_code = 400
self.assertRaises(BadRequestsError,mock_client.get)
self.assertRaises(BadRequestsError, mock_client.get)

mock_client.response_code = 404
self.assertRaises(NotFoundError,mock_client.post)
self.assertRaises(NotFoundError, mock_client.post)

mock_client.response_code = 415
self.assertRaises(UnsupportedMediaTypeError,mock_client.patch)
self.assertRaises(UnsupportedMediaTypeError, mock_client.patch)

mock_client.response_code = 503
self.assertRaises(ServiceUnavailableError,mock_client.delete)
self.assertRaises(ServiceUnavailableError, mock_client.delete)

mock_client.response_code = 523
self.assertRaises(HTTPError,mock_client.delete)
self.assertRaises(HTTPError, mock_client.delete)


def test_client_pickle_unpickle(self):
pickled_client = pickle.dumps(self.client)
Expand Down