Mercurial > p > roundup > code
comparison test/db_test_base.py @ 1988:5660b89f8903
more compliance testing, this time for find()
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Tue, 20 Jan 2004 05:55:51 +0000 |
| parents | 910b39f8c5b8 |
| children | b1704ba7be41 |
comparison
equal
deleted
inserted
replaced
| 1987:d3df62136c30 | 1988:5660b89f8903 |
|---|---|
| 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: db_test_base.py,v 1.13 2004-01-20 03:58:38 richard Exp $ | 18 # $Id: db_test_base.py,v 1.14 2004-01-20 05:55:51 richard Exp $ |
| 19 | 19 |
| 20 import unittest, os, shutil, errno, imp, sys, time, pprint | 20 import unittest, os, shutil, errno, imp, sys, time, pprint |
| 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 |
| 619 {'1': {}}) | 619 {'1': {}}) |
| 620 | 620 |
| 621 # | 621 # |
| 622 # searching tests follow | 622 # searching tests follow |
| 623 # | 623 # |
| 624 def testFind(self): | 624 def testFindIncorrectProperty(self): |
| 625 self.assertRaises(TypeError, self.db.issue.find, title='fubar') | 625 self.assertRaises(TypeError, self.db.issue.find, title='fubar') |
| 626 | 626 |
| 627 self.db.user.create(username='test') | 627 def _find_test_setup(self): |
| 628 ids = [] | 628 self.db.file.create(content='') |
| 629 ids.append(self.db.issue.create(status="1", nosy=['1'])) | 629 self.db.file.create(content='') |
| 630 oddid = self.db.issue.create(status="2", nosy=['2'], assignedto='2') | 630 self.db.user.create(username='') |
| 631 ids.append(self.db.issue.create(status="1", nosy=['1','2'])) | 631 one = self.db.issue.create(status="1", nosy=['1']) |
| 632 self.db.issue.create(status="3", nosy=['1'], assignedto='1') | 632 two = self.db.issue.create(status="2", nosy=['2'], files=['1'], |
| 633 ids.sort() | 633 assignedto='2') |
| 634 | 634 three = self.db.issue.create(status="1", nosy=['1','2']) |
| 635 # should match first and third | 635 four = self.db.issue.create(status="3", assignedto='1', |
| 636 files=['1','2']) | |
| 637 return one, two, three, four | |
| 638 | |
| 639 def testFindLink(self): | |
| 640 one, two, three, four = self._find_test_setup() | |
| 636 got = self.db.issue.find(status='1') | 641 got = self.db.issue.find(status='1') |
| 637 got.sort() | 642 got.sort() |
| 638 self.assertEqual(got, ids) | 643 self.assertEqual(got, [one, three]) |
| 639 got = self.db.issue.find(status={'1':1}) | 644 got = self.db.issue.find(status={'1':1}) |
| 640 got.sort() | 645 got.sort() |
| 641 self.assertEqual(got, ids) | 646 self.assertEqual(got, [one, three]) |
| 642 | 647 |
| 643 # none | 648 def testFindLinkFail(self): |
| 649 self._find_test_setup() | |
| 644 self.assertEqual(self.db.issue.find(status='4'), []) | 650 self.assertEqual(self.db.issue.find(status='4'), []) |
| 645 self.assertEqual(self.db.issue.find(status={'4':1}), []) | 651 self.assertEqual(self.db.issue.find(status={'4':1}), []) |
| 646 | 652 |
| 647 # should match first and third | 653 def testFindLinkUnset(self): |
| 654 one, two, three, four = self._find_test_setup() | |
| 648 got = self.db.issue.find(assignedto=None) | 655 got = self.db.issue.find(assignedto=None) |
| 649 got.sort() | 656 got.sort() |
| 650 self.assertEqual(got, ids) | 657 self.assertEqual(got, [one, three]) |
| 651 got = self.db.issue.find(assignedto={None:1}) | 658 got = self.db.issue.find(assignedto={None:1}) |
| 652 got.sort() | 659 got.sort() |
| 653 self.assertEqual(got, ids) | 660 self.assertEqual(got, [one, three]) |
| 654 | 661 |
| 655 # should match first three | 662 def testFindMultilink(self): |
| 663 one, two, three, four = self._find_test_setup() | |
| 664 got = self.db.issue.find(nosy='2') | |
| 665 got.sort() | |
| 666 self.assertEqual(got, [two, three]) | |
| 667 got = self.db.issue.find(nosy={'2':1}) | |
| 668 got.sort() | |
| 669 self.assertEqual(got, [two, three]) | |
| 670 got = self.db.issue.find(nosy={'2':1}, files={}) | |
| 671 got.sort() | |
| 672 self.assertEqual(got, [two, three]) | |
| 673 | |
| 674 def testFindMultiMultilink(self): | |
| 675 one, two, three, four = self._find_test_setup() | |
| 676 got = self.db.issue.find(nosy='2', files='1') | |
| 677 got.sort() | |
| 678 self.assertEqual(got, [two, three, four]) | |
| 679 got = self.db.issue.find(nosy={'2':1}, files={'1':1}) | |
| 680 got.sort() | |
| 681 self.assertEqual(got, [two, three, four]) | |
| 682 | |
| 683 def testFindMultilinkFail(self): | |
| 684 self._find_test_setup() | |
| 685 self.assertEqual(self.db.issue.find(nosy='3'), []) | |
| 686 self.assertEqual(self.db.issue.find(nosy={'3':1}), []) | |
| 687 | |
| 688 def testFindMultilinkUnset(self): | |
| 689 self._find_test_setup() | |
| 690 self.assertEqual(self.db.issue.find(nosy={}), []) | |
| 691 | |
| 692 def testFindLinkAndMultilink(self): | |
| 693 one, two, three, four = self._find_test_setup() | |
| 656 got = self.db.issue.find(status='1', nosy='2') | 694 got = self.db.issue.find(status='1', nosy='2') |
| 657 got.sort() | 695 got.sort() |
| 658 ids.append(oddid) | 696 self.assertEqual(got, [one, two, three]) |
| 659 ids.sort() | |
| 660 self.assertEqual(got, ids) | |
| 661 got = self.db.issue.find(status={'1':1}, nosy={'2':1}) | 697 got = self.db.issue.find(status={'1':1}, nosy={'2':1}) |
| 662 got.sort() | 698 got.sort() |
| 663 self.assertEqual(got, ids) | 699 self.assertEqual(got, [one, two, three]) |
| 664 | 700 |
| 665 # none | 701 def testFindRetired(self): |
| 666 self.assertEqual(self.db.issue.find(status='4', nosy='3'), []) | 702 one, two, three, four = self._find_test_setup() |
| 667 self.assertEqual(self.db.issue.find(status={'4':1}, nosy={'3':1}), []) | 703 self.assertEqual(len(self.db.issue.find(status='1')), 2) |
| 668 | 704 self.db.issue.retire(one) |
| 669 # test retiring a node | 705 self.assertEqual(len(self.db.issue.find(status='1')), 1) |
| 670 self.db.issue.retire(ids[0]) | |
| 671 self.assertEqual(len(self.db.issue.find(status='1', nosy='2')), 2) | |
| 672 | 706 |
| 673 def testStringFind(self): | 707 def testStringFind(self): |
| 674 self.assertRaises(TypeError, self.db.issue.stringFind, status='1') | 708 self.assertRaises(TypeError, self.db.issue.stringFind, status='1') |
| 675 | 709 |
| 676 ids = [] | 710 ids = [] |
