Skip to content

Commit

Permalink
issue #22 - fix unit tests that (strangely) were failing on Travis bu…
Browse files Browse the repository at this point in the history
…t not locally
  • Loading branch information
jantman committed Apr 1, 2017
1 parent 0e507ef commit b6c4491
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions biweeklybudget/tests/unit/flaskapp/test_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
sys.version_info[0] < 3 or
sys.version_info[0] == 3 and sys.version_info[1] < 4
):
from mock import Mock, patch, call # noqa
from mock import Mock, patch, call, DEFAULT # noqa
else:
from unittest.mock import Mock, patch, call # noqa
from unittest.mock import Mock, patch, call, DEFAULT # noqa

pbm = 'biweeklybudget.flaskapp.notifications'
pb = '%s.NotificationsController' % pbm
Expand All @@ -69,8 +69,15 @@ def test_num_stale_accounts(self):
assert mock_db.mock_calls[2] == call.query().filter().all()

def test_get_notifications_no_stale(self):
with patch('%s.num_stale_accounts' % pb) as m_num_stale:
m_num_stale.return_value = 0
with patch.multiple(
pb,
num_stale_accounts=DEFAULT,
budget_account_sum=DEFAULT,
standing_budgets_sum=DEFAULT
) as mocks:
mocks['num_stale_accounts'].return_value = 0
mocks['budget_account_sum'].return_value = 100
mocks['standing_budgets_sum'].return_value = 1
res = NotificationsController.get_notifications()
assert res == [
{
Expand All @@ -82,8 +89,15 @@ def test_get_notifications_no_stale(self):
]

def test_get_notifications_one_stale(self):
with patch('%s.num_stale_accounts' % pb) as m_num_stale:
m_num_stale.return_value = 1
with patch.multiple(
pb,
num_stale_accounts=DEFAULT,
budget_account_sum=DEFAULT,
standing_budgets_sum=DEFAULT
) as mocks:
mocks['num_stale_accounts'].return_value = 1
mocks['budget_account_sum'].return_value = 100
mocks['standing_budgets_sum'].return_value = 1
res = NotificationsController.get_notifications()
assert res == [
{
Expand All @@ -100,8 +114,15 @@ def test_get_notifications_one_stale(self):
]

def test_get_notifications_three_stale(self):
with patch('%s.num_stale_accounts' % pb) as m_num_stale:
m_num_stale.return_value = 3
with patch.multiple(
pb,
num_stale_accounts=DEFAULT,
budget_account_sum=DEFAULT,
standing_budgets_sum=DEFAULT
) as mocks:
mocks['num_stale_accounts'].return_value = 3
mocks['budget_account_sum'].return_value = 100
mocks['standing_budgets_sum'].return_value = 1
res = NotificationsController.get_notifications()
assert res == [
{
Expand Down

0 comments on commit b6c4491

Please sign in to comment.