Ejemplo n.º 1
0
 def test_UpsertLinkList(self):
     links = self.transaction.links.get('Multiple')
     random_id = random_string(8)
     links.add(Link(linked_transaction_id=random_id))
     self.transaction.upsert_link_set('Multiple', links)
     links = self.transaction.links.get('Multiple')
     self.assertEqual(len(links), 4)  # The test script inserts 3 links
     random_id_link = [link for link in links if link.linked_transaction_id == random_id]
     self.assertEqual(len(random_id_link), 1)
Ejemplo n.º 2
0
 def add_link(self, link_type, linked_transaction_id):
     new_link = Link(linked_transaction_id=linked_transaction_id)
     link_set = self.links.get(link_type)
     if link_set:
         if not isinstance(link_set, set):
             link_set = {link_set}
         link_set.add(new_link)
     else:
         link_set = new_link
     self.upsert_link_set(link_type=link_type, link_set=link_set)
def generate_transaction(asset_manager_id=None,
                         asset_book_id=None,
                         counterparty_book_id=None,
                         asset_id=None,
                         quantity=None,
                         transaction_date=None,
                         transaction_id=None,
                         price=None,
                         transaction_action=None,
                         transaction_type=None,
                         settlement_date=None,
                         transaction_status=None,
                         transaction_currency=None,
                         settlement_currency=None,
                         net_affecting_charges=None,
                         charge_currency=None):
    # Explicitly handle price is None (in case price is 0)
    price = Decimal(random.uniform(1.0, 1000.0)).quantize(
        Decimal('0.01')) if price is None else price
    transaction_currency = transaction_currency or random.choice(
        ['SGD', 'USD'])
    settlement_currency = settlement_currency or transaction_currency or random.choice(
        ['SGD', 'USD'])
    common = generate_common(asset_manager_id=asset_manager_id,
                             asset_book_id=asset_book_id,
                             counterparty_book_id=counterparty_book_id,
                             asset_id=asset_id,
                             quantity=quantity,
                             transaction_date=transaction_date,
                             transaction_id=transaction_id,
                             transaction_action=transaction_action,
                             transaction_status=transaction_status,
                             transaction_type=transaction_type,
                             settlement_date=settlement_date)

    transaction = Transaction(price=price,
                              transaction_currency=transaction_currency,
                              settlement_currency=settlement_currency,
                              **common)
    charges = {
        charge_type:
        Charge(charge_value=Decimal(random.uniform(1.0, 100.0)).quantize(
            Decimal('0.01')),
               currency=charge_currency or random.choice(['USD', 'SGD']),
               net_affecting=net_affecting_charges
               or random.choice([True, False]))
        for charge_type in CHARGE_TYPES
    }

    links = {
        'Single': Link(linked_transaction_id=random_string(8)),
        'Multiple':
        {Link(linked_transaction_id=random_string(8))
         for x in range(3)}
    }

    codes = {
        code_type: Code(code_value=random_string(8))
        for code_type in CODE_TYPES
    }
    comments = {
        comment_type: Comment(comment_value=random_string(8))
        for comment_type in COMMENT_TYPES
    }
    parties = {
        party_type: Party(party_id=random_string(8))
        for party_type in PARTY_TYPES
    }
    rates = {
        rate_type:
        Rate(rate_value=Decimal(random.uniform(1.0, 100.0)).quantize(
            Decimal('0.01')))
        for rate_type in RATE_TYPES
    }
    references = {
        ref_type: Reference(reference_value=random_string(10))
        for ref_type in REFERENCE_TYPES
    }

    transaction.charges.update(charges)
    transaction.codes.update(codes)
    transaction.comments.update(comments)
    transaction.links.update(links)
    transaction.parties.update(parties)
    transaction.rates.update(rates)
    transaction.references.update(references)
    return transaction