Skip to content

Instantly share code, notes, and snippets.

@Enome
Created April 11, 2011 08:51
Show Gist options
  • Save Enome/913242 to your computer and use it in GitHub Desktop.
Save Enome/913242 to your computer and use it in GitHub Desktop.
Class with dependencies
from unittest import TestCase
from mock import patch
import external_module
class SomeHandler(object):
def authenticate_login(self):
external_module.authenticate()
external_module.login()
class TestSomeHandler(TestCase):
@patch('external_module.authenticate')
def test_authenticate_login_should_call_authenticate(self, authenticate_mock):
SomeHandler()
authenticate_mock.assert_called()
import external_module
class SomeHandler(object):
def __init__(self, _auth=None, _login=None):
self.authenticate = _auth or external_module.authenticate
self.login = _login or external_module.login
def authenticate_login(self):
self.authenticate()
self.login()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment