<s> """<STR_LIT>""" <EOL> from django . test import TestCase <EOL> from models import Account <EOL> from roles . django import ModelRoleType <EOL> from roles . context import context <EOL> class MoneySource ( object ) : <EOL> __metaclass__ = ModelRoleType <EOL> def transfer ( self , amount ) : <EOL> if self . balance >= amount : <EOL> self . withdraw ( amount ) <EOL> context . sink . receive ( amount ) <EOL> class MoneySink ( object ) : <EOL> __metaclass__ = ModelRoleType <EOL> def receive ( self , amount ) : <EOL> self . deposit ( amount ) <EOL> class TransferMoney ( object ) : <EOL> def __init__ ( self , source , sink ) : <EOL> self . source = source <EOL> self . sink = sink <EOL> def transfer_money ( self , amount ) : <EOL> """<STR_LIT>""" <EOL> with context ( self ) , MoneySource . played_by ( self . source ) , MoneySink . played_by ( self . sink ) : <EOL> self . source . transfer ( amount ) <EOL> print "<STR_LIT>" , self . sink . balance <EOL> print "<STR_LIT>" , isinstance ( self . sink , Account ) <EOL> self . source . save ( ) <EOL> self . sink . save ( ) <EOL> class MoneyTransferTest ( TestCase ) : <EOL> def test_basic_addition ( self ) : <EOL> """<STR_LIT>""" <EOL> src = Account ( balance = <NUM_LIT:1000> ) <EOL> dst = Account ( balance = <NUM_LIT:0> ) <EOL> src . save ( ) <EOL> dst . save ( ) <EOL> accounts = Account . objects . all ( ) <EOL> assert len ( accounts ) == <NUM_LIT:2> <EOL> assert accounts [ <NUM_LIT:0> ] . balance == <NUM_LIT:1000> , accounts [ <NUM_LIT:0> ] . balance <EOL> assert accounts [ <NUM_LIT:1> ] . balance == <NUM_LIT:0> , accounts [ <NUM_LIT:1> ] . balance <EOL> ctx = TransferMoney ( src , dst ) <EOL> ctx . transfer_money ( amount = <NUM_LIT:100> ) <EOL> print src , src . balance <EOL> assert src . balance == <NUM_LIT> <EOL> print dst , dst . balance <EOL> assert dst . balance == <NUM_LIT:100> <EOL> accounts = Account . objects . all ( ) <EOL> assert accounts [ <NUM_LIT:0> ] . balance == <NUM_LIT> , accounts [ <NUM_LIT:0> ] . balance <EOL> assert accounts [ <NUM_LIT:1> ] . balance == <NUM_LIT:100> , accounts [ <NUM_LIT:1> ] . balance </s>
