<s> from __future__ import absolute_import , division , print_function , unicode_literals <EOL> from mock import patch <EOL> from mangopaysdk . entities . payout import PayOut <EOL> from liberapay . billing . exchanges import record_exchange <EOL> from liberapay . testing . emails import EmailHarness <EOL> from liberapay . testing . mangopay import MangopayHarness <EOL> class TestMangopayCallbacks ( EmailHarness , MangopayHarness ) : <EOL> def callback ( self , qs , ** kw ) : <EOL> kw . setdefault ( '<STR_LIT>' , False ) <EOL> return self . client . GET ( '<STR_LIT>' + qs , ** kw ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_payout_callback ( self , Get ) : <EOL> homer , ba = self . homer , self . homer_route <EOL> for status in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> status_up = status . upper ( ) <EOL> error = '<STR_LIT>' if status == '<STR_LIT>' else None <EOL> self . make_exchange ( '<STR_LIT>' , <NUM_LIT:10> , <NUM_LIT:0> , homer ) <EOL> e_id = record_exchange ( self . db , ba , - <NUM_LIT:10> , <NUM_LIT:0> , <NUM_LIT:0> , homer , '<STR_LIT>' ) <EOL> assert homer . balance == <NUM_LIT:0> <EOL> homer . close ( None ) <EOL> assert homer . status == '<STR_LIT>' <EOL> qs = "<STR_LIT>" + status_up + "<STR_LIT>" <EOL> payout = PayOut ( ) <EOL> payout . Status = status_up <EOL> payout . ResultCode = '<STR_LIT>' if error else '<STR_LIT>' <EOL> payout . ResultMessage = error <EOL> payout . AuthorId = homer . mangopay_user_id <EOL> payout . Tag = str ( e_id ) <EOL> Get . return_value = payout <EOL> r = self . callback ( qs , csrf_token = False ) <EOL> assert b'<STR_LIT>' not in r . headers . cookie <EOL> assert r . code == <NUM_LIT:200> , r . text <EOL> homer = homer . refetch ( ) <EOL> if status == '<STR_LIT>' : <EOL> assert homer . balance == <NUM_LIT:0> <EOL> assert homer . status == '<STR_LIT>' <EOL> else : <EOL> assert homer . balance == <NUM_LIT:10> <EOL> assert homer . status == '<STR_LIT>' <EOL> emails = self . get_emails ( ) <EOL> assert len ( emails ) == <NUM_LIT:1> <EOL> assert emails [ <NUM_LIT:0> ] [ '<STR_LIT:to>' ] [ <NUM_LIT:0> ] == '<STR_LIT>' % homer . email <EOL> assert '<STR_LIT>' in emails [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> homer . update_status ( '<STR_LIT>' ) </s>
