ofx-processor/tests/test_ynab_integration.py

37 lines
1.1 KiB
Python
Raw Normal View History

2020-02-29 11:46:11 +01:00
import json
import unittest
from unittest import mock
2021-11-20 15:00:43 +01:00
import ofx_processor.utils.config
2020-02-29 11:46:11 +01:00
from ofx_processor.utils import ynab
class YNABIntegrationTestCase(unittest.TestCase):
@mock.patch("requests.post")
def test_data_sent_to_ynab(self, post):
2021-11-20 15:00:43 +01:00
post.return_value.status_code = 201
ofx_processor.utils.config.DEFAULT_CONFIG_DIR = "tests/samples"
2020-02-29 11:46:11 +01:00
with open("tests/samples/revolut_expected.json", encoding="utf-8") as f:
transactions = json.load(f)
with open("tests/samples/revolut_transactions.json", encoding="utf-8") as f:
2020-02-29 11:46:11 +01:00
expected_data = json.load(f)
expected_headers = {"Authorization": f"Bearer <YOUR API TOKEN>"}
expected_url = f"{ynab.BASE_URL}/budgets/<YOUR BUDGET ID>/transactions"
ynab.push_transactions(transactions, "revolut")
post.assert_called_once_with(
expected_url, json=expected_data, headers=expected_headers
)
@mock.patch("requests.post")
def test_no_data_to_send(self, post):
ynab.push_transactions([], "")
post.assert_not_called()
if __name__ == "__main__":
unittest.main() # pragma: nocover