-
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.
- Loading branch information
dnbasta
committed
Apr 8, 2024
1 parent
8289e22
commit a9d1c31
Showing
1 changed file
with
62 additions
and
73 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 |
---|---|---|
@@ -1,73 +1,62 @@ | ||
# from typing import List | ||
# from unittest.mock import patch, MagicMock | ||
# | ||
# import pytest | ||
# | ||
# from ynabtransactionadjuster import YnabTransactionAdjuster | ||
# from ynabtransactionadjuster.exceptions import AdjustError | ||
# from ynabtransactionadjuster.models import ModifiedTransaction, OriginalTransaction | ||
# | ||
# | ||
# class MockYnabTransactionAdjuster(YnabTransactionAdjuster): | ||
# | ||
# def __init__(self): | ||
# self._client = None | ||
# self.categories = None | ||
# self.payees = None | ||
# | ||
#k | ||
# @pytest.fixture | ||
# def mock_adjuster(mock_original_transaction, mock_category_repo): | ||
# class MyAdjuster(MockYnabTransactionAdjuster): | ||
# | ||
# def filter(self, transactions): | ||
# return transactions | ||
# | ||
# def adjust(self, original, modifier): | ||
# return modifier | ||
# | ||
# my_adjuster = MyAdjuster() | ||
# mock_client = MagicMock() | ||
# mock_client.fetch_transactions.return_value = [mock_original_transaction] | ||
# my_adjuster._client = mock_client | ||
# my_adjuster.categories = mock_category_repo | ||
# return my_adjuster | ||
# | ||
# | ||
# def test_test(mock_category_repo, caplog, mock_original_transaction): | ||
# # Arrange | ||
# class MyAdjuster(MockYnabTransactionAdjuster): | ||
# | ||
# def filter(self, transactions): | ||
# return transactions | ||
# | ||
# def adjust(self, original, modifier): | ||
# modifier.memo = 'test' | ||
# return modifier | ||
# | ||
# my_adjuster = MyAdjuster() | ||
# mock_client = MagicMock() | ||
# mock_client.fetch_transactions.return_value = [mock_original_transaction] | ||
# my_adjuster._client = mock_client | ||
# my_adjuster.categories = mock_category_repo | ||
# # Act | ||
# r = my_adjuster.test() | ||
# | ||
# # Assert | ||
# assert len(r) == 1 | ||
# assert isinstance(r[0], ModifiedTransaction) | ||
# | ||
# | ||
# def test_run(mock_adjuster, caplog, mock_original_transaction): | ||
# # Arrange | ||
# class MyAdjuster(MockYnabTransactionAdjuster): | ||
# def filter(self, transactions): | ||
# return transactions | ||
# | ||
# def adjust(self, original, modifier): | ||
# modifier.memo = 'test' | ||
# return modifier | ||
# | ||
# my_adjuster = MyAdjuster() | ||
# my_adjuster.run() | ||
# assert my_adjuster._client.update_transactions.called_once() | ||
from unittest.mock import MagicMock | ||
|
||
import pytest | ||
|
||
from ynabtransactionadjuster import YnabTransactionAdjuster | ||
|
||
|
||
class MockYnabTransactionAdjuster(YnabTransactionAdjuster): | ||
|
||
def __init__(self, memo: str): | ||
self._client = None | ||
self.categories = None | ||
self.payees = None | ||
self.memo = memo | ||
|
||
def filter(self, transactions): | ||
return transactions | ||
|
||
def adjust(self, original, modifier): | ||
modifier.memo = self.memo | ||
return modifier | ||
|
||
|
||
def test_test(mock_category_repo, caplog, mock_original_transaction): | ||
# Arrange | ||
memo = 'test' | ||
my_adjuster = MockYnabTransactionAdjuster(memo=memo) | ||
mock_client = MagicMock() | ||
mock_client.fetch_transactions.return_value = [mock_original_transaction] | ||
my_adjuster._client = mock_client | ||
my_adjuster.categories = mock_category_repo | ||
# Act | ||
r = my_adjuster.test() | ||
|
||
# Assert | ||
assert len(r) == 1 | ||
assert r[0]['changes']['memo']['changed'] == memo | ||
|
||
|
||
def test_run(mock_category_repo, caplog, mock_original_transaction): | ||
# Arrange | ||
my_adjuster = MockYnabTransactionAdjuster(memo='test') | ||
mock_client = MagicMock() | ||
mock_client.fetch_transactions.return_value = [mock_original_transaction] | ||
my_adjuster._client = mock_client | ||
my_adjuster.categories = mock_category_repo | ||
|
||
my_adjuster.run() | ||
my_adjuster._client.update_transactions.assert_called_once() | ||
|
||
|
||
@pytest.mark.parametrize('test_input', ['a', 'b']) | ||
def test_run_no_modified(mock_category_repo, caplog, test_input, mock_original_transaction): | ||
# Arrange | ||
my_adjuster = MockYnabTransactionAdjuster(memo='memo') | ||
mock_client = MagicMock() | ||
mock_client.fetch_transactions.return_value = [mock_original_transaction] if test_input == 'a' else [] | ||
my_adjuster._client = mock_client | ||
my_adjuster.categories = mock_category_repo | ||
|
||
my_adjuster.run() | ||
my_adjuster._client.update_transactions.assert_not_called() |