Skip to content

Commit b8c7f97

Browse files
author
Andrey Lebedev
committed
unit tests for filtering ranges
1 parent b96bc09 commit b8c7f97

File tree

1 file changed

+38
-27
lines changed

1 file changed

+38
-27
lines changed

test/test_db.py

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: test_db.py,v 1.75 2003-03-10 00:22:21 richard Exp $
18+
# $Id: test_db.py,v 1.76 2003-03-10 18:16:42 kedder Exp $
1919

2020
import unittest, os, shutil, time
2121

@@ -633,11 +633,13 @@ def filteringSetup(self):
633633
iss = self.db.issue
634634
for issue in (
635635
{'title': 'issue one', 'status': '2',
636-
'foo': date.Interval('1:10')},
636+
'foo': date.Interval('1:10'),
637+
'deadline': date.Date('2003-01-01.00:00')},
637638
{'title': 'issue two', 'status': '1',
638-
'foo': date.Interval('1d')},
639+
'foo': date.Interval('1d'),
640+
'deadline': date.Date('2003-02-16.22:50')},
639641
{'title': 'issue three', 'status': '1',
640-
'nosy': ['1','2']}):
642+
'nosy': ['1','2'], 'deadline': date.Date('2003-03-08')}):
641643
self.db.issue.create(**issue)
642644
self.db.commit()
643645
return self.assertEqual, self.db.issue.filter
@@ -665,14 +667,23 @@ def testFilteringMany(self):
665667
ae(filt(None, {'nosy': '2', 'status': '1'}, ('+','id'), (None,None)),
666668
['3'])
667669

670+
def testFilteringRange(self):
671+
ae, filt = self.filteringSetup()
672+
ae(filt(None, {'deadline': 'from 2003-02-10 to 2003-02-23'}), ['2'])
673+
ae(filt(None, {'deadline': '2003-02-10; 2003-02-23'}), ['2'])
674+
ae(filt(None, {'deadline': '; 2003-02-16'}), ['1'])
675+
# Lets assume people won't invent a time machine, otherwise this test
676+
# may fail :)
677+
ae(filt(None, {'deadline': 'from 2003-02-16'}), ['2', '3'])
678+
ae(filt(None, {'deadline': '2003-02-16'}), ['2', '3'])
679+
668680
def testFilteringIntervalSort(self):
669681
ae, filt = self.filteringSetup()
670682
# ascending should sort None, 1:10, 1d
671683
ae(filt(None, {}, ('+','foo'), (None,None)), ['3', '1', '2'])
672684
# descending should sort 1d, 1:10, None
673685
ae(filt(None, {}, ('-','foo'), (None,None)), ['2', '1', '3'])
674686

675-
676687
# XXX add sorting tests for other types
677688
# XXX test auditors and reactors
678689

@@ -916,28 +927,28 @@ def suite():
916927

917928
from roundup import backends
918929
p = []
919-
# if hasattr(backends, 'mysql'):
920-
# from roundup.backends import mysql
921-
# try:
922-
# # Check if we can run mysql tests
923-
# import MySQLdb
924-
# db = mysql.Database(nodbconfig, 'admin')
925-
# db.conn.select_db(config.MYSQL_DBNAME)
926-
# db.sql("SHOW TABLES");
927-
# tables = db.sql_fetchall()
928-
# if tables:
929-
# # Database should be empty. We don't dare to delete any data
930-
# raise DatabaseError, "(Database %s contains tables)" % config.MYSQL_DBNAME
931-
# db.sql("DROP DATABASE %s" % config.MYSQL_DBNAME)
932-
# db.sql("CREATE DATABASE %s" % config.MYSQL_DBNAME)
933-
# db.close()
934-
# except (MySQLdb.ProgrammingError, DatabaseError), msg:
935-
# print "Warning! Mysql tests will not be performed", msg
936-
# print "See doc/mysql.txt for more details."
937-
# else:
938-
# p.append('mysql')
939-
# l.append(unittest.makeSuite(mysqlDBTestCase, 'test'))
940-
# l.append(unittest.makeSuite(mysqlReadOnlyDBTestCase, 'test'))
930+
if hasattr(backends, 'mysql'):
931+
from roundup.backends import mysql
932+
try:
933+
# Check if we can run mysql tests
934+
import MySQLdb
935+
db = mysql.Database(nodbconfig, 'admin')
936+
db.conn.select_db(config.MYSQL_DBNAME)
937+
db.sql("SHOW TABLES");
938+
tables = db.sql_fetchall()
939+
if tables:
940+
# Database should be empty. We don't dare to delete any data
941+
raise DatabaseError, "(Database %s contains tables)" % config.MYSQL_DBNAME
942+
db.sql("DROP DATABASE %s" % config.MYSQL_DBNAME)
943+
db.sql("CREATE DATABASE %s" % config.MYSQL_DBNAME)
944+
db.close()
945+
except (MySQLdb.ProgrammingError, DatabaseError), msg:
946+
print "Warning! Mysql tests will not be performed", msg
947+
print "See doc/mysql.txt for more details."
948+
else:
949+
p.append('mysql')
950+
l.append(unittest.makeSuite(mysqlDBTestCase, 'test'))
951+
l.append(unittest.makeSuite(mysqlReadOnlyDBTestCase, 'test'))
941952
#return unittest.TestSuite(l)
942953

943954
if hasattr(backends, 'gadfly'):

0 commit comments

Comments
 (0)