def test_detect_usbank(self): input_ = { "Date": "12/23/2019", "Transaction": "CREDIT", "Name": "PAYMENT THANK YOU", "Memo": "WEB AUTOMTC; ; ; ; ; ", "Amount": 123.45, } expected = "usbank", CARD_DEFINITIONS["usbank"] self.assertEqual(expected, identify_card(input_))
def test_detect_chase(self): input_ = { "Transaction Date": "12/30/2018", "Post Date": "01/01/2019", "Description": "CHESHIRE CAFE", "Category": "Food & Drink", "Type": "Sale", "Amount": -123, } expected = "chase", CARD_DEFINITIONS["chase"] self.assertEqual(expected, identify_card(input_))
def test_detect_capital_one(self): input_ = { "Transaction Date": "2019-01-02", "Posted Date": "2019-01-02", "Card No.": 1234, "Description": "UBER", "Category": "Other Travel", "Debit": 123, "Credit": None, } expected = "capital_one", CARD_DEFINITIONS["capital_one"] self.assertEqual(expected, identify_card(input_))
def parse(infile, outfile): """Converts extracted json files files into uniform schema""" log.info(f"Parsing {infile} into {outfile}") card, card_def = identify_card(json.loads(open(infile).readline())) with open(infile, "r") as inf, open(outfile, "w") as outf: for line in inf: record = json.loads(line) parsed_record = parse_record(record, card, card_def) outf.write(f"{json.dumps(parsed_record)}\n")
def test_detect_amex(self): input_ = { "Date": "1/3/20", "Description": "Trader Joe's", "Amount": 123, "Extended Details": '0098616 626-599-3700\n"Description : GROCERY STORES,SUPE Price : 0.00"\n626-599-3700', "Appears On Your Statement As": "TRADER JOE'S #502 QCAMBRIDGE MA", "Address": "748 MEMORIAL DR\nCAMBRIDGE\nMA\n02139\nUNITED STATES", "Reference": "'123'", "Category": "Merchandise & Supplies-Groceries", } expected = "amex", CARD_DEFINITIONS["amex"] self.assertEqual(expected, identify_card(input_))
def test_parse(self): input_ = { "source_file": "amex.csv", "Date": "12/30/19", "Reference": 1234567890, "Description": "Trader Joe's", "Card Member": "foo", "Card Number": 12345, "Amount": 16.23, "Category": "Merchandise & Supplies-Groceries", "Type": "DEBIT", "Appears On Your Statement As": "TRADER JOE'S #502 QCAMBRIDGE MA", "Address": "748 MEMORIAL DR\nCAMBRIDGE\nMA\n02139\nUNITED STATES", "Phone Number": 1234567890, "Website": "http://traderjoes.com", "Additional Information": '0080291 626-599-3700\n"Description : GROCERY STORES,SUPE Price : 0.00"\n626-599-3700', } expected = { "date": "12/30/19", "description": "Trader Joe's", "amount": 16.23, "category": "Merchandise & Supplies-Groceries", "source": "amex", "source_file": "amex.csv", } card, card_def = identify_card(input_) self.assertEqual(parse_record(input_, card, card_def), expected) input_ = { "source_file": "capital_one.csv", "Transaction Date": "2019-12-28", "Posted Date": "2019-12-30", "Card No.": 1234, "Description": "NIGHT SHIFT BREWING @", "Category": "Dining", "Debit": 4, "Credit": None, } expected = { "date": "2019-12-28", "description": "NIGHT SHIFT BREWING @", "amount": 4, "category": "Dining", "source": "capital_one", "source_file": "capital_one.csv", } card, card_def = identify_card(input_) self.assertEqual(parse_record(input_, card, card_def), expected) input_ = { "source_file": "chase.csv", "Transaction Date": "12/30/2019", "Post Date": "12/31/2019", "Description": "THE LANDING PIZZA AND KIT", "Category": "Food & Drink", "Type": "Sale", "Amount": -44, } expected = { "date": "12/30/2019", "description": "THE LANDING PIZZA AND KIT", "amount": 44, "category": "Food & Drink", "source": "chase", "source_file": "chase.csv", } card, card_def = identify_card(input_) self.assertEqual(parse_record(input_, card, card_def), expected) input_ = { "source_file": "usbank.csv", "Date": "12/18/2018", "Transaction": "CREDIT", "Name": "REI #80 BOSTON BOSTON MA", "Memo": "12345; ; ; ; ", "Amount": 59.89, } expected = { "date": "12/18/2018", "description": "REI #80 BOSTON BOSTON MA", "amount": -59.89, "category": None, "source": "usbank", "source_file": "usbank.csv", } card, card_def = identify_card(input_) self.assertEqual(parse_record(input_, card, card_def), expected)