def test_arrow_support_eq(self): filter = DateTimeFilter(ArrowRecord.created_utc) filter.set('eq', '12/31/2010') self.assert_filter_query( filter, "WHERE arrow_records.created_utc BETWEEN '2010-12-31 00:00:00.000000' " "AND '2010-12-31 23:59:59.999999'")
def test_days_ago(self): filter = DateTimeFilter(Person.createdts, _now=dt.date(2012, 1, 1)) filter.set('da', '10') self.assert_filter_query( filter, "WHERE persons.createdts BETWEEN '2011-12-22 00:00:00.000000' AND " "'2011-12-22 23:59:59.999999'")
def test_in_less_than_days(self): filter = DateTimeFilter(Person.createdts, _now=dt.datetime(2012, 1, 1, 12, 35)) filter.set('iltd', '10') self.assert_filter_query( filter, "WHERE persons.createdts >= '2012-01-01 12:35:00.000000' AND " "persons.createdts < '2012-01-11 00:00:00.000000'")
def test_less_than_days_ago(self): filter = DateTimeFilter(Person.createdts, _now=dt.date(2012, 1, 1)) filter.set('ltda', '10') self.assert_filter_query( filter, "WHERE persons.createdts > '2011-12-22 23:59:59.999999' AND " "persons.createdts < '2012-01-01 00:00:00.000000'")
def test_in_days(self): filter = DateTimeFilter(Person.createdts, _now=dt.datetime(2012, 1, 1, 12, 35)) filter.set('ind', '10') self.assert_filter_query( filter, "WHERE persons.createdts BETWEEN '2012-01-11 00:00:00.000000' AND " "'2012-01-11 23:59:59.999999'")
def test_today(self): filter = DateTimeFilter(Person.createdts, _now=dt.datetime(2012, 1, 1, 12, 35)) filter.set('today', None) self.assert_filter_query( filter, "WHERE persons.createdts BETWEEN '2012-01-01 00:00:00.000000' AND " "'2012-01-01 23:59:59.999999'")
def test_this_week_right_edge(self): filter = DateTimeFilter(Person.createdts, _now=dt.datetime(2012, 1, 1, 23, 59, 59, 999999)) filter.set('thisweek', None) self.assert_filter_query( filter, "WHERE persons.createdts BETWEEN '2012-01-01 00:00:00.000000' AND " "'2012-01-07 23:59:59.999999'")
def test_between_with_explicit_midnight(self): filter = DateTimeFilter(Person.createdts) filter.set('between', '1/31/2010 10:00', '12/31/2010 00:00') self.assert_filter_query( filter, "WHERE persons.createdts BETWEEN '2010-01-31 10:00:00.000000' AND " "'2010-12-31 00:00:00.000000'")
def test_arrow_support_lastmonth(self): filter = DateTimeFilter(ArrowRecord.created_utc, _now=dt.datetime(2016, 7, 18)) filter.set('lastmonth', None) self.assert_filter_query( filter, "WHERE arrow_records.created_utc BETWEEN '2016-06-01 00:00:00.000000' " "AND '2016-06-30 23:59:59.999999'")
def test_not_between(self): filter = DateTimeFilter(Person.createdts) filter.set('!between', '1/31/2010', '12/31/2010') eq_(filter.error, False) self.assert_filter_query( filter, "WHERE persons.createdts NOT BETWEEN '2010-01-31 00:00:00.000000' AND " "'2010-12-31 23:59:59.999999'")
def test_not_eq(self): filter = DateTimeFilter(Person.createdts) filter.set('!eq', '12/31/2010') self.assert_filter_query( filter, "WHERE persons.createdts NOT BETWEEN '2010-12-31 00:00:00.000000' AND " "'2010-12-31 23:59:59.999999'") eq_(filter.value1_set_with, '12/31/2010')
def test_default(self): filter = DateTimeFilter(Person.createdts, default_op='between', default_value1='1/31/2010', default_value2='12/31/2010') filter.set(None, None) self.assert_filter_query( filter, "WHERE persons.createdts BETWEEN '2010-01-31 00:00:00.000000' AND " "'2010-12-31 23:59:59.999999'")
def test_between_with_time(self): filter = DateTimeFilter(Person.createdts) filter.set('between', '1/31/2010 10:00', '12/31/2010 10:59:59') self.assert_filter_query( filter, "WHERE persons.createdts BETWEEN '2010-01-31 10:00:00.000000' AND " "'2010-12-31 10:59:59.000000'") eq_(filter.value1_set_with, '01/31/2010 10:00 AM') eq_(filter.value2_set_with, '12/31/2010 10:59 AM')
def test_this_year_default(self): filter = DateTimeFilter(Person.createdts, _now=dt.date(2012, 2, 4), default_op='thisyear') filter.set(None, None) self.assert_filter_query( filter, "WHERE persons.createdts BETWEEN '2012-01-01 00:00:00.000000' AND " "'2012-12-31 23:59:59.999999'" ) eq_(filter.description, '01/01/2012 - 12/31/2012')
def test_lte(self): filter = DateTimeFilter(Person.createdts) filter.set('lte', '12/31/2010') self.assert_filter_query(filter, "WHERE persons.createdts <= '2010-12-31 23:59:59.999999'") filter.set('lte', '12/31/2010', '') self.assert_filter_query(filter, "WHERE persons.createdts <= '2010-12-31 23:59:59.999999'") eq_(filter.value1_set_with, '12/31/2010') with assert_raises(formencode.Invalid): filter.set('lte', '')
def test_set_makes_op_none(self): filter = DateTimeFilter(Person.createdts, _now=dt.datetime(2012, 1, 1, 12, 35)) filter.op = 'foo' filter.set('', '') assert filter.op is None
def test_in_days_overflow(self): filter = DateTimeFilter(Person.due_date, _now=dt.date(2012, 1, 1)) filter.set('ind', '10000000')
def test_in_more_than_days(self): filter = DateTimeFilter(Person.createdts, _now=dt.datetime(2012, 1, 1, 12, 35)) filter.set('imtd', '10') self.assert_filter_query(filter, "WHERE persons.createdts > '2012-01-11 23:59:59.999999'")
def test_more_than_days_ago(self): filter = DateTimeFilter(Person.createdts, _now=dt.date(2012, 1, 1)) filter.set('mtda', '10') self.assert_filter_query(filter, "WHERE persons.createdts < '2011-12-22 00:00:00.000000'")
def test_not_eq_with_time(self): filter = DateTimeFilter(Person.createdts) filter.set('!eq', '12/31/2010 10:26:27') self.assert_filter_query(filter, "WHERE persons.createdts != '2010-12-31 10:26:27.000000'")
def test_this_month(self): filter = DateTimeFilter(Person.createdts, _now=dt.date(2012, 1, 4)) filter.set('thismonth', None) self.assert_filter_query(filter, self.between_sql) eq_(filter.description, '01/01/2012 - 01/31/2012')
def test_selmonth(self): filter = DateTimeFilter(Person.createdts, _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_between_blank(self): filter = DateTimeFilter(Person.createdts) with assert_raises(formencode.Invalid): filter.set('between', '', '') eq_(filter.error, True) eq_(filter.description, 'invalid')
def test_gte(self): filter = DateTimeFilter(Person.createdts) filter.set('gte', '12/31/2010') self.assert_filter_query(filter, "WHERE persons.createdts >= '2010-12-31 00:00:00.000000'") eq_(filter.value1_set_with, '12/31/2010')
def test_not_empty(self): filter = DateTimeFilter(Person.createdts) filter.set('!empty', None) self.assert_filter_query(filter, "WHERE persons.createdts IS NOT NULL") filter.set('!empty', '') self.assert_filter_query(filter, "WHERE persons.createdts IS NOT NULL")
def test_gte_with_time(self): filter = DateTimeFilter(Person.createdts) filter.set('gte', '12/31/2010 12:35') self.assert_filter_query(filter, "WHERE persons.createdts >= '2010-12-31 12:35:00.000000'")
def test_non_days_operator_with_empty_value(self): filter = DateTimeFilter(Person.createdts, _now=dt.datetime(2012, 1, 1, 12, 35)) filter.set('lastmonth', '')
def test_last_month_right_edge(self): filter = DateTimeFilter(Person.createdts, _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')