def setUp(self): super().setUp() url = '{}/home?start=2018-01-01&end=2018-01-22'.format(self.live_server_url) self.driver.get(url) home_page = HomePage(self.driver) home_page.create_transaction( date=dt.date(2018, 1, 1), size=1, description='a', repeats='weekly', ends={'how': 'never_ends'}) home_page.show_repeat_transactions_view() repeat_transactions = home_page.get_repeat_transactions() self.assertEqual(len(repeat_transactions), 1) rt = repeat_transactions[0] self.assertEqual(rt.start_date, dt.date(2018, 1, 1)) self.assertEqual(rt.size, 1) self.assertEqual(rt.description, 'a') self.assertEqual(rt.frequency, 'weekly') self.assertEqual(rt.ends, 'never') self.repeat_transaction = rt self.home_page = home_page
def test(self): self.driver.get(self.live_server_url) welcome_page = WelcomePage(self.driver) welcome_page.login_user('*****@*****.**', 'password') start=datetime.date(2018, 1, 1) end=datetime.date(2018, 1, 15) url = '{}/home?start={}&end={}'.format(self.live_server_url, start, end) self.driver.get(url) homepage = HomePage(self.driver) homepage.create_transaction( description='a', ends={'how': 'never_ends'}, size=10, date=datetime.date(2018, 1, 1), steps=2, repeats='weekly', ) homepage.reload() df_balances = homepage.get_balances() transactions = homepage.get_transactions() dates = pd.date_range(datetime.date(2018, 1, 1), datetime.date(2018, 1, 15)) values = [10.0 for i in range(14)] + [20.0] df_expected = pd.DataFrame({'balance': values, 'date': dates}) df_expected = df_expected.set_index('date') df_expected.index = pd.to_datetime(df_expected.index) self.assertTrue(df_balances.equals(df_expected), (df_balances, df_expected))
def test_updates_future_transactions(self): self.driver.get(self.live_server_url) welcome_page = WelcomePage(self.driver) welcome_page.login_user('*****@*****.**', 'password') start = datetime.date(2018, 1, 1) end = datetime.date(2018, 1, 15) homepage = HomePage(self.driver, self.live_server_url, start, end) homepage.create_transaction(date=datetime.date(2018, 1, 7), size=1, description='a') homepage = homepage.reload() homepage.create_transaction(date=datetime.date(2018, 1, 1), size=2, description='b', repeats='weekly', ends={'how': 'never_ends'}) balances = homepage.get_balances() transactions = homepage.get_transactions() dates = pd.date_range(datetime.date(2018, 1, 1), datetime.date(2018, 1, 15)) values = [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 3.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 7.0 ] balances_expected = pd.DataFrame({'date': dates, 'balance': values}) balances_expected = balances_expected.set_index('date') self.assertTrue(balances.equals(balances_expected), (balances, balances_expected)) values = [(t.date, t.size, t.description, t.balance) for t in transactions] transactions = pd.DataFrame( values, columns=['date', 'size', 'description', 'closing_balance']) transactions_expected = [ (datetime.date(2018, 1, 1), 2.0, 'b', '£2.00'), (datetime.date(2018, 1, 7), 1.0, 'a', '£3.00'), (datetime.date(2018, 1, 8), 2.0, 'b', '£5.00'), (datetime.date(2018, 1, 15), 2.0, 'b', '£7.00') ] transactions_expected = pd.DataFrame( transactions_expected, columns=['date', 'size', 'description', 'closing_balance']) self.assertTrue(transactions.equals(transactions_expected), (transactions, transactions_expected))
def test_this_transaction_only_deletion(self): home_page = HomePage(self.driver) home_page.create_transaction(date=dt.date(2018, 1, 1), size=10, description='a', repeats='weekly', ends={'how': 'never_ends'}) home_page.create_transaction(date=dt.date(2018, 1, 9), size=5, description='b') url = '{}/home?start={}&end={}'.format(self.live_server_url, '2018-01-01', '2018-01-15') self.driver.get(url) home_page = HomePage(self.driver) t_list = home_page.transaction_list transactions = t_list.get_transactions() t = transactions[1] t.delete() ### WebDriverWait(self.driver, 5).until( EC.visibility_of_element_located( (By.ID, 'repeat-transaction-deletion-prompt'))) prompt = RepeatTransactionDeletionPrompt(self.driver) prompt.select('delete_only_this_transaction') prompt.submit() ### put this in the transaction class self.driver.get(url) home_page = HomePage(self.driver) t_list = home_page.transaction_list transactions = t_list.get_transactions() self.assertEqual(len(transactions), 3) t = transactions[0] self.assertEqual(t.date, dt.date(2018, 1, 1)) t = transactions[1] self.assertEqual(t.date, dt.date(2018, 1, 9)) self.assertEqual('£15.00', t.balance) t = transactions[2] self.assertEqual(t.date, dt.date(2018, 1, 15)) self.assertEqual('£25.00', t.balance)
def test(self): self.driver.get(self.live_server_url) welcome_page = WelcomePage(self.driver) welcome_page.login_user(email="*****@*****.**", password="******") today = datetime.date.today() last_month = today - datetime.timedelta(days=41) homepage = HomePage(self.driver) homepage.create_transaction(date=last_month, size=100, description='a', update=True) homepage.create_transaction(date=today, size=-50, description='b', update=True) balance_chart = homepage.balance_chart self.assertEqual(balance_chart.bars[0].balance, 100) self.assertEqual( balance_chart.bars[len(balance_chart.bars) // 2].balance, 50) date_selector = homepage.date_selector self.assertEqual(date_selector.start, today - datetime.timedelta(days=41)) self.assertEqual(date_selector.end, today + datetime.timedelta(days=42)) date_selector.start = last_month date_selector.end = last_month + datetime.timedelta(days=7) date_selector.submit() homepage = HomePage(self.driver) balance_chart = homepage.balance_chart self.assertEqual(len(balance_chart.bars), 8) self.assertEqual(balance_chart.bars[0].balance, 100) self.assertEqual(balance_chart.bars[0].date, last_month) self.assertEqual(balance_chart.bars[7].balance, 100) self.assertEqual(balance_chart.bars[7].date, last_month + datetime.timedelta(days=7))
def test(self): home_page = HomePage(self.driver) home_page.create_transaction(date=dt.date(2018, 1, 1), size=10, description='a', repeats='weekly', ends={'how': 'never_ends'}) home_page.show_repeat_transactions_view() repeat_transaction = { 'date': dt.date(2018, 1, 1), 'size': 10, 'description': 'a', 'repeats': 'weekly', 'ends': '' } self.assertIn(repeat_transaction, home_page.repeat_transactions_list.items)
def test(self): self.driver.get(self.live_server_url) welcome_page = WelcomePage(self.driver) welcome_page.login_user(email="*****@*****.**", password="******") today = datetime.date.today() homepage = HomePage(self.driver) homepage.create_transaction(date=today, size=10, description='a', update=True) week_forward_button = self.driver.find_element_by_id( 'week-forward-button') week_backward_button = self.driver.find_element_by_id( 'week-backward-button') date_range = homepage.get_date_range() homepage.move_date_range_forward(days=7) WebDriverWait(self.driver, timeout=2).until(lambda b: homepage.get_date_range() == [ today - datetime.timedelta(days=34), today + datetime .timedelta(days=49) ]) date_range = homepage.get_date_range() homepage.move_date_range_backward(days=7) WebDriverWait(self.driver, timeout=2).until(lambda b: homepage.get_date_range() == [ date_range[0] - datetime.timedelta(days=7), date_range[1] - datetime.timedelta(days=7) ]) date_range = homepage.get_date_range() homepage.move_date_range_backward(days=7) WebDriverWait(self.driver, timeout=2).until(lambda b: homepage.get_date_range() == [ date_range[0] - datetime.timedelta(days=7), date_range[1] - datetime.timedelta(days=7) ])
def test(self): url = '{}/home?start=2018-01-01&end=2018-01-22'.format(self.live_server_url) self.driver.get(url) home_page = HomePage(self.driver) home_page.create_transaction( date=dt.date(2018, 1, 1), size=1000, description='a', repeats='weekly', ends={'how': 'ends_after_#_transactions', 'when': 2}) home_page.show_repeat_transactions_view() repeat_transactions = home_page.get_repeat_transactions() self.assertEqual(len(repeat_transactions), 1) rt = repeat_transactions[0] self.assertEqual(rt.start_date, dt.date(2018, 1, 1)) self.assertEqual(rt.size, 1000) self.assertEqual(rt.description, 'a') self.assertEqual(rt.frequency, 'weekly') self.assertEqual(rt.ends, dt.date(2018, 1, 8)) # change date rt.ends = dt.date(2018, 1, 15) import time time.sleep(15) rt.save() home_page.reload() expected = [ (dt.date(2018, 1, 1), 1000, 'a', '£1,000.00'), (dt.date(2018, 1, 8), 1000, 'a', '£2,000.00'), (dt.date(2018, 1, 15), 1000, 'a', '£3,000.00'), ] check_transactions(self, home_page, expected)
def test_update_repeat_transaction_description_only_all_transactions(self): url = '{}/home?start={}&end={}'.format(self.live_server_url, '2018-01-01', '2018-01-15') self.driver.get(url) home_page = HomePage(self.driver) home_page.create_transaction(date=dt.date(2018, 1, 1), size=10, description='a', repeats='weekly', ends={'how': 'never_ends'}) home_page.create_transaction(date=dt.date(2018, 1, 9), size=5, description='b') home_page = HomePage(self.driver) t_list = home_page.transaction_list transactions = t_list.get_transactions() self.assertEqual(len(transactions), 4) t = transactions[0] self.assertEqual(t.date, dt.date(2018, 1, 1)) self.assertEqual(t.description, 'a') t = transactions[1] self.assertEqual(t.date, dt.date(2018, 1, 8)) self.assertEqual(t.description, 'a') t = transactions[1] t.description = 'c' t.save() WebDriverWait(self.driver, 5).until( EC.visibility_of_element_located( (By.ID, 'repeat-transaction-update-prompt'))) prompt = RepeatTransactionUpdatePrompt(self.driver) prompt.select('update_all_transactions_of_this_kind') prompt.submit() home_page = HomePage(self.driver) t_list = home_page.transaction_list transactions = t_list.get_transactions() self.assertEqual(len(transactions), 4) t = transactions[0] self.assertEqual(t.date, dt.date(2018, 1, 1)) self.assertEqual('c', t.description) t = transactions[1] self.assertEqual(t.date, dt.date(2018, 1, 8)) self.assertEqual('c', t.description) t = transactions[2] self.assertEqual(t.date, dt.date(2018, 1, 9)) self.assertEqual('b', t.description) t = transactions[3] self.assertEqual(t.date, dt.date(2018, 1, 15)) self.assertEqual('c', t.description) self.assertEqual('£35.00', t.balance) url = '{}/home?start={}&end={}'.format(self.live_server_url, '2018-01-01', '2018-01-22') self.driver.get(url) home_page = HomePage(self.driver) t_list = home_page.transaction_list transactions = t_list.get_transactions() self.assertEqual(len(transactions), 5) t = transactions[4] self.assertEqual(t.date, dt.date(2018, 1, 22)) self.assertEqual('c', t.description) self.assertEqual('£45.00', t.balance)
def test_date_and_description_changed(self): home_page = HomePage(self.driver) home_page.create_transaction(date=dt.date(2018, 1, 1), size=10, description='a', repeats='weekly', ends={'how': 'never_ends'}) home_page.create_transaction(date=dt.date(2018, 1, 9), size=5, description='b') url = '{}/home?start={}&end={}'.format(self.live_server_url, '2018-01-01', '2018-01-15') self.driver.get(url) home_page = HomePage(self.driver) t_list = home_page.transaction_list transactions = t_list.get_transactions() self.assertEqual(len(transactions), 4) t = transactions[0] self.assertEqual(t.date, dt.date(2018, 1, 1)) self.assertEqual(t.description, 'a') t = transactions[1] self.assertEqual(t.date, dt.date(2018, 1, 8)) self.assertEqual(t.description, 'a') t = transactions[1] t.date = dt.date(2018, 1, 7) t.description = 'c' t.save() self.driver.get(url) home_page = HomePage(self.driver) t_list = home_page.transaction_list transactions = t_list.get_transactions() self.assertEqual(len(transactions), 4) t = transactions[0] self.assertEqual(t.date, dt.date(2018, 1, 1)) self.assertEqual(t.description, 'a') self.assertEqual('£10.00', t.balance) t = transactions[1] self.assertEqual(t.date, dt.date(2018, 1, 7)) self.assertEqual(t.description, 'c') self.assertEqual('£20.00', t.balance) t = transactions[2] self.assertEqual(t.date, dt.date(2018, 1, 9)) self.assertEqual('£25.00', t.balance) self.assertEqual(t.description, 'b') t = transactions[3] self.assertEqual(t.date, dt.date(2018, 1, 15)) self.assertEqual('£35.00', t.balance) self.assertEqual(t.description, 'a')
def test_deletion_of_all_transactions_of_this_type(self): url = '{}/home?start={}&end={}'.format(self.live_server_url, '2018-01-01', '2018-01-15') self.driver.get(url) home_page = HomePage(self.driver) home_page.create_transaction(date=dt.date(2018, 1, 1), size=10, description='a', repeats='weekly', ends={'how': 'never_ends'}) home_page.create_transaction(date=dt.date(2018, 1, 9), size=5, description='b') url = '{}/home?start={}&end={}'.format(self.live_server_url, '2018-01-01', '2018-01-15') self.driver.get(url) home_page = HomePage(self.driver) t_list = home_page.transaction_list transactions = t_list.get_transactions() t = transactions[1] t.delete() WebDriverWait(self.driver, 20).until( EC.visibility_of_element_located( (By.ID, 'repeat-transaction-deletion-prompt'))) prompt = RepeatTransactionDeletionPrompt(self.driver) prompt.select('all_transactions_of_this_type') prompt.submit() self.driver.get(url) home_page = HomePage(self.driver) t_list = home_page.transaction_list transactions = t_list.get_transactions() self.assertEqual(len(transactions), 1) t = transactions[0] self.assertEqual(t.date, dt.date(2018, 1, 9)) self.assertEqual(t.description, 'b') self.assertEqual('£5.00', t.balance) url = '{}/home?start={}&end={}'.format(self.live_server_url, '2018-01-01', '2018-01-22') self.driver.get(url) home_page = HomePage(self.driver) t_list = home_page.transaction_list transactions = t_list.get_transactions() self.assertEqual(len(transactions), 1) t = transactions[0] self.assertEqual(t.date, dt.date(2018, 1, 9)) self.assertEqual('£5.00', t.balance) rts = home_page.get_repeat_transactions() self.assertEqual(len(rts), 0)