Example #1
0
def post_trans(dbsrv=dbsrv):
    # try to extract info from JSON
    try:
        args = request.get_json()
        kind = args.get('kind')
        group_id = args.get('group_id')
        # these params won't be present if its a clear
        from_ids = args.get('from_ids')
        to_id = args.get('to_id')
        amount = args.get('amount')

        #determine kind
        if kind == "debt":
            kindn = DEBT
        elif kind == "payment":
            kindn = PAYMENT
        elif kind == "clear":
            kindn = CLEAR_ALL
        else:
            raise RuntimeError("Transaction type not specified correctly.")
    except:
        raise err.JSONParseError("JSON Parsing Failed.")

    # if this is a debt or a payment, try to add the transactions
    if kindn in [DEBT, PAYMENT]:
        for from_id in from_ids:
            dbsrv.add_transaction(group_id, from_id, to_id,
                                  amount/len(from_ids), kindn)
    elif kindn == CLEAR_ALL:
        dbsrv.clear_all(group_id)
    return jsonify(success)
Example #2
0
 def test_fail_is_users_not_in_group(self):
     dbsrv.add_transaction(1, 3, 2, 20, DEBT)
Example #3
0
 def test_succeeds_normally(self):
     dbsrv.add_transaction(1, 1, 2, 20, DEBT)
     newtrans = Trans.query.get(1)
     assert newtrans.amount == 20