Skip to content

Instantly share code, notes, and snippets.

@zain
Created January 30, 2012 19:34
Show Gist options
  • Save zain/1706189 to your computer and use it in GitHub Desktop.
Save zain/1706189 to your computer and use it in GitHub Desktop.
from mock import Mock, patch
import requests
class VSSecureMailWS:
def encrypt_and_send(self, url, data):
r = requests.post(url)
if r.status_code == 200:
return "{0} {1}".format(data, r.text)
else:
return "Error"
mock_response = Mock()
mock_response.status_code = 200
mock_response.text = "world"
with patch('requests.post') as mock_post:
mock_post.return_value = mock_response
v = VSSecureMailWS()
assert v.encrypt_and_send("http://foo.com/", "hello") == "hello world"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment