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(self): self.driver.get(self.live_server_url) welcome_page = WelcomePage(self.driver) welcome_page.login_user(email='*****@*****.**', password='******') today = datetime.date.today() yesterday = today - datetime.timedelta(days=1) tomorrow = today + datetime.timedelta(days=1) day_before_yesterday = yesterday - datetime.timedelta(days=1) self.create_transaction(yesterday, 1, 'a') self.create_transaction(today, 2, 'b') self.create_transaction(tomorrow, 3, 'c') transactions = self.get_transactions() t = transactions[1] t.delete() transactions = self.get_transactions() t = transactions[0] self.assertEqual(t.description, 'a') self.assertEqual(t.date, yesterday) self.assertEqual(t.size, 1) self.assertEqual(t.balance, '£1.00') t = transactions[1] self.assertEqual(t.description, 'c') self.assertEqual(t.date, tomorrow) self.assertEqual(t.size, 3) self.assertEqual(t.balance, '£4.00')
def setUp(self): super().setUp() self.create_user(email='*****@*****.**', password='******') self.driver.get(self.live_server_url) welcome_page = WelcomePage(self.driver) welcome_page.login_user(email='*****@*****.**', password='******')
def test_monthly_transactions(self): start = datetime.date(2018, 4, 1) end = datetime.date(2018, 7, 1) self.driver.get(self.live_server_url) welcome_page = WelcomePage(self.driver) welcome_page.login_user('*****@*****.**', 'password') self.driver.get('{}/home?start=2018-04-01&end=2018-08-01'.format( self.live_server_url)) homepage = HomePage(self.driver) transaction_form = homepage.transaction_form transaction_form.date = start transaction_form.transaction_size = -10 transaction_form.description = 'phone contract' transaction_form.repeat_checkbox.click() repeat_options = transaction_form.repeat_options repeat_options.select('ends_on_date') repeat_options.set_frequency('monthly') import time time.sleep(10) repeat_options.set_end_date(end) time.sleep(10) repeat_options.submit() homepage = HomePage(self.driver) transactions = homepage.transaction_list.get_transactions() self.assertEqual(len(transactions), 4) t = transactions[0] self.assertEqual(t.date, start) self.assertEqual(t.size, -10) self.assertEqual(t.description, 'phone contract') self.assertEqual(t.balance, '£-10.00') t = transactions[1] self.assertEqual(t.date, datetime.date(2018, 5, 1)) self.assertEqual(t.size, -10) self.assertEqual(t.description, 'phone contract') self.assertEqual(t.balance, '£-20.00') t = transactions[2] self.assertEqual(t.date, datetime.date(2018, 6, 1)) self.assertEqual(t.size, -10) self.assertEqual(t.description, 'phone contract') self.assertEqual(t.balance, '£-30.00') t = transactions[3] self.assertEqual(t.date, datetime.date(2018, 7, 1)) self.assertEqual(t.size, -10) self.assertEqual(t.description, 'phone contract') self.assertEqual(t.balance, '£-40.00')
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(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_never_ends(self): today = datetime.date.today() self.driver.get(self.live_server_url) welcome_page = WelcomePage(self.driver) welcome_page.login_user('*****@*****.**', 'password') homepage = HomePage(self.driver) transaction_form = homepage.transaction_form transaction_form.date = today transaction_form.transaction_size = -10 transaction_form.description = 'phone contract' transaction_form.repeat_checkbox.click() repeat_options = transaction_form.repeat_options repeat_options.submit() homepage = HomePage(self.driver) transactions = homepage.transaction_list.get_transactions() # self.assertEqual(len(transactions), 3) # TODO: more dynamic test, maybe get date range and calculate how many transactions # should be in there t = transactions[0] self.assertEqual(t.date, today) self.assertEqual(t.size, -10) self.assertEqual(t.description, 'phone contract') self.assertEqual(t.balance, '£-10.00') t = transactions[1] self.assertEqual(t.date, today + datetime.timedelta(days=7)) self.assertEqual(t.size, -10) self.assertEqual(t.description, 'phone contract') self.assertEqual(t.balance, '£-20.00') t = transactions[2] self.assertEqual(t.date, today + datetime.timedelta(days=14)) self.assertEqual(t.size, -10) self.assertEqual(t.description, 'phone contract') self.assertEqual(t.balance, '£-30.00')
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): today = datetime.date.today() self.driver.get(self.live_server_url) welcome_page = WelcomePage(self.driver) welcome_page.login_user('*****@*****.**', 'password') homepage = HomePage(self.driver) transaction_form = homepage.transaction_form transaction_form.date = today transaction_form.transaction_size = -10 transaction_form.description = 'phone contract' transaction_form.repeat_checkbox.click() transaction_form.repeat_options.submit() homepage = HomePage(self.driver) transactions = homepage.transaction_list.get_transactions() # self.assertEqual(len(transactions), 3) # TODO: check number of transactions for date range t = transactions[0] self.assertEqual(t.date, today) self.assertEqual(t.size, -10) self.assertEqual(t.description, 'phone contract') self.assertEqual(t.balance, '£-10.00') t = transactions[1] self.assertEqual(t.date, today + datetime.timedelta(days=7)) self.assertEqual(t.size, -10) self.assertEqual(t.description, 'phone contract') self.assertEqual(t.balance, '£-20.00') t = transactions[2] self.assertEqual(t.date, today + datetime.timedelta(days=14)) self.assertEqual(t.size, -10) self.assertEqual(t.description, 'phone contract') self.assertEqual(t.balance, '£-30.00')
def test_ends_after_2_occurrences(self): today = datetime.date.today() self.driver.get(self.live_server_url) welcome_page = WelcomePage(self.driver) welcome_page.login_user('*****@*****.**', 'password') homepage = HomePage(self.driver) transaction_form = homepage.transaction_form transaction_form.date = today transaction_form.transaction_size = -10 transaction_form.description = 'phone contract' transaction_form.repeat_checkbox.click() repeat_options = transaction_form.repeat_options repeat_options.select('ends_after_#_transactions') repeat_options.set_n_transactions(2) repeat_options.submit() homepage = HomePage(self.driver) transactions = homepage.transaction_list.get_transactions() self.assertEqual(len(transactions), 2) t = transactions[0] self.assertEqual(t.date, today) self.assertEqual(t.size, -10) self.assertEqual(t.description, 'phone contract') self.assertEqual(t.balance, '£-10.00') t = transactions[1] self.assertEqual(t.date, today + datetime.timedelta(days=7)) self.assertEqual(t.size, -10) self.assertEqual(t.description, 'phone contract') self.assertEqual(t.balance, '£-20.00')
def test(self): self.driver.get(self.live_server_url) welcome_page = WelcomePage(self.driver) welcome_page.login_user(email='*****@*****.**', password='******') homepage = HomePage(self.driver) today = datetime.date.today() self.assertEqual( homepage.transaction_form.date_input.get_attribute('value'), today.isoformat()) self.create_transaction(today, 1000, 'pay day') transactions = self.get_transactions() self.assertEqual(len(transactions), 1) t = transactions[0] self.assertEqual(t.date, today) self.assertEqual(t.size, 1000) self.assertEqual(t.description, 'pay day') self.assertEqual(t.balance, '£1,000.00') homepage = HomePage(self.driver) balance_chart = homepage.balance_chart bars = balance_chart.bars self.assertEqual(len(bars), 84) bar_today = bars[41] self.assertEqual(bar_today.date, today) self.assertEqual(bars[0].date, today - datetime.timedelta(days=41)) self.assertEqual(bars[-1].date, today + datetime.timedelta(days=42)) self.assertEqual(bar_today.balance, 1000) self.assertEqual(bars[0].balance, 0) self.assertEqual(bars[-1].balance, 1000) y_ticks = balance_chart.y_ticks for tick in y_ticks: number_int = int( tick.replace('£', '').replace(',', '').replace('.', '')) number_float = float( tick.replace('£', '').replace(',', '').replace('.', '')) self.assertTrue(tick.startswith('£')) self.assertEqual(number_int, number_float) # int numbers only ## creates another transaction before the first ## transaction - check balances calculted properly yesterday = today - datetime.timedelta(days=1) self.create_transaction(yesterday, 500, 'dividends received') transactions = self.get_transactions() self.assertEqual(len(transactions), 2) t = transactions[0] self.assertEqual(t.date, yesterday) self.assertEqual(t.size, 500) self.assertEqual(t.description, 'dividends received') self.assertEqual(t.balance, '£500.00') t = transactions[1] self.assertEqual(t.date, today) self.assertEqual(t.size, 1000) self.assertEqual(t.description, 'pay day') self.assertEqual(t.balance, '£1,500.00') # test modifying existing transactions t = transactions[1] tomorrow = today + datetime.timedelta(days=1) t.date = tomorrow t.save() transactions = self.get_transactions() self.assertEqual(len(transactions), 2) t = transactions[1] self.assertEqual(t.date, tomorrow) self.assertEqual(t.size, 1000) self.assertEqual(t.description, 'pay day') self.assertEqual(t.balance, '£1,500.00') # add test for when transaction gets updated to before a previous transaction, will need to recalculate the closing balance # set the latter transaction to happening before the first t = transactions[1] day_before_yesterday = yesterday - datetime.timedelta(days=1) t.date = day_before_yesterday t.save() homepage = HomePage(self.driver) transaction_list = homepage.transaction_list transactions = transaction_list.get_transactions() self.assertEqual(len(transactions), 2) t = transactions[0] self.assertEqual(t.date, day_before_yesterday) self.assertEqual(t.size, 1000) self.assertEqual(t.description, 'pay day') self.assertEqual(t.balance, '£1,000.00') t = transactions[1] self.assertEqual(t.date, yesterday) self.assertEqual(t.size, 500) self.assertEqual(t.description, 'dividends received') self.assertEqual(t.balance, '£1,500.00') # change transaction size t = transactions[0] t.size = 2000 t.save() transactions = self.get_transactions() self.assertEqual(len(transactions), 2) t = transactions[0] self.assertEqual(t.date, day_before_yesterday) self.assertEqual(t.size, 2000) self.assertEqual(t.description, 'pay day') self.assertEqual(t.balance, '£2,000.00') t = transactions[1] self.assertEqual(t.date, yesterday) self.assertEqual(t.size, 500) self.assertEqual(t.description, 'dividends received') self.assertEqual(t.balance, '£2,500.00')
def sign_in(self, email, password): url = '{}{}'.format(self.live_server_url, WelcomePage.url) self.driver.get(url) welcome_page = WelcomePage(self.driver) welcome_page.login_user(email, password)