예제 #1
0
 def test_payout_suspended_user(self):
     self.make_exchange('mango-cc', 20, 0, self.homer)
     self.db.run(
         """
         UPDATE participants
            SET is_suspended = true
          WHERE id = %s
     """, (self.homer.id, ))
     self.homer.set_attributes(is_suspended=True)
     with self.assertRaises(AccountSuspended):
         payout(self.db, self.homer, D('10.00'))
 def test_sync_with_mangopay_reverts_credits_that_didnt_happen(self):
     self.make_exchange('mango-cc', 41, 0, self.homer)
     with mock.patch('liberapay.billing.exchanges.record_exchange_result') as rer \
        , mock.patch('liberapay.billing.exchanges.test_hook') as test_hook:
         rer.side_effect = test_hook.side_effect = Foobar
         with self.assertRaises(Foobar):
             payout(self.db, self.homer, D('35.00'))
     exchange = self.db.one("SELECT * FROM exchanges WHERE amount < 0")
     assert exchange.status == 'pre'
     sync_with_mangopay(self.db)
     exchanges = self.db.all("SELECT * FROM exchanges WHERE amount < 0")
     assert not exchanges
     assert Participant.from_username('homer').balance == 41
예제 #3
0
 def test_sync_with_mangopay_reverts_credits_that_didnt_happen(self):
     self.make_exchange('mango-cc', 41, 0, self.homer)
     with mock.patch('liberapay.billing.exchanges.record_exchange_result') as rer \
        , mock.patch('liberapay.billing.exchanges.test_hook') as test_hook:
         rer.side_effect = test_hook.side_effect = Foobar
         with self.assertRaises(Foobar):
             payout(self.db, self.homer, D('35.00'))
     exchange = self.db.one("SELECT * FROM exchanges WHERE amount < 0")
     assert exchange.status == 'pre'
     sync_with_mangopay(self.db)
     exchange = self.db.one("SELECT * FROM exchanges WHERE amount < 0")
     assert exchange.status == 'failed'
     homer = self.homer.refetch()
     assert homer.balance == homer.withdrawable_balance == 41
예제 #4
0
 def test_sync_with_mangopay_reverts_credits_that_didnt_happen(self):
     self.make_exchange('mango-cc', 41, 0, self.homer)
     with mock.patch('liberapay.billing.exchanges.record_exchange_result') as rer, \
          mock.patch('liberapay.billing.exchanges.test_hook') as test_hook:
         rer.side_effect = test_hook.side_effect = Foobar
         with self.assertRaises(Foobar):
             payout(self.db, self.homer, D('35.00'))
     exchange = self.db.one("SELECT * FROM exchanges WHERE amount < 0")
     assert exchange.status == 'pre'
     sync_with_mangopay(self.db)
     exchange = self.db.one("SELECT * FROM exchanges WHERE amount < 0")
     assert exchange.status == 'failed'
     homer = self.homer.refetch()
     assert homer.balance == homer.withdrawable_balance == 41
 def test_payout(self):
     self.make_exchange('mango-cc', 27, 0, self.homer)
     exchange = payout(self.db, self.homer, D('1.00'))
     assert exchange.note is None
     assert exchange.status == 'created'
     homer = Participant.from_id(self.homer.id)
     assert self.homer.balance == homer.balance == 26
예제 #6
0
 def test_payout_failure(self, test_hook):
     test_hook.side_effect = Foobar
     self.make_exchange('mango-cc', 20, 0, self.homer)
     exchange = payout(self.db, self.homer, D('1.00'))
     assert exchange.status == 'failed'
     homer = Participant.from_id(self.homer.id)
     assert homer.get_bank_account_error() == exchange.note == "Foobar()"
     assert self.homer.balance == homer.balance == 20
예제 #7
0
 def test_payout_failure(self, test_hook):
     test_hook.side_effect = Foobar
     self.make_exchange('mango-cc', 20, 0, self.homer)
     exchange = payout(self.db, self.homer, D('1.00'))
     assert exchange.status == 'failed'
     homer = Participant.from_id(self.homer.id)
     assert homer.get_bank_account_error() == exchange.note == "Foobar()"
     assert self.homer.balance == homer.balance == 20
 def test_payout(self):
     self.make_exchange('mango-cc', 27, 0, self.homer)
     self.make_exchange('mango-cc', 19, 0, self.homer)
     exchange = payout(self.db, self.homer, D('30.00'))
     assert exchange.note is None
     assert exchange.status == 'created'
     homer = Participant.from_id(self.homer.id)
     assert self.homer.balance == homer.balance == 16
     self.db.self_check()
예제 #9
0
 def test_payout(self):
     e = charge(self.db, self.janet, D('46.00'), 'http://localhost/')
     assert e.status == 'succeeded', e.note
     self.janet.set_tip_to(self.homer, '42.00')
     self.janet.close('downstream')
     self.homer = self.homer.refetch()
     assert self.homer.balance == 46
     exchange = payout(self.db, self.homer, D('30.00'))
     assert exchange.note is None
     assert exchange.status == 'created'
     homer = Participant.from_id(self.homer.id)
     assert self.homer.balance == homer.balance == 16
     self.db.self_check()
예제 #10
0
 def test_payout(self):
     e = charge(self.db, self.janet, D('46.00'), 'http://localhost/')
     assert e.status == 'succeeded', e.note
     self.janet.set_tip_to(self.homer, '42.00')
     self.janet.close('downstream')
     self.homer = self.homer.refetch()
     assert self.homer.balance == 46
     exchange = payout(self.db, self.homer, D('30.00'))
     assert exchange.note is None
     assert exchange.status == 'created'
     homer = Participant.from_id(self.homer.id)
     assert self.homer.balance == homer.balance == 16
     self.db.self_check()
예제 #11
0
 def test_payout_during_payday(self):
     self.make_exchange('mango-cc', 200, 0, self.homer)
     Payday.start()
     with self.assertRaises(PaydayIsRunning):
         payout(self.db, self.homer, D('97.35'))
예제 #12
0
 def test_payout_quarantine(self, gba):
     self.make_exchange('mango-cc', 39, 0, self.homer)
     gba.return_value = self.bank_account
     with mock.patch.multiple(exchanges, QUARANTINE='1 month'):
         with self.assertRaises(NotEnoughWithdrawableMoney):
             payout(self.db, self.homer, D('32.00'))
예제 #13
0
 def test_payout_invalidated_bank_account(self):
     self.make_exchange('mango-cc', 20, 0, self.homer)
     self.homer_route.invalidate()
     with self.assertRaises(AssertionError):
         payout(self.db, self.homer, D('10.00'))
예제 #14
0
 def test_payout_no_bank_account(self):
     self.make_exchange('mango-cc', 20, 0, self.david)
     with self.assertRaises(AssertionError):
         payout(self.db, self.david, D('1.00'))
예제 #15
0
 def test_payout_amount_under_minimum(self, gba):
     self.make_exchange('mango-cc', 8, 0, self.homer)
     gba.return_value = self.bank_account_outside_sepa
     with self.assertRaises(FeeExceedsAmount):
         payout(self.db, self.homer, D('0.10'))
예제 #16
0
 def test_payout_amount_under_minimum(self, gba):
     self.make_exchange('mango-cc', 8, 0, self.homer)
     gba.return_value = self.bank_account_outside_sepa
     with self.assertRaises(FeeExceedsAmount):
         payout(self.db, self.homer, D('0.10'))
예제 #17
0
 def test_payout_no_bank_account(self):
     self.make_exchange('mango-cc', 20, 0, self.david)
     with self.assertRaises(AssertionError):
         payout(self.db, self.david, D('1.00'))
예제 #18
0
 def test_payout_invalidated_bank_account(self):
     self.make_exchange('mango-cc', 20, 0, self.homer)
     self.homer_route.invalidate()
     with self.assertRaises(AssertionError):
         payout(self.db, self.homer, D('10.00'))
예제 #19
0
 def test_payout_during_payday(self):
     self.make_exchange('mango-cc', 200, 0, self.homer)
     Payday.start()
     with self.assertRaises(PaydayIsRunning):
         payout(self.db, self.homer, D('97.35'))
예제 #20
0
 def test_payout_quarantine(self, gba):
     self.make_exchange('mango-cc', 39, 0, self.homer)
     gba.return_value = self.bank_account
     with mock.patch.multiple(exchanges, QUARANTINE='1 month'):
         with self.assertRaises(NotEnoughWithdrawableMoney):
             payout(self.db, self.homer, D('32.00'))