From 33f1a1dbcc6c6a88fad33580dc6c2fa606d74b3a Mon Sep 17 00:00:00 2001 From: Jason Antman Date: Sun, 6 Aug 2017 17:12:04 -0400 Subject: [PATCH] issue #97 - replace all uses of datetime.now() in tests with dtnow() --- .../acceptance/flaskapp/views/test_budgets.py | 17 +++++++++-------- .../flaskapp/views/test_payperiods.py | 12 ++++++------ .../flaskapp/views/test_transactions.py | 4 ++-- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/biweeklybudget/tests/acceptance/flaskapp/views/test_budgets.py b/biweeklybudget/tests/acceptance/flaskapp/views/test_budgets.py index cf99871f..b39dbf74 100644 --- a/biweeklybudget/tests/acceptance/flaskapp/views/test_budgets.py +++ b/biweeklybudget/tests/acceptance/flaskapp/views/test_budgets.py @@ -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 @@ -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() @@ -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 @@ -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 @@ -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' @@ -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() @@ -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 @@ -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 @@ -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 diff --git a/biweeklybudget/tests/acceptance/flaskapp/views/test_payperiods.py b/biweeklybudget/tests/acceptance/flaskapp/views/test_payperiods.py index b730fc1e..b2efacd9 100644 --- a/biweeklybudget/tests/acceptance/flaskapp/views/test_payperiods.py +++ b/biweeklybudget/tests/acceptance/flaskapp/views/test_payperiods.py @@ -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( @@ -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') @@ -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 @@ -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 @@ -2061,7 +2061,7 @@ def test_16_transaction_table(self, base_url, selenium, testdb): 'Yes (2)' ], [ - datetime.now().date().strftime('%Y-%m-%d'), + dtnow().date().strftime('%Y-%m-%d'), '$123.45', '' 'Budget Transfer - 123.45 from Periodic2 (2) to ' @@ -2072,7 +2072,7 @@ def test_16_transaction_table(self, base_url, selenium, testdb): 'Yes (3)' ], [ - datetime.now().date().strftime('%Y-%m-%d'), + dtnow().date().strftime('%Y-%m-%d'), '-$123.45', '' 'Budget Transfer - 123.45 from Periodic2 (2) to ' diff --git a/biweeklybudget/tests/acceptance/flaskapp/views/test_transactions.py b/biweeklybudget/tests/acceptance/flaskapp/views/test_transactions.py index 6521a1a8..0e9975f7 100644 --- a/biweeklybudget/tests/acceptance/flaskapp/views/test_transactions.py +++ b/biweeklybudget/tests/acceptance/flaskapp/views/test_transactions.py @@ -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() @@ -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