Skip to content

Commit

Permalink
Merge pull request #18 from NathanReb/python3-compat
Browse files Browse the repository at this point in the history
Make requests json encoding Python3 compatible
  • Loading branch information
zackkitzmiller committed Apr 5, 2016
2 parents 18dc647 + e8d0897 commit 15dca15
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
language: python
python:
- "2.7"
- "3.4"
install: "pip install -r requirements.txt"
before_script: "pip install nose-cov"
before_script: "pip install nose-cov mock"
script: nosetests --with-coverage --cover-package=sixpack
sudo: false
cache: pip
15 changes: 8 additions & 7 deletions sixpack/sixpack.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
import re
import requests
from uuid import uuid4
Expand Down Expand Up @@ -105,11 +104,13 @@ def get_response(self, endpoint=None, params=None):

try:
response = requests.get(url, params=params, timeout=self.timeout)
if response.status_code != 200:
ret = "{{\"status\": \"failed\", \"response\": {0}}}".format(response.content)
else:
ret = response.content
except Exception:
ret = "{\"status\": \"failed\", \"response\": \"http error: sixpack is unreachable\"}"
return {"status": "failed", "response": "http error: sixpack is unreachable"}

return json.loads(ret)
if response.status_code != 200:
return {"status": "failed", "response": response.content}

try:
return response.json()
except ValueError:
return {"status": "failed", "response": response.content}
5 changes: 3 additions & 2 deletions sixpack/test/test_sixpack_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,15 @@ def test_failure_on_bad_alt_names(self):
def new_convert(*args, **kwargs):
m = Mock()
m.status_code = 200
m.content = '{"status": "ok"}'
m.json.return_value = {"status": "ok"}

return m


def new_participate(*args, **kwargs):
m = Mock()
m.status_code = 200
m.content = '{"status": "ok"}'
m.json.return_value = {"status": "ok"}

return m

Expand Down

0 comments on commit 15dca15

Please sign in to comment.