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

Commit

Permalink
add test for _send_request
Browse files Browse the repository at this point in the history
  • Loading branch information
zupo committed Apr 5, 2012
1 parent 7c67438 commit 8fbe83b
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/spinrewriter/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ def test_protected_terms_transformation(self, _send_request):
@mock.patch('spinrewriter.Api._send_request')
def test_protected_terms_empty(self, _send_request):
"""Test that correct default value is set for protected_terms if the
list is empty."""
list is empty.
"""
# prepare arguments for calling _transform_plain_text
args = dict(
action=Api.ACTION.unique_variation,
Expand Down Expand Up @@ -200,3 +201,21 @@ def test_protected_terms_empty(self, _send_request):
('nested_spintax', False),
('spintax_format', '{|}'),
))

@mock.patch('spinrewriter.urllib2')
@mock.patch('spinrewriter.urllib')
def test_send_request(self, urllib, urllib2):
"""Test that _send_requests correctly parses JSON response into a dict
and that request parameters get encoded beforehand.
"""
# mock response from connection
urllib2.urlopen.return_value.read.return_value = '{"foo":"bar"}'

# call it
result = self.api._send_request({'foo': 'bar'})

# test response
self.assertEquals(result['foo'], 'bar')

# were parameters encoded?
urllib.urlencode.assert_called_with({'foo': 'bar'})

0 comments on commit 8fbe83b

Please sign in to comment.