def test_lte(self): filter = DateFilter(Person.due_date) filter.set('lte', '12/31/2010') self.assert_filter_query(filter, "WHERE persons.due_date <= '2010-12-31'") eq_(filter.description, 'up to 12/31/2010') with assert_raises(formencode.Invalid): filter.set('lte', '')
def test_not_empty(self): filter = DateFilter(Person.due_date) filter.set('!empty', None) self.assert_filter_query(filter, "WHERE persons.due_date IS NOT NULL") eq_(filter.description, 'any date') filter.set('!empty', '') self.assert_filter_query(filter, "WHERE persons.due_date IS NOT NULL") eq_(filter.description, 'any date')
def test_empty(self): filter = DateFilter(Person.due_date) filter.set('empty', None) self.assert_filter_query(filter, "WHERE persons.due_date IS NULL") eq_(filter.description, 'date not specified') filter.set('empty', '') self.assert_filter_query(filter, "WHERE persons.due_date IS NULL") eq_(filter.description, 'date not specified')
def test_not_between_missing_date(self): filter = DateFilter(Person.due_date) filter.set('!between', '12/31/2010', '') today = dt.date.today().strftime('%Y-%m-%d') self.assert_filter_query( filter, "WHERE persons.due_date NOT BETWEEN '2010-12-31' AND '{}'".format(today) )
def test_this_year_default(self): filter = DateFilter(Person.due_date, _now=dt.date(2012, 2, 4), default_op='thisyear') filter.set(None, None) self.assert_filter_query( filter, "WHERE persons.due_date BETWEEN '2012-01-01' AND '2012-12-31'" ) eq_(filter.description, '01/01/2012 - 12/31/2012')
def test_less_than_days_ago(self): filter = DateFilter(Person.due_date, _now=dt.date(2012, 1, 1)) filter.set('ltda', '10') self.assert_filter_query( filter, "WHERE persons.due_date > '2011-12-22' AND persons.due_date < '2012-01-01'" ) eq_(filter.description, '12/22/2011 - 01/01/2012')
def test_not_between(self): filter = DateFilter(Person.due_date) filter.set('!between', '1/31/2010', '12/31/2010') self.assert_filter_query( filter, "WHERE persons.due_date NOT BETWEEN '2010-01-31' AND '2010-12-31'" ) eq_(filter.description, 'excluding 01/31/2010 - 12/31/2010')
def test_in_less_than_days(self): filter = DateFilter(Person.due_date, _now=dt.date(2012, 1, 1)) filter.set('iltd', '10') self.assert_filter_query( filter, "WHERE persons.due_date >= '2012-01-01' AND persons.due_date < '2012-01-11'" ) eq_(filter.description, '01/01/2012 - 01/11/2012')
def test_not_between_none_date(self): filter = DateFilter(Person.due_date) filter.set('!between', '12/31/2010') today = dt.date.today().strftime('%Y-%m-%d') self.assert_filter_query( filter, "WHERE persons.due_date NOT BETWEEN '2010-12-31' AND '{}'".format(today) ) with assert_raises(formencode.Invalid): filter.set('!between', None) eq_(filter.error, True) eq_(filter.description, 'invalid')
def test_today(self): filter = DateFilter(Person.due_date, _now=dt.date(2012, 1, 1)) filter.set('today', None) self.assert_filter_query(filter, "WHERE persons.due_date = '2012-01-01'") eq_(filter.description, '01/01/2012')
def test_more_than_days_ago(self): filter = DateFilter(Person.due_date, _now=dt.date(2012, 1, 1)) filter.set('mtda', '10') self.assert_filter_query(filter, "WHERE persons.due_date < '2011-12-22'") eq_(filter.description, 'before 12/22/2011')
def test_between_blank(self): filter = DateFilter(Person.due_date) with assert_raises(formencode.Invalid): filter.set('between', '', '') eq_(filter.error, True) eq_(filter.description, 'invalid')
def test_gte(self): filter = DateFilter(Person.due_date) filter.set('gte', '12/31/2010') self.assert_filter_query(filter, "WHERE persons.due_date >= '2010-12-31'") eq_(filter.description, 'beginning 12/31/2010')
def test_in_more_than_days(self): filter = DateFilter(Person.due_date, _now=dt.date(2012, 1, 1)) filter.set('imtd', '10') self.assert_filter_query(filter, "WHERE persons.due_date > '2012-01-11'") eq_(filter.description, 'after 01/11/2012')
def test_in_days_empty_value2(self): filter = DateFilter(Person.due_date, _now=dt.date(2012, 1, 1)) filter.set('ind', '10', '') self.assert_filter_query(filter, "WHERE persons.due_date = '2012-01-11'")
def test_days_operator_with_invalid_value(self): filter = DateFilter(Person.due_date, _now=dt.date(2012, 1, 1)) filter.set('ind', 'a')
def test_int_filter_process(self): filter = DateFilter(Person.due_date, _now=dt.date(2012, 2, 29)) filter.set('ltda', '1', '') eq_(filter.error, False)
def test_days_ago_overflow(self): filter = DateFilter(Person.due_date, _now=dt.date(2012, 1, 1)) filter.set('da', '10142015')
def test_this_month_left_edge(self): filter = DateFilter(Person.due_date, _now=dt.date(2012, 1, 1)) filter.set('thismonth', None) self.assert_filter_query(filter, self.between_sql) eq_(filter.description, '01/01/2012 - 01/31/2012')
def test_this_week_right_edge(self): filter = DateFilter(Person.due_date, _now=dt.date(2012, 1, 7)) filter.set('thisweek', None) self.assert_filter_query(filter, self.between_week_sql) eq_(filter.description, '01/01/2012 - 01/07/2012')
def test_last_month_right_edge(self): filter = DateFilter(Person.due_date, _now=dt.date(2012, 2, 29)) filter.set('lastmonth', None) self.assert_filter_query(filter, self.between_sql) eq_(filter.description, '01/01/2012 - 01/31/2012')
def test_selmonth(self): filter = DateFilter(Person.due_date, _now=dt.date(2012, 2, 4)) filter.set('selmonth', 1, 2012) self.assert_filter_query(filter, self.between_sql) eq_(filter.description, 'Jan 2012')
def test_bad_date(self): filter = DateFilter(Person.due_date) with assert_raises(formencode.Invalid): filter.set('eq', '1/1/2015 - 8/31/2015') eq_(filter.error, True) eq_(filter.description, 'invalid')
def test_in_days_overflow(self): filter = DateFilter(Person.due_date, _now=dt.date(2012, 1, 1)) filter.set('ind', '10000000')
def test_invalid_date(self): filter = DateFilter(Person.due_date) filter.set('eq', '7/45/2007')
def test_default(self): filter = DateFilter(Person.due_date, default_op='between', default_value1='1/31/2010', default_value2='12/31/2010') filter.set(None, None) self.assert_filter_query(filter, "WHERE persons.due_date BETWEEN '2010-01-31' AND '2010-12-31'")
def test_not_eq(self): filter = DateFilter(Person.due_date) filter.set('!eq', '12/31/2010') self.assert_filter_query(filter, "WHERE persons.due_date != '2010-12-31'") eq_(filter.description, 'excluding 12/31/2010')