import datetime from comptabilite.forms import ( get_key, map_crelan_dict, map_keytrade_dict, update_transaction_dict, ) def test_get_key(): """ """ initial = { "test_int_pos": 100.00, "test_int_neg": -100.00, } result = get_key(initial, "test_int_pos") assert result == initial["test_int_pos"] result = get_key(initial, "test_int_neg") assert result == initial["test_int_neg"] result = get_key(initial, "test_int_pos", float) assert result == float(initial["test_int_pos"]) result = get_key(initial, "test_int_neg", float) assert result == float(initial["test_int_neg"]) def test_map_crelan_dict(): """ """ initial = {} result = map_crelan_dict(initial) assert result == { "account_number": None, "amount": None, "bkAmount": None, "bxAmount": 0, "counterpart": "CRELAN", "description": None, "is_done": True, "is_simulated": False, "notes": None, "otherDescription": None, "registrationDate": None, "totalAmount": None, "transaction_type": 3, } def test_map_crelan_dict_amount_below_zero(): """ """ initial = { "Date": "01/01/2020", "Montant": -100.00, "Communication": "Payement gaufres", "Contrepartie": "Programmeur Python", "Type d'opération": "Virement", "Compte contrepartie": "BE01 2345 6789 1234", } result = map_crelan_dict(initial) assert result == { "registrationDate": datetime.datetime.strptime("01/01/2020", "%d/%m/%Y"), "totalAmount": float(100.00), "bkAmount": float(100.00), "amount": float(100.00), "transaction_type": 4, "description": "Payement gaufres", "is_done": True, "is_simulated": False, "counterpart": "Programmeur Python", "bxAmount": 0, "otherDescription": "Virement", "account_number": "BE01 2345 6789 1234", } def test_map_crelan_dict_cotisation_in_description(): """ """ initial = { "Date": "01/01/2020", "Montant": 100.00, "Communication": "Cotisation", "Contrepartie": "Programmeur Python", "Type d'opération": "Virement", "Compte contrepartie": "BE01 2345 6789 1234", } result = map_crelan_dict(initial) assert result == { "registrationDate": datetime.datetime.strptime("01/01/2020", "%d/%m/%Y"), "totalAmount": float(100.00), "bkAmount": float(100.00), "amount": float(100.00), "transaction_type": 6, "description": "Cotisation", "is_done": True, "is_simulated": False, "counterpart": "Programmeur Python", "bxAmount": 0, "otherDescription": "Virement", "account_number": "BE01 2345 6789 1234", } def test_map_crelan_dict_counterpart_and_description_are_empty(): """ """ initial = { "Date": "01/01/2020", "Montant": -4.00, "Communication": "", "Contrepartie": "", "Type d'opération": "Virement", "Compte contrepartie": "BE01 2345 6789 1234", } result = map_crelan_dict(initial) assert result == { "registrationDate": datetime.datetime.strptime("01/01/2020", "%d/%m/%Y"), "totalAmount": float(4.00), "bkAmount": float(4.00), "amount": float(4.00), "transaction_type": 3, "description": "Virement", "is_done": True, "is_simulated": False, "counterpart": "CRELAN", "bxAmount": 0, "otherDescription": "Virement", "account_number": "BE01 2345 6789 1234", "notes": "Virement", } def test_map_keytrade_dict(): """ """ initial = {} result = map_keytrade_dict(initial) assert result == { "account_number": None, "amount": None, "bkAmount": None, "bxAmount": 0, "counterpart": None, "description": None, "is_done": True, "is_simulated": False, "notes": None, "otherDescription": None, "registrationDate": None, "totalAmount": None, "transaction_type": 5, } def test_map_keytrade_dict_amount_below_zero(): """ """ initial = { "Date": "01.01.2020", "Montant": -100.00, "Description": "Payement gaufres", "Contrepartie": "Programmeur Python", "Type d'opération": "Virement", "Compte": "BE01 2345 6789 1234", } result = map_keytrade_dict(initial) assert result == { "registrationDate": datetime.datetime.strptime("01.01.2020", "%d.%m.%Y"), "totalAmount": float(100.00), "bkAmount": float(100.00), "amount": float(100.00), "transaction_type": 4, "description": "Payement gaufres", "is_done": True, "is_simulated": False, "counterpart": "BE01 2345 6789 1234", "bxAmount": 0, "otherDescription": "Payement gaufres", "account_number": "BE01 2345 6789 1234", "notes": "Payement gaufres", } def test_map_keytrade_dict_cotisation_in_description(): """ """ initial = { "Date": "01.01.2020", "Montant": 100.00, "Description": "Cotisation", "Contrepartie": "Programmeur Python", "Type d'opération": "Virement", "Compte": "BE01 2345 6789 1234", } result = map_keytrade_dict(initial) assert result == { "registrationDate": datetime.datetime.strptime("01.01.2020", "%d.%m.%Y"), "totalAmount": float(100.00), "bkAmount": float(100.00), "amount": float(100.00), "transaction_type": 6, "description": "Cotisation", "is_done": True, "is_simulated": False, "counterpart": "BE01 2345 6789 1234", "bxAmount": 0, "otherDescription": "Cotisation", "account_number": "BE01 2345 6789 1234", "notes": "Cotisation", } def test_map_keytrade_dict_counterpart_is_empty(): """ """ initial = { "Date": "01.01.2020", "Montant": -4.00, "Description": "Description.", "Contrepartie": "", "Type d'opération": "Virement", "Compte": "-", } result = map_keytrade_dict(initial) assert result == { "registrationDate": datetime.datetime.strptime("01.01.2020", "%d.%m.%Y"), "totalAmount": float(4.00), "bkAmount": float(4.00), "amount": float(4.00), "transaction_type": 3, "description": "Description.", "is_done": True, "is_simulated": False, "counterpart": "KEYTRADE", "bxAmount": 0, "otherDescription": "Description.", "account_number": "-", "notes": "Description.", } def test_update_transaction_dict_amount_below_zero(): """ """ transaction_dict = { "registrationDate": datetime.datetime.strptime("01.01.2020", "%d.%m.%Y"), "totalAmount": float(-4.00), "bkAmount": float(-4.00), "amount": float(-4.00), "transaction_type": 3, "description": "Description.", "is_done": True, "is_simulated": False, "counterpart": "TEST", "bxAmount": 0, "otherDescription": "Description.", "account_number": "-", "notes": "Description.", } result = update_transaction_dict(transaction_dict) assert result == { "registrationDate": datetime.datetime.strptime("01.01.2020", "%d.%m.%Y"), "totalAmount": float(4.00), "bkAmount": float(4.00), "amount": float(4.00), "transaction_type": 4, "description": "Description.", "is_done": True, "is_simulated": False, "counterpart": "TEST", "bxAmount": 0, "otherDescription": "Description.", "account_number": "-", "notes": "Description.", } def test_update_transaction_dict_cotisation_in_description(): """ """ transaction_dict = { "registrationDate": datetime.datetime.strptime("01.01.2020", "%d.%m.%Y"), "totalAmount": float(4.00), "bkAmount": float(4.00), "amount": float(4.00), "transaction_type": 3, "description": "Cotisation.", "is_done": True, "is_simulated": False, "counterpart": "TEST", "bxAmount": 0, "otherDescription": "Cotisation.", "account_number": "-", "notes": "Cotisation.", } result = update_transaction_dict(transaction_dict) assert result == { "registrationDate": datetime.datetime.strptime("01.01.2020", "%d.%m.%Y"), "totalAmount": float(4.00), "bkAmount": float(4.00), "amount": float(4.00), "transaction_type": 6, "description": "Cotisation.", "is_done": True, "is_simulated": False, "counterpart": "TEST", "bxAmount": 0, "otherDescription": "Cotisation.", "account_number": "-", "notes": "Cotisation.", } def test_update_transaction_dict(): """ """ transaction_dict = { "registrationDate": datetime.datetime.strptime("01.01.2020", "%d.%m.%Y"), "totalAmount": None, "bkAmount": None, "amount": None, "transaction_type": 3, "description": "TEST", "is_done": True, "is_simulated": False, "counterpart": "TEST", "bxAmount": 0, "otherDescription": "TEST", "account_number": "-", "notes": "TEST", } result = update_transaction_dict(transaction_dict) assert result == transaction_dict transaction_dict["totalAmount"] = float(4.00) transaction_dict["bkAmount"] = float(4.00) transaction_dict["amount"] = float(4.00) result = update_transaction_dict(transaction_dict) assert result == transaction_dict transaction_dict["description"] = None result = update_transaction_dict(transaction_dict) assert result == transaction_dict