Beispiel #1
0
 def test_payout_callback(self, Get):
     homer, ba = self.homer, self.homer_route
     for status in ('succeeded', 'failed'):
         status_up = status.upper()
         error = 'FOO' if status == 'failed' else None
         self.make_exchange('mango-cc', 10, 0, homer)
         e_id = record_exchange(self.db, ba, EUR(-10), EUR(0), EUR(0),
                                homer, 'pre').id
         assert homer.balance == 0
         homer.close(None)
         assert homer.status == 'closed'
         qs = "EventType=PAYOUT_NORMAL_" + status_up + "&RessourceId=123456790"
         payout = BankWirePayOut(Id=-1)
         payout.Status = status_up
         payout.ResultCode = '000001' if error else '000000'
         payout.ResultMessage = error
         payout.AuthorId = homer.mangopay_user_id
         payout.Tag = str(e_id)
         Get.return_value = payout
         r = self.callback(qs)
         assert CSRF_TOKEN not in r.headers.cookie
         assert r.code == 200, r.text
         homer = homer.refetch()
         if status == 'succeeded':
             assert homer.balance == 0
             assert homer.status == 'closed'
         else:
             assert homer.balance == 10
             assert homer.status == 'active'
             emails = self.get_emails()
             assert len(emails) == 1
             assert emails[0]['to'][0] == 'homer <%s>' % homer.email
             assert 'fail' in emails[0]['subject']
         self.db.self_check()
         homer.update_status('active')  # reset for next loop run
 def test_payout_callback(self, Get):
     homer, ba = self.homer, self.homer_route
     for status in ('succeeded', 'failed'):
         status_up = status.upper()
         error = 'FOO' if status == 'failed' else None
         self.make_exchange('mango-cc', 10, 0, homer)
         e_id = record_exchange(self.db, ba, EUR(-10), EUR(0), EUR(0), homer, 'pre').id
         assert homer.balance == 0
         homer.close(None)
         assert homer.status == 'closed'
         qs = "EventType=PAYOUT_NORMAL_"+status_up+"&RessourceId=123456790"
         payout = BankWirePayOut(Id=-1)
         payout.Status = status_up
         payout.ResultCode = '000001' if error else '000000'
         payout.ResultMessage = error
         payout.AuthorId = homer.mangopay_user_id
         payout.Tag = str(e_id)
         Get.return_value = payout
         r = self.callback(qs)
         assert CSRF_TOKEN not in r.headers.cookie
         assert r.code == 200, r.text
         homer = homer.refetch()
         if status == 'succeeded':
             assert homer.balance == 0
             assert homer.status == 'closed'
         else:
             assert homer.balance == 10
             assert homer.status == 'active'
             emails = self.get_emails()
             assert len(emails) == 1
             assert emails[0]['to'][0] == 'homer <%s>' % homer.email
             assert 'fail' in emails[0]['subject']
         self.db.self_check()
         homer.update_status('active')  # reset for next loop run
Beispiel #3
0
 def test_payout_refund_callback(self, R_Get, PO_Get):
     homer, ba = self.homer, self.homer_route
     for status in ('failed', 'succeeded'):
         # Create the payout
         self.make_exchange('mango-cc', 10, 0, homer)
         e_id = record_exchange(self.db, ba, EUR(-9), EUR(1), EUR(0), homer,
                                'pre').id
         assert homer.balance == 0
         homer.close(None)
         assert homer.status == 'closed'
         payout = BankWirePayOut(Id=-1)
         payout.Status = 'SUCCEEDED'
         payout.ResultCode = '000000'
         payout.AuthorId = homer.mangopay_user_id
         payout.Tag = str(e_id)
         PO_Get.return_value = payout
         # Create the refund
         status_up = status.upper()
         error = 'FOO' if status == 'failed' else None
         refund = Refund(Id=-1)
         refund.DebitedFunds = Money(900, 'EUR')
         refund.Fees = Money(-100, 'EUR')
         refund.Status = status_up
         refund.ResultCode = '000001' if error else '000000'
         refund.ResultMessage = error
         refund.RefundReason = Reason(message='BECAUSE 42')
         refund.AuthorId = homer.mangopay_user_id
         R_Get.return_value = refund
         # Call back
         qs = "EventType=PAYOUT_REFUND_" + status_up + "&RessourceId=123456790"
         r = self.callback(qs)
         assert r.code == 200, r.text
         homer = homer.refetch()
         if status == 'failed':
             assert homer.balance == 0
             assert homer.status == 'closed'
         else:
             assert homer.balance == 10
             assert homer.status == 'active'
             emails = self.get_emails()
             assert len(emails) == 1
             assert emails[0]['to'][0] == 'homer <%s>' % homer.email
             assert 'fail' in emails[0]['subject']
             assert 'BECAUSE 42' in emails[0]['text']
         self.db.self_check()
         homer.update_status('active')  # reset for next loop run
 def test_payout_refund_callback(self, R_Get, PO_Get):
     homer, ba = self.homer, self.homer_route
     for status in ('failed', 'succeeded'):
         # Create the payout
         self.make_exchange('mango-cc', 10, 0, homer)
         e_id = record_exchange(self.db, ba, EUR(-9), EUR(1), EUR(0), homer, 'pre').id
         assert homer.balance == 0
         homer.close(None)
         assert homer.status == 'closed'
         payout = BankWirePayOut(Id=-1)
         payout.Status = 'SUCCEEDED'
         payout.ResultCode = '000000'
         payout.AuthorId = homer.mangopay_user_id
         payout.Tag = str(e_id)
         PO_Get.return_value = payout
         # Create the refund
         status_up = status.upper()
         error = 'FOO' if status == 'failed' else None
         refund = Refund(Id=-1)
         refund.DebitedFunds = Money(900, 'EUR')
         refund.Fees = Money(-100, 'EUR')
         refund.Status = status_up
         refund.ResultCode = '000001' if error else '000000'
         refund.ResultMessage = error
         refund.RefundReason = Reason(message='BECAUSE 42')
         refund.AuthorId = homer.mangopay_user_id
         R_Get.return_value = refund
         # Call back
         qs = "EventType=PAYOUT_REFUND_"+status_up+"&RessourceId=123456790"
         r = self.callback(qs)
         assert r.code == 200, r.text
         homer = homer.refetch()
         if status == 'failed':
             assert homer.balance == 0
             assert homer.status == 'closed'
         else:
             assert homer.balance == 10
             assert homer.status == 'active'
             emails = self.get_emails()
             assert len(emails) == 1
             assert emails[0]['to'][0] == 'homer <%s>' % homer.email
             assert 'fail' in emails[0]['subject']
             assert 'BECAUSE 42' in emails[0]['text']
         self.db.self_check()
         homer.update_status('active')  # reset for next loop run