Example #1
0
    def test_compare_dates_in_succession_with_later_date_as_first_and_consider_now_as_false(self):
        first_date = self.get_datetime('2/12/1950')
        later_date = self.get_datetime('3/12/1950')
        result = relate(first_date, later_date,
                           past='before', consider_now=False)
        expected_result = '1 day before'

        compare(result, expected_result)
Example #2
0
    def test_compare_dates_in_succession_with_later_date_as_first(self):
        first_date = self.get_datetime('2/12/1950')
        later_date = self.get_datetime('3/12/1950')
        past = 'day before'
        result = relate(first_date, later_date, past=past)
        expected_result = 'yesterday'

        compare(result, expected_result)
Example #3
0
    def test_compare_dates_in_succession(self):
        first_date = self.get_datetime('2/12/1950')
        later_date = self.get_datetime('3/12/1950')
        result = relate(later_date, first_date,
                           consider_now=False, future='after')
        expected_result = '1 day after'

        compare(result, expected_result)
Example #4
0
    def test_compare_same_date(self):
        first_date = self.get_datetime('2/12/2018')
        second_date = self.get_datetime('02/12/2018')
        result = relate(second_date,
                           first_date, consider_now=False)
        expected_result = 'same day'

        compare(result, expected_result)
Example #5
0
def query():
    """Load selenium and scrape"""
    browser = choice_browser.get('class', webdriver.Chrome)(**kwargs)
    browser.get(HOMEPAGE)

    try:
        # Wait until logout button is visible
        ui.WebDriverWait(browser, 3).until(
            conditions.visibility_of_element_located((By.ID, 'userLogoutBtn')))
        # browser.find_element_by_id('userLogoutBtn').click()
    except TimeoutException:
        # Login if logout button not visible
        login(browser)

    try:
        # Locate details table
        ui.WebDriverWait(browser, 15).until(
            conditions.visibility_of_element_located(
                (By.CLASS_NAME, 'table_main')))
    except TimeoutException:
        browser.close()
        sys.exit(1)
    else:
        table = browser.find_element_by_class_name('table_main')

    rows = table.find_elements_by_tag_name('tr')

    messages = []

    for row in rows[1:6]:
        message = ''
        tds = row.find_elements_by_tag_name('td')
        for td in tds:
            try:
                input = td.find_element_by_tag_name('input')
            except NoSuchElementException:
                text = td.text.strip()
                message += '{}'.format(text)
            else:
                text = input.get_attribute('value')
                message += ': {}\n'.format(text)
                try:
                    date = datetime.strptime(text, '%d-%m-%Y')
                except ValueError:
                    pass
                else:
                    message += relate(date,
                                      TODAY,
                                      future='to expiry',
                                      past='ago')

        messages.append(message)

    browser.close()

    pprint(messages)

    for message in messages:
        # Display notification
        alert(message)
        time.sleep(3)
Example #6
0
    def test_compare_date_after_today(self):
        second_date = self.now + timedelta(days=1)
        result = relate(second_date, self.now)
        expected_result = 'tomorrow'

        compare(result, expected_result)
Example #7
0
 def test_compare_current_date_with_default(self):
     result = relate(self.now)
     expected_result = 'today'
     compare(result, expected_result)