def get_transactions(self, pending=False): if pending: self.t.find_button('Pending Charges').click() else: self.t.find_button('Posted Transactions').click() dates = [ parser.parse(' '.join([x.text for x in xs])).isoformat() for xs in zip( self.t.browser.driver.find_elements_by_xpath( '//*[contains(@class, "estmt-date")]'), self.t.browser.driver.find_elements_by_xpath( '//*[contains(@class, "estmt-month")]'), self.t.browser.driver.find_elements_by_xpath( '//*[contains(@class, "estmt-year")]')) ] descs = [ x.text for x in self.t.browser.driver.find_elements_by_xpath( '//*[contains(@class, "desc-trans")]') ] amounts = [ utils.parse_dols(x.text) for x in self.t.browser.driver.find_elements_by_xpath( '//*[contains(@class, "colAmount")]') ] return [ Transaction(dt, desc, '', amt, not pending) for dt, desc, amt in zip(dates, descs, amounts) if amt > 0 ]
def test_repr_instance(): """ Given __repr__(), an expression is created that can be used to recreate object. """ trans_two = Transaction(500, dt.datetime(2018, 1, 10)) trans_three = trans_two #recreate trans_two instance as trans_three directly using __repr__() assert trans_two == trans_three
def get_transactions(self, pending=False): f = self.t.browser.driver.find_elements_by_xpath if pending: el = self.t.find_el_xp('//span[contains(text(), "Pending Transactions")]') if el.text == 'View Pending Transactions': el.click() dates_xp = '//*[@id="pendingTransactionTable"]//div[contains(@class, "date")]' names_xp = '//*[@id="pendingTransactionTable"]//div[contains(@class, "merchant")]' amnts_xp = '//*[@id="pendingTransactionTable"]//div[contains(@class, "amount")]' else: dates_xp = '//*[@id="postedTransactionTable"]//div[contains(@class, "date")]/span' names_xp = '//*[@id="postedTransactionTable"]//div[contains(@class, "merchant")]' amnts_xp = '//*[@id="postedTransactionTable"]//div[contains(@class, "amount")]' amounts = [None] while amounts and any(a == None for a in amounts): dates = [parser.parse(x.text).isoformat() for x in f(dates_xp)] names = [x.text for x in f(names_xp)] # txtype = [x.text for x in f(pend + '/div[3]')] amounts = [utils.parse_dols(x.text) for x in f(amnts_xp)] return [ Transaction(tdate, desc, '', amt, not pending,) for tdate, desc, amt in zip(dates, names, amounts) ]
def test_default_timestamp_now(): """ Given no user input defined for timestamp, the default current timestamp now() is used when the Transaction object is created. The now() value should very similar or the same. """ now = dt.datetime.now() trans_one = Transaction(100) assert trans_one.timestamp >= now
def test_userdefined_timestamp(): """ Given a user defined input for timestamp, the default current timestamp now() is not used when the Transaction object is created. The user defined timestamp is bound to the Transaction object using self.timestamp = timestamp. """ arg_timestamp = dt.datetime(2018, 1, 10) trans_one = Transaction(100, arg_timestamp) assert trans_one.timestamp == arg_timestamp
def get_transactions(self, pending=False): f = self.t.browser.driver.find_elements_by_xpath tbl = 'Pending' if pending else 'Posted' pend = '//*[@id="%s"]/table[contains(@class, "card-activity")]/tbody/tr/' % tbl tdates = [x.text for x in f(pend + '/td[2]')] # pdates = [x.text for x in f(pend + '/td[3]')] # types = [x.text for x in f(pend + '/td[4]')] descs = [x.text for x in f(pend + '/td[5]')] amounts = [utils.parse_dols(x.text) for x in f(pend + '/td[7]')] return [ Transaction( tdate, desc, '', amount, not pending, ) for tdate, desc, amount in zip(tdates, descs, amounts) ]
def test_str_instance(): """ Given __str__(), a string respresentation of the object can be created. """ trans_one = Transaction(500, dt.datetime(2018, 1, 10)) assert str(trans_one) == '2018-01-10: +$500.00'