Created
May 20, 2014 21:06
-
-
Save evansde77/ce4023da802c35653335 to your computer and use it in GitHub Desktop.
Mocking example
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
import unittest | |
import mock | |
from wilson.views.bluemix import BluemixSingleUser | |
class TestBluemixUser(unittest.TestCase): | |
def test_get_user(self): | |
with mock.patch('wilson.views.bluemix.build_dao') as mock_build_dao: | |
with mock.patch('wilson.views.bluemix.jsonify') as mock_jsonify: | |
mock_dao = mock.Mock() | |
mock_dao.exists = mock.Mock() | |
mock_dao.exists.return_value = True | |
mock_dao.read = mock.Mock() | |
mock_build_dao.return_value = mock_dao | |
mock_dao.to_json = mock.Mock() | |
mock_dao.to_json.return_value = {'username': 'batman'} | |
mock_jsonify.return_value = "ResponseGoesHere" | |
bmsu = BluemixSingleUser() | |
result = bmsu.get(username='ringo') | |
self.failUnless(mock_build_dao.called) | |
self.failUnless(mock_dao.exists.called) | |
self.failUnless(mock_dao.read.called) | |
self.failUnless(mock_dao.to_json.called) | |
self.assertEqual(result, "ResponseGoesHere") | |
if __name__ == '__main__': | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment