-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improved robustness of transaction_date handling all possible cases f…
…rom api
- Loading branch information
dnbasta
committed
Feb 11, 2024
1 parent
dc4b8fd
commit bad3a09
Showing
2 changed files
with
40 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from datetime import datetime | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
|
||
from ynabapiimport.models.transaction import Transaction | ||
|
||
|
||
@patch('ynabapiimport.models.transaction.datetime', wraps=datetime) | ||
@pytest.mark.parametrize('test_input', [{'valueDate': '2024-01-01'}, | ||
{'bookingDate': '2024-01-01'}, | ||
{'valueDateTime': '2024-01-01T00:00:'}, | ||
{'bookingDateTime': '2024-01-01T00:00:00'}, | ||
{}]) | ||
def test_from_dict_datetimes(mock_datetime, test_input): | ||
mock_datetime.now.return_value = datetime(2024, 1,1) | ||
transaction_dict = {'internalTransactionId': 'id', | ||
'creditorName': 'payee', | ||
'transactionAmount': {'amount': '100'}} | ||
transaction_dict = {**transaction_dict, **test_input} | ||
t = Transaction.from_dict(transaction_dict) | ||
assert t.transaction_date == '2024-01-01' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters