Example #1
0
 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', '')
Example #2
0
 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', '')
Example #3
0
 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')
Example #4
0
 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')
Example #5
0
 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)
     )
Example #6
0
 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')
Example #7
0
 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)
     )
Example #8
0
 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')
Example #9
0
 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')
Example #10
0
 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')
Example #11
0
 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')
Example #12
0
 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')
Example #13
0
 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')
Example #14
0
 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')
Example #15
0
 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')
Example #16
0
 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')
Example #17
0
    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')
Example #18
0
    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')
Example #19
0
 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')
Example #20
0
 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')
Example #21
0
 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')
Example #22
0
 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')
Example #23
0
 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')
Example #24
0
 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')
Example #25
0
 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')
Example #26
0
 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'")
Example #27
0
 def test_days_operator_with_invalid_value(self):
     filter = DateFilter(Person.due_date, _now=dt.date(2012, 1, 1))
     filter.set('ind', 'a')
Example #28
0
 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)
Example #29
0
 def test_days_ago_overflow(self):
     filter = DateFilter(Person.due_date, _now=dt.date(2012, 1, 1))
     filter.set('da', '10142015')
Example #30
0
 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')
Example #31
0
 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')
Example #32
0
 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')
Example #33
0
 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')
Example #34
0
 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')
Example #35
0
 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')
Example #36
0
 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)
Example #37
0
 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')
Example #38
0
 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')
Example #39
0
 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')
Example #40
0
 def test_days_ago_overflow(self):
     filter = DateFilter(Person.due_date, _now=dt.date(2012, 1, 1))
     filter.set('da', '10142015')
Example #41
0
 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')
Example #42
0
 def test_in_days_overflow(self):
     filter = DateFilter(Person.due_date, _now=dt.date(2012, 1, 1))
     filter.set('ind', '10000000')
Example #43
0
 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')
Example #44
0
 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'")
Example #45
0
 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')
Example #46
0
 def test_invalid_date(self):
     filter = DateFilter(Person.due_date)
     filter.set('eq', '7/45/2007')
Example #47
0
 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')
Example #48
0
 def test_days_operator_with_invalid_value(self):
     filter = DateFilter(Person.due_date, _now=dt.date(2012, 1, 1))
     filter.set('ind', 'a')
Example #49
0
 def test_in_days_overflow(self):
     filter = DateFilter(Person.due_date, _now=dt.date(2012, 1, 1))
     filter.set('ind', '10000000')
Example #50
0
 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'")
Example #51
0
 def test_invalid_date(self):
     filter = DateFilter(Person.due_date)
     filter.set('eq', '7/45/2007')
Example #52
0
 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')
Example #53
0
 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'")
Example #54
0
 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')