Created
April 11, 2011 08:51
-
-
Save Enome/913242 to your computer and use it in GitHub Desktop.
Class with dependencies
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
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() |
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 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