Beispiel #1
0
def test_amex_ytd():
    test_data = {
        "Date": "1/9/20",
        "Description": "ONLINE PAYMENT - THANK YOU",
        "Card Member": "ACHIN S SAGADEVA",
        "Account #": "-220146",
        "Amount": "-117.36",
    }
    assert get_expense_type(list(test_data.keys())) == "amex_ytd"
    normalized_data = normalizer_map.get("amex_ytd")(test_data)
    assert normalized_data["amount"] == 117.36
    assert normalized_data["is_credit"] is True
    assert normalized_data["description"] == "ONLINE PAYMENT - THANK YOU"

    test_data["Amount"] = "35.00"
    normalized_data = normalizer_map.get("amex")(test_data)
    assert normalized_data["is_credit"] is False
Beispiel #2
0
def test_discover():
    test_data = {
        "Trans. Date": "12/16/2019",
        "Post Date": "12/17/2019",
        "Description": "Online payment from CHK 4119",
        "Amount": "473.93",
        "Category": "ThemePark",
    }
    assert get_expense_type(list(test_data.keys())) == "discover"
    normalized_data = normalizer_map.get("discover")(test_data)
    assert normalized_data["amount"] == 473.93
    assert normalized_data["is_credit"] is False
    assert normalized_data["description"] == "Online payment from CHK 4119"
    assert normalized_data["category"] == "ThemePark"

    test_data["Amount"] = "-400.00"
    normalized_data = normalizer_map.get("discover")(test_data)
    assert normalized_data["is_credit"] is True
Beispiel #3
0
def test_apple():
    test_data = {
        "Transaction Date": "12/12/2019",
        "Clearing Date": "12/16/2019",
        "Description": "Apple test",
        "Amount (USD)": "4.99",
        "Category": "Other",
        "Merchant": "Walgreens",
        "Type": "Purchase",
    }
    assert get_expense_type(list(test_data.keys())) == "apple"
    normalized_data = normalizer_map.get("apple")(test_data)
    assert normalized_data["amount"] == 4.99
    assert normalized_data["is_credit"] is False
    assert normalized_data["description"] == "Apple test"
    assert normalized_data["category"] == "Other"

    test_data["Amount (USD)"] = "-400.00"
    normalized_data = normalizer_map.get("apple")(test_data)
    assert normalized_data["is_credit"] is True
Beispiel #4
0
def test_bofa():
    test_data = {
        "Posted Date": "12/16/2019",
        "Reference Number": "35006005720001509041659",
        "Payee": "Online payment from CHK 4119",
        "Address": "",
        "Amount": "473.93",
    }
    assert get_expense_type(list(test_data.keys())) == "bofa"
    normalized_data = normalizer_map.get("bofa")(test_data)
    assert normalized_data["amount"] == 473.93
    assert normalized_data["is_credit"] is True
    assert normalized_data["description"] == "Online payment from CHK 4119"
    assert normalized_data["ref_num"] == "35006005720001509041659"

    test_data["Address"] = "AIRBNB.COM    CA"
    test_data["Amount"] = "-159.51"
    normalized_data = normalizer_map.get("bofa")(test_data)
    assert normalized_data["is_credit"] is False
    assert normalized_data["address"] == "AIRBNB.COM    CA"
Beispiel #5
0
def test_amex():
    test_data = {
        "Date": "1/9/20",
        "Reference": "320200090698686232",
        "Description": "ONLINE PAYMENT - THANK YOU",
        "Card Member": "ACHIN S SAGADEVA",
        "Card Number": "-22006",
        "Amount": "-117.36",
        "Category": "",
        "Type": "CREDIT",
    }
    assert get_expense_type(list(test_data.keys())) == "amex"
    normalized_data = normalizer_map.get("amex")(test_data)
    assert normalized_data["amount"] == 117.36
    assert normalized_data["is_credit"] is True
    assert normalized_data["description"] == "ONLINE PAYMENT - THANK YOU"
    assert normalized_data["ref_num"] == "320200090698686232"

    test_data["Amount"] = "35.00"
    normalized_data = normalizer_map.get("amex")(test_data)
    assert normalized_data["is_credit"] is False
Beispiel #6
0
logger = logging.getLogger(__name__)
src_path = os.path.abspath("./data")
dst_path = os.path.abspath("./output-data")
if not os.path.exists(dst_path):
    os.makedirs(dst_path)
files = os.listdir(src_path)
master_data = []
for file in files:
    file_path = os.path.join(src_path, file)
    column_list = get_csv_header(file_path)
    read_type = get_expense_type(column_list)
    if not read_type:
        logger.error("Input type not found for - {}".format(column_list))
        continue
    normalizer_func = normalizer_map.get(read_type)
    logger.debug("Input type is - {}".format(read_type))
    csv_reader = csv.DictReader(open(file_path), delimiter=",")
    for row_dict in csv_reader:
        logger.debug(row_dict)
        tmp_norm_dict = normalizer_func(row_dict)
        tmp_expense = Expense.from_dict(tmp_norm_dict)
        master_data.append(tmp_expense)
master_data.sort()

expense_file = open(os.path.join(dst_path, "all-expenses.csv"),
                    "w",
                    newline="")
payment_file = open(os.path.join(dst_path, "all-payments.csv"),
                    "w",
                    newline="")