コード例 #1
0
 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')
コード例 #2
0
 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')
コード例 #3
0
 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')
コード例 #4
0
 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')
コード例 #5
0
 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')
コード例 #6
0
 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')
コード例 #7
0
 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')
コード例 #8
0
 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'
コード例 #9
0
 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'
                         )
コード例 #10
0
 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')
コード例 #11
0
 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')
コード例 #12
0
 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'
コード例 #13
0
 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')
コード例 #14
0
 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')
コード例 #15
0
 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')
コード例 #16
0
 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')
コード例 #17
0
 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')
コード例 #18
0
 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')
コード例 #19
0
 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()
コード例 #21
0
 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")
コード例 #22
0
 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()
コード例 #23
0
 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')
コード例 #24
0
 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')
コード例 #25
0
 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')
コード例 #26
0
 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")
コード例 #27
0
 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")
コード例 #28
0
 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')
コード例 #29
0
 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')
コード例 #30
0
 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'
コード例 #31
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'
コード例 #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
ファイル: __init__.py プロジェクト: HolaChica/gratipay.com
 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
コード例 #35
0
 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
コード例 #37
0
 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
コード例 #38
0
 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
ファイル: harness.py プロジェクト: cyberjacob/www.gittip.com
 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
ファイル: __init__.py プロジェクト: beerm/gratipay.com
 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
コード例 #43
0
 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')
コード例 #44
0
 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')
コード例 #45
0
 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")
コード例 #46
0
 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")