Skip to content
Browse files

add test for _send_request

  • Loading branch information...
1 parent 7c67438 commit 8fbe83b391f0599acdc72a90898b2343e9d753dc @zupo zupo committed Apr 5, 2012
Showing with 20 additions and 1 deletion.
  1. +20 −1 src/spinrewriter/tests.py
View
21 src/spinrewriter/tests.py
@@ -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,
@@ -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.
Something went wrong with that request. Please try again.