This repository has been archived by the owner on Nov 25, 2017. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed JSON encoding of request bodies.
- Loading branch information
Showing
5 changed files
with
54 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
""" | ||
Tests for the parts of StorymarketClient not otherwise covered. | ||
""" | ||
|
||
import mock | ||
import storymarket | ||
import httplib2 | ||
from nose.tools import assert_raises | ||
|
||
client = storymarket.StorymarketClient('APIKEY') | ||
|
||
def test_json_encoding(): | ||
mock_resp = httplib2.Response({"status": 200}) | ||
mock_body = '{"hi": "there"}' | ||
mock_req = mock.Mock(return_value=(mock_resp, mock_body)) | ||
|
||
with mock.patch('httplib2.Http.request', mock_req): | ||
client.request('/url/', 'POST', body={"hello": ["world"]}) | ||
mock_req.assert_called_with( | ||
'%surl/' % client.BASE_URL, | ||
'POST', | ||
body = '{"hello": ["world"]}', | ||
headers = { | ||
'Authorization': client.apikey, | ||
'Content-Type': 'application/json', | ||
'User-Agent': client.USER_AGENT, | ||
}, | ||
) | ||
|
||
def test_error_response(): | ||
mock_resp = httplib2.Response({"status": 400}) | ||
mock_body = 'oops!' | ||
mock_req = mock.Mock(return_value=(mock_resp, mock_body)) | ||
|
||
with mock.patch('httplib2.Http.request', mock_req): | ||
assert_raises(storymarket.exceptions.StorymarketError, client.request, '/url/', 'GET') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters