Skip to content

Commit

Permalink
fix omissions in previous commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jantman committed Dec 29, 2022
1 parent e4526a4 commit 89e2f46
Showing 1 changed file with 1 addition and 91 deletions.
92 changes: 1 addition & 91 deletions biweeklybudget/tests/unit/flaskapp/views/test_plaid.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@
from biweeklybudget import settings
from biweeklybudget.version import VERSION
from biweeklybudget.flaskapp.views.plaid import (
PlaidJs, PlaidPublicToken, PlaidHandleLink, set_url_rules,
PlaidConfigJS, PlaidUpdate, PlaidRefreshAccounts,
PlaidJs, PlaidHandleLink, set_url_rules, PlaidUpdate, PlaidRefreshAccounts,
PlaidUpdateItemInfo, PlaidLinkToken
)
from biweeklybudget.utils import dtnow
Expand All @@ -69,7 +68,6 @@ def test_rules(self):
with patch.multiple(
pbm,
PlaidHandleLink=DEFAULT,
PlaidPublicToken=DEFAULT,
PlaidJs=DEFAULT,
PlaidUpdate=DEFAULT,
PlaidRefreshAccounts=DEFAULT,
Expand Down Expand Up @@ -336,82 +334,6 @@ def se_acct(**kwargs):
assert mocks['PlaidAccount'].mock_calls == []


class TestPlaidPublicToken:

@patch.dict('os.environ', {}, clear=True)
def test_normal(self):
mock_json = Mock()
mock_req = Mock(form={'item_id': 'Item1'})
mock_client = MagicMock()
mock_client.Item.public_token.create.return_value = {
'create': 'response'
}
mock_item = Mock(item_id='Item1', access_token='aToken')
mock_db = Mock()
mock_query = Mock()
mock_query.get.return_value = mock_item
mock_db.query.return_value = mock_query
with patch(f'{pbm}.db_session', mock_db):
with patch(f'{pbm}.jsonify') as m_jsonify:
m_jsonify.return_value = mock_json
with patch(f'{pbm}.request', mock_req):
with patch(f'{pbm}.plaid_client') as m_client:
m_client.return_value = mock_client
res = PlaidPublicToken().post()
assert res == mock_json
assert m_jsonify.mock_calls == [
call({'create': 'response'})
]
assert mock_json.mock_calls == []
assert m_client.mock_calls == [
call(),
call().Item.public_token.create('aToken')
]
assert mock_db.mock_calls == [
call.query(PlaidItem),
call.query().get('Item1')
]

@patch.dict('os.environ', {}, clear=True)
def test_exception(self):
mock_json = Mock()
mock_req = Mock(form={'item_id': 'Item1'})
mock_client = MagicMock()
mock_client.Item.public_token.create.side_effect = ApiException(
reason='some error message',
status=999,
)
mock_item = Mock(item_id='Item1', access_token='aToken')
mock_db = Mock()
mock_query = Mock()
mock_query.get.return_value = mock_item
mock_db.query.return_value = mock_query
with patch(f'{pbm}.db_session', mock_db):
with patch(f'{pbm}.jsonify') as m_jsonify:
m_jsonify.return_value = mock_json
with patch(f'{pbm}.request', mock_req):
with patch(f'{pbm}.plaid_client') as m_client:
m_client.return_value = mock_client
res = PlaidPublicToken().post()
assert res == mock_json
assert m_jsonify.mock_calls == [
call({
'success': False,
'message': 'Exception: (999)\nReason: some error message\n'
})
]
assert mock_json.mock_calls == []
assert mock_json.status_code == 400
assert m_client.mock_calls == [
call(),
call().Item.public_token.create('aToken')
]
assert mock_db.mock_calls == [
call.query(PlaidItem),
call.query().get('Item1')
]


class TestPlaidRefreshAccounts:

@patch.dict('os.environ', {}, clear=True)
Expand Down Expand Up @@ -838,18 +760,6 @@ def se_inst(data):
assert mocks['PlaidAccount'].mock_calls == []


class TestPlaidConfigJS:

def test_happy_path(self):
assert PlaidConfigJS().get() == dedent(f"""
// generated by utils.PlaidConfigJS
var BIWEEKLYBUDGET_VERSION = "{VERSION}";
var PLAID_ENV = "{settings.PLAID_ENV}";
var PLAID_PRODUCTS = "{settings.PLAID_PRODUCTS}";
var PLAID_COUNTRY_CODES = "{settings.PLAID_COUNTRY_CODES}";
""")


class TestPlaidUpdate:

pb = f'{pbm}.PlaidUpdate'
Expand Down

0 comments on commit 89e2f46

Please sign in to comment.