def test_record_exchange_result_doesnt_restore_balance_on_success(self):
     alice = self.make_participant("alice", balance=50)
     e_id = record_exchange(self.db, "ach", D("-43.98"), D("1.60"), alice, "pre")
     assert alice.balance == D("4.42")
     record_exchange_result(self.db, e_id, "succeeded", None, alice)
     alice = Participant.from_username("alice")
     assert alice.balance == D("4.42")
 def test_record_exchange_result_restores_balance_on_error(self):
     alice = self.make_participant("alice", balance=30)
     e_id = record_exchange(self.db, "ach", D("-27.06"), D("0.81"), alice, "pre")
     assert alice.balance == D("02.13")
     record_exchange_result(self.db, e_id, "failed", "SOME ERROR", alice)
     alice = Participant.from_username("alice")
     assert alice.balance == D("30.00")
 def test_re_result_restores_balance_on_error(self):
     alice = self.make_participant('alice', balance=30, last_paypal_result='')
     ba = ExchangeRoute.from_network(alice, 'paypal')
     e_id = record_exchange(self.db, ba, D('-27.06'), D('0.81'), alice, 'pre')
     assert alice.balance == D('02.13')
     record_exchange_result(self.db, e_id, 'failed', 'SOME ERROR', alice)
     assert P('alice').balance == D('30.00')
 def test_record_exchange_result_doesnt_restore_balance_on_success(self):
     alice = self.make_participant('alice', balance=50)
     e_id = record_exchange(self.db, 'ach', D('-43.98'), D('1.60'), alice, 'pre')
     assert alice.balance == D('4.42')
     record_exchange_result( self.db, e_id, 'succeeded', None, alice)
     alice = Participant.from_username('alice')
     assert alice.balance == D('4.42')
 def test_record_exchange_result_updates_balance_for_positive_amounts(self):
     alice = self.make_participant('alice', balance=4)
     e_id = record_exchange(self.db, 'bill', D('31.59'), D('0.01'), alice, 'pre')
     assert alice.balance == D('4.00')
     record_exchange_result( self.db, e_id, 'succeeded', None, alice)
     alice = Participant.from_username('alice')
     assert alice.balance == D('35.59')
 def test_re_result_updates_balance_for_positive_amounts(self):
     alice = self.make_participant('alice', balance=4, last_bill_result='')
     cc = ExchangeRoute.from_network(alice, 'braintree-cc')
     e_id = record_exchange(self.db, cc, D('31.59'), D('0.01'), alice, 'pre')
     assert alice.balance == D('4.00')
     record_exchange_result(self.db, e_id, 'succeeded', None, alice)
     assert P('alice').balance == D('35.59')
 def test_record_exchange_result_restores_balance_on_error(self):
     alice = self.make_participant('alice', balance=30)
     e_id = record_exchange(self.db, 'ach', D('-27.06'), D('0.81'), alice, 'pre')
     assert alice.balance == D('02.13')
     record_exchange_result( self.db, e_id, 'failed', 'SOME ERROR', alice)
     alice = Participant.from_username('alice')
     assert alice.balance == D('30.00')
 def test_record_exchange_result_updates_balance_for_positive_amounts(self):
     alice = self.make_participant("alice", balance=4)
     e_id = record_exchange(self.db, "bill", D("31.59"), D("0.01"), alice, "pre")
     assert alice.balance == D("4.00")
     record_exchange_result(self.db, e_id, "succeeded", None, alice)
     alice = Participant.from_username("alice")
     assert alice.balance == D("35.59")
 def test_re_result_doesnt_restore_balance_on_success(self):
     alice = self.make_participant('alice', balance=50, last_paypal_result='')
     ba = ExchangeRoute.from_network(alice, 'paypal')
     e_id = record_exchange(self.db, ba, D('-43.98'), D('1.60'), alice, 'pre')
     assert alice.balance == D('4.42')
     record_exchange_result(self.db, e_id, 'succeeded', None, alice)
     assert P('alice').balance == D('4.42')
Exemple #10
0
 def make_exchange(self,
                   kind,
                   amount,
                   fee,
                   participant,
                   status='succeeded',
                   error=''):
     e_id = record_exchange(self.db, kind, amount, fee, participant, 'pre')
     record_exchange_result(self.db, e_id, status, error, participant)
     return e_id
 def make_exchange(self, route, amount, fee, participant, status='succeeded', error=''):
     if not isinstance(route, ExchangeRoute):
         network = route
         route = ExchangeRoute.from_network(participant, network)
         if not route:
             route = ExchangeRoute.insert(participant, network, 'dummy-address')
             assert route
     e_id = record_exchange(self.db, route, amount, fee, participant, 'pre')
     record_exchange_result(self.db, e_id, status, error, participant)
     return e_id
 def test_record_exchange_result_restores_balance_on_error_with_invalidated_route(self):
     alice = self.make_participant('alice', balance=37, last_ach_result='')
     ba = ExchangeRoute.from_network(alice, 'balanced-ba')
     e_id = record_exchange(self.db, ba, D('-32.45'), D('0.86'), alice, 'pre')
     assert alice.balance == D('3.69')
     ba.update_error('invalidated')
     record_exchange_result(self.db, e_id, 'failed', 'oops', alice)
     alice = Participant.from_username('alice')
     assert alice.balance == D('37.00')
     assert ba.error == alice.get_bank_account_error() == 'invalidated'
Exemple #13
0
 def make_exchange(self, route, amount, fee, participant, status='succeeded', error=''):
     if not isinstance(route, ExchangeRoute):
         network = route
         route = ExchangeRoute.from_network(participant, network)
         if not route:
             route = ExchangeRoute.insert(participant, network, 'dummy-address')
             assert route
     e_id = record_exchange(self.db, route, amount, fee, participant, 'pre')
     record_exchange_result(self.db, e_id, status, error, participant)
     return e_id
 def test_re_result_restores_balance_on_error_with_invalidated_route(self):
     alice = self.make_participant('alice', balance=37, last_paypal_result='')
     pp = ExchangeRoute.from_network(alice, 'paypal')
     e_id = record_exchange(self.db, pp, D('-32.45'), D('0.86'), alice, 'pre')
     assert alice.balance == D('3.69')
     pp.update_error('invalidated')
     record_exchange_result(self.db, e_id, 'failed', 'oops', alice)
     alice = P('alice')
     assert alice.balance == D('37.00')
     assert pp.error == alice.get_paypal_error() == 'invalidated'
 def test_re_result_restores_balance_on_error_with_invalidated_route(self):
     alice = self.make_participant('alice', balance=37, last_paypal_result='')
     pp = ExchangeRoute.from_network(alice, 'paypal')
     e_id = record_exchange(self.db, pp, D('-32.45'), D('0.86'), alice, 'pre')
     assert alice.balance == D('3.69')
     pp.update_error('invalidated')
     record_exchange_result(self.db, e_id, 'failed', 'oops', alice)
     alice = P('alice')
     assert alice.balance == D('37.00')
     assert pp.error == alice.get_paypal_error() == 'invalidated'
 def test_re_result_restores_balance_on_error(self):
     alice = self.make_participant('alice',
                                   balance=30,
                                   last_paypal_result='')
     ba = ExchangeRoute.from_network(alice, 'paypal')
     e_id = record_exchange(self.db, ba, D('-27.06'), D('0.81'), alice,
                            'pre')
     assert alice.balance == D('02.13')
     record_exchange_result(self.db, e_id, 'failed', 'SOME ERROR', alice)
     assert P('alice').balance == D('30.00')
 def test_re_result_doesnt_restore_balance_on_success(self):
     alice = self.make_participant('alice',
                                   balance=50,
                                   last_paypal_result='')
     ba = ExchangeRoute.from_network(alice, 'paypal')
     e_id = record_exchange(self.db, ba, D('-43.98'), D('1.60'), alice,
                            'pre')
     assert alice.balance == D('4.42')
     record_exchange_result(self.db, e_id, 'succeeded', None, alice)
     assert P('alice').balance == D('4.42')
Exemple #18
0
 def make_exchange(self, route, amount, fee, participant, status='succeeded', error=''):
     if not isinstance(route, ExchangeRoute):
         network = route
         route = ExchangeRoute.from_network(participant, network)
         if not route:
             from .balanced import BalancedHarness
             route = ExchangeRoute.insert(participant, network, BalancedHarness.card_href)
             assert route
     e_id = record_exchange(self.db, route, amount, fee, participant, 'pre')
     record_exchange_result(self.db, e_id, status, error, participant)
     return e_id
Exemple #19
0
 def test_record_exchange_result_restores_balance_on_error_with_invalidated_route(
         self):
     alice = self.make_participant('alice', balance=37, last_ach_result='')
     ba = ExchangeRoute.from_network(alice, 'balanced-ba')
     e_id = record_exchange(self.db, ba, D('-32.45'), D('0.86'), alice,
                            'pre')
     assert alice.balance == D('3.69')
     ba.update_error('invalidated')
     record_exchange_result(self.db, e_id, 'failed', 'oops', alice)
     alice = Participant.from_username('alice')
     assert alice.balance == D('37.00')
     assert ba.error == alice.get_bank_account_error() == 'invalidated'
Exemple #20
0
 def make_exchange(self, route, amount, fee, participant, status='succeeded', error='',
                                                ref='dummy-trans-id', address='dummy-address'):
     """Factory for exchanges.
     """
     if not isinstance(route, ExchangeRoute):
         network = route
         route = ExchangeRoute.from_network(participant, network)
         if not route:
             route = ExchangeRoute.insert(participant, network, address)
             assert route
     e_id = record_exchange(self.db, route, amount, fee, participant, 'pre', ref)
     record_exchange_result(self.db, e_id, status, error, participant)
     return e_id
Exemple #21
0
 def make_exchange(self, route, amount, fee, participant, status='succeeded', error='',
                                                ref='dummy-trans-id', address='dummy-address'):
     """Factory for exchanges.
     """
     if not isinstance(route, ExchangeRoute):
         network = route
         route = ExchangeRoute.from_network(participant, network)
         if not route:
             route = ExchangeRoute.insert(participant, network, address)
             assert route
     e_id = record_exchange(self.db, route, amount, fee, participant, 'pre', ref)
     record_exchange_result(self.db, e_id, status, error, participant)
     return e_id
Exemple #22
0
 def make_exchange(self, kind, amount, fee, participant, status='succeeded', error=''):
     e_id = record_exchange(self.db, kind, amount, fee, participant, 'pre')
     record_exchange_result(self.db, e_id, status, error, participant)
     return e_id