示例#1
0
def fake_exchange(db, participant, amount, fee, vat, timestamp):
    route = ExchangeRoute.from_network(participant, 'mango-cc')
    if not route:
        route = _fake_thing(
            db,
            "exchange_routes",
            participant=participant.id,
            network='mango-cc',
            address='-1',
            error='',
            one_off=False,
        )
    e = _fake_thing(
        db,
        "exchanges",
        timestamp=timestamp,
        participant=participant.id,
        amount=amount,
        fee=fee,
        vat=vat,
        status='pre',
        route=route.id,
    )
    record_exchange_result(db, e.id, 'succeeded', '', participant)
    return e
示例#2
0
def fake_exchange(db, participant, amount, fee, vat, timestamp):
    route = ExchangeRoute.from_network(participant, 'mango-cc')
    if not route:
        route = _fake_thing(
            db,
            "exchange_routes",
            participant=participant.id,
            network='mango-cc',
            address='-1',
            error='',
            one_off=False,
        )
    e = _fake_thing(
        db,
        "exchanges",
        timestamp=timestamp,
        participant=participant.id,
        amount=amount,
        fee=fee,
        vat=vat,
        status='pre',
        route=route.id,
    )
    record_exchange_result(db, e.id, 'succeeded', '', participant)
    return e
示例#3
0
 def test_record_exchange_result_updates_balance_for_positive_amounts(self):
     janet, cc = self.janet, self.janet_route
     self.make_exchange('mango-cc', 4, 0, janet)
     e_id = record_exchange(self.db, cc, D('31.59'), D('0.01'), 0, janet, 'pre')
     assert janet.balance == D('4.00')
     record_exchange_result(self.db, e_id, 'succeeded', None, janet)
     janet = Participant.from_username('janet')
     assert janet.balance == D('35.59')
示例#4
0
 def test_record_exchange_result_doesnt_restore_balance_on_success(self):
     homer, ba = self.homer, self.homer_route
     self.make_exchange('mango-cc', 50, 0, homer)
     e_id = record_exchange(self.db, ba, D('-43.98'), D('1.60'), 0, homer, 'pre')
     assert homer.balance == D('4.42')
     record_exchange_result(self.db, e_id, 'succeeded', None, homer)
     homer = Participant.from_username('homer')
     assert homer.balance == D('4.42')
示例#5
0
 def test_record_exchange_result_restores_balance_on_error(self):
     homer, ba = self.homer, self.homer_route
     self.make_exchange('mango-cc', 30, 0, homer)
     e_id = record_exchange(self.db, ba, D('-27.06'), D('0.81'), 0, homer, 'pre')
     assert homer.balance == D('02.13')
     record_exchange_result(self.db, e_id, 'failed', 'SOME ERROR', homer)
     homer = Participant.from_username('homer')
     assert homer.balance == D('30.00')
示例#6
0
 def test_record_exchange_result_updates_balance_for_positive_amounts(self):
     janet, cc = self.janet, self.janet_route
     self.make_exchange('mango-cc', 4, 0, janet)
     e_id = record_exchange(self.db, cc, D('31.59'), D('0.01'), 0, janet,
                            'pre')
     assert janet.balance == D('4.00')
     record_exchange_result(self.db, e_id, 'succeeded', None, janet)
     janet = Participant.from_username('janet')
     assert janet.balance == D('35.59')
示例#7
0
 def test_record_exchange_result_doesnt_restore_balance_on_success(self):
     homer, ba = self.homer, self.homer_route
     self.make_exchange('mango-cc', 50, 0, homer)
     e_id = record_exchange(self.db, ba, D('-43.98'), D('1.60'), 0, homer,
                            'pre')
     assert homer.balance == D('4.42')
     record_exchange_result(self.db, e_id, 'succeeded', None, homer)
     homer = Participant.from_username('homer')
     assert homer.balance == D('4.42')
示例#8
0
 def test_record_exchange_result_restores_balance_on_error(self):
     homer, ba = self.homer, self.homer_route
     self.make_exchange('mango-cc', 30, 0, homer)
     e_id = record_exchange(self.db, ba, D('-27.06'), D('0.81'), 0, homer,
                            'pre')
     assert homer.balance == D('02.13')
     record_exchange_result(self.db, e_id, 'failed', 'SOME ERROR', homer)
     homer = Participant.from_username('homer')
     assert homer.balance == D('30.00')
示例#9
0
 def test_record_exchange_result_restores_balance_on_error_with_invalidated_route(self):
     homer, ba = self.homer, self.homer_route
     self.make_exchange('mango-cc', 37, 0, homer)
     e_id = record_exchange(self.db, ba, D('-32.45'), D('0.86'), 0, homer, 'pre')
     assert homer.balance == D('3.69')
     ba.update_error('invalidated')
     record_exchange_result(self.db, e_id, 'failed', 'oops', homer)
     homer = Participant.from_username('homer')
     assert homer.balance == D('37.00')
     assert ba.error == homer.get_bank_account_error() == 'invalidated'
示例#10
0
 def make_exchange(self, route, amount, fee, participant, status='succeeded', error='', vat=0):
     if not isinstance(route, ExchangeRoute):
         network = route
         route = ExchangeRoute.from_network(participant, network)
         if not route:
             from .mangopay import MangopayHarness
             route = ExchangeRoute.insert(participant, network, MangopayHarness.card_id)
             assert route
     e_id = record_exchange(self.db, route, amount, fee, vat, participant, 'pre')
     record_exchange_result(self.db, e_id, status, error, participant)
     return e_id
示例#11
0
 def make_exchange(self, route, amount, fee, participant, status='succeeded', error='', vat=0):
     if not isinstance(route, ExchangeRoute):
         network = route
         route = ExchangeRoute.from_network(participant, network)
         if not route:
             from .mangopay import MangopayHarness
             route = ExchangeRoute.insert(participant, network, MangopayHarness.card_id)
             assert route
     e_id = record_exchange(self.db, route, amount, fee, vat, participant, 'pre')
     record_exchange_result(self.db, e_id, status, error, participant)
     return e_id
示例#12
0
 def test_record_exchange_result_restores_balance_on_error_with_invalidated_route(
         self):
     homer, ba = self.homer, self.homer_route
     self.make_exchange('mango-cc', 37, 0, homer)
     e_id = record_exchange(self.db, ba, D('-32.45'), D('0.86'), 0, homer,
                            'pre')
     assert homer.balance == D('3.69')
     ba.update_error('invalidated')
     record_exchange_result(self.db, e_id, 'failed', 'oops', homer)
     homer = Participant.from_username('homer')
     assert homer.balance == D('37.00')
     assert ba.error == homer.get_bank_account_error() == 'invalidated'
示例#13
0
def fake_exchange(db, participant, amount, fee, timestamp):
    route = ExchangeRoute.from_network(participant, "mango-cc")
    if not route:
        route = _fake_thing(
            db, "exchange_routes", participant=participant.id, network="mango-cc", address="-1", error="", one_off=False
        )
    e = _fake_thing(
        db,
        "exchanges",
        timestamp=timestamp,
        participant=participant.id,
        amount=amount,
        fee=fee,
        status="pre",
        route=route.id,
    )
    record_exchange_result(db, e.id, "succeeded", "", participant)
    return e