def test_re_doesnt_update_balance_for_positive_amounts(self):
     alice = self.make_participant('alice', last_bill_result='')
     record_exchange(self.db,
                     ExchangeRoute.from_network(alice, 'braintree-cc'),
                     amount=D("0.59"),
                     fee=D("0.41"),
                     participant=alice,
                     status='pre')
     assert P('alice').balance == D('0.00')
 def test_record_exchange_updates_balance_for_negative_amounts(self):
     alice = self.make_participant('alice', balance=50)
     record_exchange(self.db,
                     'ach',
                     amount=D('-35.84'),
                     fee=D('0.75'),
                     participant=alice,
                     status='pre')
     alice = Participant.from_username('alice')
     assert alice.balance == D('13.41')
 def test_re_updates_balance_for_negative_amounts(self):
     alice = self.make_participant('alice', balance=50, last_paypal_result='')
     record_exchange( self.db
                    , ExchangeRoute.from_network(alice, 'paypal')
                    , amount=D('-35.84')
                    , fee=D('0.75')
                    , participant=alice
                    , status='pre'
                     )
     assert P('alice').balance == D('13.41')
 def test_re_doesnt_update_balance_for_positive_amounts(self):
     alice = self.make_participant('alice', last_bill_result='')
     record_exchange( self.db
                    , ExchangeRoute.from_network(alice, 'braintree-cc')
                    , amount=D("0.59")
                    , fee=D("0.41")
                    , participant=alice
                    , status='pre'
                     )
     assert P('alice').balance == D('0.00')
 def test_re_updates_balance_for_negative_amounts(self):
     alice = self.make_participant('alice', balance=50, last_paypal_result='')
     record_exchange( self.db
                    , ExchangeRoute.from_network(alice, 'paypal')
                    , amount=D('-35.84')
                    , fee=D('0.75')
                    , participant=alice
                    , status='pre'
                     )
     assert P('alice').balance == D('13.41')
 def test_re_requires_valid_route(self):
     alice = self.make_participant('alice', last_bill_result='')
     bob = self.make_participant('bob', last_bill_result='')
     with self.assertRaises(AssertionError):
         record_exchange(self.db,
                         ExchangeRoute.from_network(bob, 'braintree-cc'),
                         amount=D("0.59"),
                         fee=D("0.41"),
                         participant=alice,
                         status='pre')
 def test_record_exchange_doesnt_update_balance_for_positive_amounts(self):
     alice = self.make_participant('alice')
     record_exchange(self.db,
                     'bill',
                     amount=D("0.59"),
                     fee=D("0.41"),
                     participant=alice,
                     status='pre')
     alice = Participant.from_username('alice')
     assert alice.balance == D('0.00')
 def test_re_stores_error_in_note(self):
     alice = self.make_participant('alice', last_bill_result='')
     record_exchange(self.db,
                     ExchangeRoute.from_network(alice, 'braintree-cc'),
                     amount=D("0.59"),
                     fee=D("0.41"),
                     participant=alice,
                     status='pre',
                     error='Card payment failed')
     exchange = self.db.one("SELECT * FROM exchanges")
     assert exchange.note == 'Card payment failed'
 def test_re_requires_valid_route(self):
     alice = self.make_participant('alice', last_bill_result='')
     bob = self.make_participant('bob', last_bill_result='')
     with self.assertRaises(AssertionError):
         record_exchange( self.db
                        , ExchangeRoute.from_network(bob, 'braintree-cc')
                        , amount=D("0.59")
                        , fee=D("0.41")
                        , participant=alice
                        , status='pre'
                         )
 def test_record_exchange_updates_balance_for_negative_amounts(self):
     alice = self.make_participant('alice', balance=50)
     record_exchange( self.db
                    , 'ach'
                    , amount=D('-35.84')
                    , fee=D('0.75')
                    , participant=alice
                    , status='pre'
                     )
     alice = Participant.from_username('alice')
     assert alice.balance == D('13.41')
 def test_record_exchange_doesnt_update_balance_for_positive_amounts(self):
     alice = self.make_participant('alice')
     record_exchange( self.db
                    , 'bill'
                    , amount=D("0.59")
                    , fee=D("0.41")
                    , participant=alice
                    , status='pre'
                     )
     alice = Participant.from_username('alice')
     assert alice.balance == D('0.00')
 def test_re_stores_error_in_note(self):
     alice = self.make_participant('alice', last_bill_result='')
     record_exchange( self.db
                    , ExchangeRoute.from_network(alice, 'braintree-cc')
                    , amount=D("0.59")
                    , fee=D("0.41")
                    , participant=alice
                    , status='pre'
                    , error='Card payment failed'
                     )
     exchange = self.db.one("SELECT * FROM exchanges")
     assert exchange.note == 'Card payment failed'
 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_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_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_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_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')
示例#20
0
 def test_credit_callback(self, rer):
     alice = self.make_participant('alice', last_ach_result='')
     ba = ExchangeRoute.from_network(alice, 'balanced-ba')
     for status in ('succeeded', 'failed'):
         error = 'FOO' if status == 'failed' else None
         e_id = record_exchange(self.db, ba, 10, 0, alice, 'pre')
         body = json.dumps({
             "events": [{
                 "type": "credit." + status,
                 "entity": {
                     "credits": [{
                         "failure_reason": error,
                         "meta": {
                             "participant_id": alice.id,
                             "exchange_id": e_id,
                         },
                         "status": status,
                     }]
                 }
             }]
         })
         r = self.callback(body=body, csrf_token=False)
         assert r.code == 200, r.body
         assert rer.call_count == 1
         assert rer.call_args[0][:-1] == (self.db, e_id, status, error)
         assert rer.call_args[0][-1].id == alice.id
         assert rer.call_args[1] == {}
         rer.reset_mock()
 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_credit_callback(self, rer):
     alice = self.make_participant('alice')
     ExchangeRoute.insert(alice, 'balanced-ba', '/bank/foo', '')
     ba = ExchangeRoute.from_network(alice, 'balanced-ba')
     for status in ('succeeded', 'failed'):
         error = 'FOO' if status == 'failed' else None
         e_id = record_exchange(self.db, ba, 10, 0, alice, 'pre')
         body = json.dumps({
             "events": [
                 {
                     "type": "credit."+status,
                     "entity": {
                         "credits": [
                             {
                                 "failure_reason": error,
                                 "meta": {
                                     "participant_id": alice.id,
                                     "exchange_id": e_id,
                                 },
                                 "status": status,
                             }
                         ]
                     }
                 }
             ]
         })
         r = self.callback(body=body, csrf_token=False)
         assert r.code == 200, r.body
         assert rer.call_count == 1
         assert rer.call_args[0][:-1] == (self.db, e_id, status, error)
         assert rer.call_args[0][-1].id == alice.id
         assert rer.call_args[1] == {}
         rer.reset_mock()
 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_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')
 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_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_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')
 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_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'
示例#32
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
示例#33
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
示例#34
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 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'
示例#36
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
 def test_re_records_exchange(self):
     alice = self.make_participant('alice', last_bill_result='')
     record_exchange( self.db
                    , ExchangeRoute.from_network(alice, 'braintree-cc')
                    , amount=D("0.59")
                    , fee=D("0.41")
                    , participant=alice
                    , status='pre'
                     )
     actual = self.db.one("""
         SELECT amount, fee, participant, status, route
           FROM exchanges
     """, back_as=dict)
     expected = { "amount": D('0.59')
                , "fee": D('0.41')
                , "participant": "alice"
                , "status": 'pre'
                , "route": ExchangeRoute.from_network(alice, 'braintree-cc').id
                 }
     assert actual == expected
 def test_re_records_exchange(self):
     alice = self.make_participant('alice', last_bill_result='')
     record_exchange( self.db
                    , ExchangeRoute.from_network(alice, 'braintree-cc')
                    , amount=D("0.59")
                    , fee=D("0.41")
                    , participant=alice
                    , status='pre'
                     )
     actual = self.db.one("""
         SELECT amount, fee, participant, status, route
           FROM exchanges
     """, back_as=dict)
     expected = { "amount": D('0.59')
                , "fee": D('0.41')
                , "participant": "alice"
                , "status": 'pre'
                , "route": ExchangeRoute.from_network(alice, 'braintree-cc').id
                 }
     assert actual == expected
示例#39
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'
示例#40
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
示例#41
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
示例#42
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 test_re_fails_if_negative_balance(self):
     alice = self.make_participant('alice', last_paypal_result='')
     ba = ExchangeRoute.from_network(alice, 'paypal')
     with pytest.raises(NegativeBalance):
         record_exchange(self.db, ba, D("-10.00"), D("0.41"), alice, 'pre')
 def test_re_fails_if_negative_balance(self):
     alice = self.make_participant('alice', last_paypal_result='')
     ba = ExchangeRoute.from_network(alice, 'paypal')
     with pytest.raises(NegativeBalance):
         record_exchange(self.db, ba, D("-10.00"), D("0.41"), alice, 'pre')
 def test_record_exchange_updates_balance_for_negative_amounts(self):
     alice = self.make_participant("alice", balance=50)
     record_exchange(self.db, "ach", amount=D("-35.84"), fee=D("0.75"), participant=alice, status="pre")
     alice = Participant.from_username("alice")
     assert alice.balance == D("13.41")
 def test_record_exchange_doesnt_update_balance_for_positive_amounts(self):
     alice = self.make_participant("alice")
     record_exchange(self.db, "bill", amount=D("0.59"), fee=D("0.41"), participant=alice, status="pre")
     alice = Participant.from_username("alice")
     assert alice.balance == D("0.00")