I have a class that actually connects to a service and does authentication and stuff, but all of this is well tested somewhere else in my code, I just want to mock in the following test:
Object with tedious __init__
class B(object):
def __init__(self, username, password):
con = connect_to_service() #
auth = con.authenticate(username, password)
def upload(self)
return "Uploaded"
class A(object):
def send():
b = B('user', 'pass')
b.upload()
tests.py
# Now, I want here to test A, and since it uses B, I need to mock it, but I can't get it to work.
def test_A():
# Here I need to mock B and B.upload, I tried this:
a = A()
b = Mock()
b.upload.return_value='Hi'
a.send()
But this test is failling because it reached auth() on B.init, which I want to be a Mock model.