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)
def test_fails_if_group_does_not_exist(self): dbsrv.clear_all(2)
def test_succeeds_normally(self): dbsrv.clear_all(1) newtrans = Trans.query.get(1) assert newtrans.kind == CLEAR_ALL