Skip to content

Commit

Permalink
issue #97 - replace all uses of datetime.now() in tests with dtnow()
Browse files Browse the repository at this point in the history
  • Loading branch information
jantman committed Aug 6, 2017
1 parent 82c2edb commit 33f1a1d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
17 changes: 9 additions & 8 deletions biweeklybudget/tests/acceptance/flaskapp/views/test_budgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
from biweeklybudget.models.txn_reconcile import TxnReconcile
from selenium.webdriver.support.ui import Select
from biweeklybudget.biweeklypayperiod import BiweeklyPayPeriod
from biweeklybudget.utils import dtnow


@pytest.mark.acceptance
Expand Down Expand Up @@ -627,7 +628,7 @@ def test_2_transfer_modal(self, base_url, selenium):
self.assert_modal_displayed(modal, title, body)
assert title.text == 'Budget Transfer'
assert body.find_element_by_id(
'budg_txfr_frm_date').get_attribute('value') == datetime.now(
'budg_txfr_frm_date').get_attribute('value') == dtnow(
).strftime('%Y-%m-%d')
amt = body.find_element_by_id('budg_txfr_frm_amount')
amt.clear()
Expand Down Expand Up @@ -711,7 +712,7 @@ def test_2_transfer_modal(self, base_url, selenium):
def test_3_verify_db(self, testdb):
desc = 'Budget Transfer - 123.45 from Periodic2 (2) to Standing2 (5)'
t1 = testdb.query(Transaction).get(4)
assert t1.date == datetime.now().date()
assert t1.date == dtnow().date()
assert float(t1.actual_amount) == 123.45
assert float(t1.budgeted_amount) == 123.45
assert t1.description == desc
Expand All @@ -725,7 +726,7 @@ def test_3_verify_db(self, testdb):
assert rec1.ofx_account_id is None
assert rec1.note == desc
t2 = testdb.query(Transaction).get(5)
assert t2.date == datetime.now().date()
assert t2.date == dtnow().date()
assert float(t2.actual_amount) == -123.45
assert float(t2.budgeted_amount) == -123.45
assert t2.description == desc
Expand Down Expand Up @@ -764,7 +765,7 @@ def test_2_transfer_modal(self, base_url, selenium, testdb):
ptable = selenium.find_element_by_id('table-periodic-budgets')
ptexts = self.tbody2textlist(ptable)
assert ptexts[2] == ['yes', 'Periodic2 (2)', '$234.00']
pp = BiweeklyPayPeriod.period_for_date(datetime.now(), testdb)
pp = BiweeklyPayPeriod.period_for_date(dtnow(), testdb)
assert float(pp.budget_sums[2]['allocated']) == 222.22
assert float(pp.budget_sums[2]['budget_amount']) == 234.0
assert "%.2f" % float(pp.budget_sums[2]['remaining']) == '11.78'
Expand All @@ -776,7 +777,7 @@ def test_2_transfer_modal(self, base_url, selenium, testdb):
self.assert_modal_displayed(modal, title, body)
assert title.text == 'Budget Transfer'
assert body.find_element_by_id(
'budg_txfr_frm_date').get_attribute('value') == datetime.now(
'budg_txfr_frm_date').get_attribute('value') == dtnow(
).strftime('%Y-%m-%d')
amt = body.find_element_by_id('budg_txfr_frm_amount')
amt.clear()
Expand Down Expand Up @@ -858,7 +859,7 @@ def test_2_transfer_modal(self, base_url, selenium, testdb):
assert ptexts[2] == ['yes', 'Periodic2 (2)', '$234.00']

def test_3_verify_db(self, testdb):
d = datetime.now().date()
d = dtnow().date()
pp = BiweeklyPayPeriod.period_for_date(d, testdb)
print('Found period for %s: %s' % (d, pp))
assert float(pp.budget_sums[2]['allocated']) == 98.77
Expand All @@ -869,7 +870,7 @@ def test_3_verify_db(self, testdb):
assert float(pp.budget_sums[2]['trans_total']) == 98.77
desc = 'Budget Transfer - 123.45 from Standing2 (5) to Periodic2 (2)'
t1 = testdb.query(Transaction).get(4)
assert t1.date == datetime.now().date()
assert t1.date == dtnow().date()
assert float(t1.actual_amount) == 123.45
assert float(t1.budgeted_amount) == 123.45
assert t1.description == desc
Expand All @@ -883,7 +884,7 @@ def test_3_verify_db(self, testdb):
assert rec1.ofx_account_id is None
assert rec1.note == desc
t2 = testdb.query(Transaction).get(5)
assert t2.date == datetime.now().date()
assert t2.date == dtnow().date()
assert float(t2.actual_amount) == -123.45
assert float(t2.budgeted_amount) == -123.45
assert t2.description == desc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,7 @@ def test_04_make_trans_modal_num_per(self, base_url, selenium, testdb):
# this default is populated by JS, which will use localtime
assert body.find_element_by_id(
'schedtotrans_frm_date').get_attribute(
'value') == datetime.now().strftime('%Y-%m-%d')
'value') == dtnow().strftime('%Y-%m-%d')
assert body.find_element_by_id(
'schedtotrans_frm_amount').get_attribute('value') == '11.11'
assert body.find_element_by_id(
Expand Down Expand Up @@ -1786,7 +1786,7 @@ def test_08_budget_transfer(self, base_url, selenium, testdb):
assert title.text == 'Budget Transfer'
assert body.find_element_by_id(
'budg_txfr_frm_date').get_attribute('value') == \
datetime.now().date().strftime('%Y-%m-%d')
dtnow().date().strftime('%Y-%m-%d')
amt = body.find_element_by_id('budg_txfr_frm_amount')
amt.clear()
amt.send_keys('123.45')
Expand Down Expand Up @@ -1862,7 +1862,7 @@ def test_08_budget_transfer(self, base_url, selenium, testdb):
def test_10_verify_db(self, testdb):
desc = 'Budget Transfer - 123.45 from Periodic2 (2) to Standing2 (5)'
t1 = testdb.query(Transaction).get(8)
assert t1.date == datetime.now().date()
assert t1.date == dtnow().date()
assert float(t1.actual_amount) == 123.45
assert float(t1.budgeted_amount) == 123.45
assert t1.description == desc
Expand All @@ -1876,7 +1876,7 @@ def test_10_verify_db(self, testdb):
assert rec1.ofx_account_id is None
assert rec1.note == desc
t2 = testdb.query(Transaction).get(9)
assert t2.date == datetime.now().date()
assert t2.date == dtnow().date()
assert float(t2.actual_amount) == -123.45
assert float(t2.budgeted_amount) == -123.45
assert t2.description == desc
Expand Down Expand Up @@ -2061,7 +2061,7 @@ def test_16_transaction_table(self, base_url, selenium, testdb):
'<a href="javascript:txnReconcileModal(2)">Yes (2)</a>'
],
[
datetime.now().date().strftime('%Y-%m-%d'),
dtnow().date().strftime('%Y-%m-%d'),
'$123.45',
'<a href="javascript:transModal(8, null);">'
'Budget Transfer - 123.45 from Periodic2 (2) to '
Expand All @@ -2072,7 +2072,7 @@ def test_16_transaction_table(self, base_url, selenium, testdb):
'<a href="javascript:txnReconcileModal(3)">Yes (3)</a>'
],
[
datetime.now().date().strftime('%Y-%m-%d'),
dtnow().date().strftime('%Y-%m-%d'),
'-$123.45',
'<a href="javascript:transModal(9, null);">'
'Budget Transfer - 123.45 from Periodic2 (2) to '
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ def test_2_modal_add(self, base_url, selenium):
assert title.text == 'Add New Transaction'
date_input = body.find_element_by_id('trans_frm_date')
assert date_input.get_attribute(
'value') == datetime.now().strftime('%Y-%m-%d')
'value') == dtnow().strftime('%Y-%m-%d')
# END date chooser popup
amt = body.find_element_by_id('trans_frm_amount')
amt.clear()
Expand Down Expand Up @@ -618,7 +618,7 @@ def test_3_verify_db(self, testdb):
t = testdb.query(Transaction).get(4)
assert t is not None
assert t.description == 'NewTrans4'
assert t.date == datetime.now().date()
assert t.date == dtnow().date()
assert float(t.actual_amount) == 345.67
assert t.budgeted_amount is None
assert t.account_id == 1
Expand Down

0 comments on commit 33f1a1d

Please sign in to comment.