comparison test/test_db.py @ 1506:8b698780bb7d

unit tests for filtering ranges
author Andrey Lebedev <kedder@users.sourceforge.net>
date Mon, 10 Mar 2003 18:16:42 +0000
parents c101d2ff5a20
children 6fede2aa6a12
comparison
equal deleted inserted replaced
1505:c101d2ff5a20 1506:8b698780bb7d
13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" 14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, 15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
17 # 17 #
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 $
19 19
20 import unittest, os, shutil, time 20 import unittest, os, shutil, time
21 21
22 from roundup.hyperdb import String, Password, Link, Multilink, Date, \ 22 from roundup.hyperdb import String, Password, Link, Multilink, Date, \
23 Interval, DatabaseError, Boolean, Number, Node 23 Interval, DatabaseError, Boolean, Number, Node
631 {'username': 'blorp'}): 631 {'username': 'blorp'}):
632 self.db.user.create(**user) 632 self.db.user.create(**user)
633 iss = self.db.issue 633 iss = self.db.issue
634 for issue in ( 634 for issue in (
635 {'title': 'issue one', 'status': '2', 635 {'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')},
637 {'title': 'issue two', 'status': '1', 638 {'title': 'issue two', 'status': '1',
638 'foo': date.Interval('1d')}, 639 'foo': date.Interval('1d'),
640 'deadline': date.Date('2003-02-16.22:50')},
639 {'title': 'issue three', 'status': '1', 641 {'title': 'issue three', 'status': '1',
640 'nosy': ['1','2']}): 642 'nosy': ['1','2'], 'deadline': date.Date('2003-03-08')}):
641 self.db.issue.create(**issue) 643 self.db.issue.create(**issue)
642 self.db.commit() 644 self.db.commit()
643 return self.assertEqual, self.db.issue.filter 645 return self.assertEqual, self.db.issue.filter
644 646
645 def testFilteringID(self): 647 def testFilteringID(self):
662 664
663 def testFilteringMany(self): 665 def testFilteringMany(self):
664 ae, filt = self.filteringSetup() 666 ae, filt = self.filteringSetup()
665 ae(filt(None, {'nosy': '2', 'status': '1'}, ('+','id'), (None,None)), 667 ae(filt(None, {'nosy': '2', 'status': '1'}, ('+','id'), (None,None)),
666 ['3']) 668 ['3'])
669
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'])
667 679
668 def testFilteringIntervalSort(self): 680 def testFilteringIntervalSort(self):
669 ae, filt = self.filteringSetup() 681 ae, filt = self.filteringSetup()
670 # ascending should sort None, 1:10, 1d 682 # ascending should sort None, 1:10, 1d
671 ae(filt(None, {}, ('+','foo'), (None,None)), ['3', '1', '2']) 683 ae(filt(None, {}, ('+','foo'), (None,None)), ['3', '1', '2'])
672 # descending should sort 1d, 1:10, None 684 # descending should sort 1d, 1:10, None
673 ae(filt(None, {}, ('-','foo'), (None,None)), ['2', '1', '3']) 685 ae(filt(None, {}, ('-','foo'), (None,None)), ['2', '1', '3'])
674
675 686
676 # XXX add sorting tests for other types 687 # XXX add sorting tests for other types
677 # XXX test auditors and reactors 688 # XXX test auditors and reactors
678 689
679 class anydbmReadOnlyDBTestCase(MyTestCase): 690 class anydbmReadOnlyDBTestCase(MyTestCase):
914 ] 925 ]
915 # return unittest.TestSuite(l) 926 # return unittest.TestSuite(l)
916 927
917 from roundup import backends 928 from roundup import backends
918 p = [] 929 p = []
919 # if hasattr(backends, 'mysql'): 930 if hasattr(backends, 'mysql'):
920 # from roundup.backends import mysql 931 from roundup.backends import mysql
921 # try: 932 try:
922 # # Check if we can run mysql tests 933 # Check if we can run mysql tests
923 # import MySQLdb 934 import MySQLdb
924 # db = mysql.Database(nodbconfig, 'admin') 935 db = mysql.Database(nodbconfig, 'admin')
925 # db.conn.select_db(config.MYSQL_DBNAME) 936 db.conn.select_db(config.MYSQL_DBNAME)
926 # db.sql("SHOW TABLES"); 937 db.sql("SHOW TABLES");
927 # tables = db.sql_fetchall() 938 tables = db.sql_fetchall()
928 # if tables: 939 if tables:
929 # # Database should be empty. We don't dare to delete any data 940 # Database should be empty. We don't dare to delete any data
930 # raise DatabaseError, "(Database %s contains tables)" % config.MYSQL_DBNAME 941 raise DatabaseError, "(Database %s contains tables)" % config.MYSQL_DBNAME
931 # db.sql("DROP DATABASE %s" % config.MYSQL_DBNAME) 942 db.sql("DROP DATABASE %s" % config.MYSQL_DBNAME)
932 # db.sql("CREATE DATABASE %s" % config.MYSQL_DBNAME) 943 db.sql("CREATE DATABASE %s" % config.MYSQL_DBNAME)
933 # db.close() 944 db.close()
934 # except (MySQLdb.ProgrammingError, DatabaseError), msg: 945 except (MySQLdb.ProgrammingError, DatabaseError), msg:
935 # print "Warning! Mysql tests will not be performed", msg 946 print "Warning! Mysql tests will not be performed", msg
936 # print "See doc/mysql.txt for more details." 947 print "See doc/mysql.txt for more details."
937 # else: 948 else:
938 # p.append('mysql') 949 p.append('mysql')
939 # l.append(unittest.makeSuite(mysqlDBTestCase, 'test')) 950 l.append(unittest.makeSuite(mysqlDBTestCase, 'test'))
940 # l.append(unittest.makeSuite(mysqlReadOnlyDBTestCase, 'test')) 951 l.append(unittest.makeSuite(mysqlReadOnlyDBTestCase, 'test'))
941 #return unittest.TestSuite(l) 952 #return unittest.TestSuite(l)
942 953
943 if hasattr(backends, 'gadfly'): 954 if hasattr(backends, 'gadfly'):
944 p.append('gadfly') 955 p.append('gadfly')
945 l.append(unittest.makeSuite(gadflyDBTestCase, 'test')) 956 l.append(unittest.makeSuite(gadflyDBTestCase, 'test'))

Roundup Issue Tracker: http://roundup-tracker.org/