comparison test/test_db.py @ 825:0779ea9f1f18

More indexer work: - all String properties may now be indexed too. Currently there's a bit of "issue" specific code in the actual searching which needs to be addressed. In a nutshell: + pass 'indexme="yes"' as a String() property initialisation arg, eg: file = FileClass(db, "file", name=String(), type=String(), comment=String(indexme="yes")) + the comment will then be indexed and be searchable, with the results related back to the issue that the file is linked to - as a result of this work, the FileClass has a default MIME type that may be overridden in a subclass, or by the use of a "type" property as is done in the default templates. - the regeneration of the indexes (if necessary) is done once the schema is set up in the dbinit.
author Richard Jones <richard@users.sourceforge.net>
date Tue, 09 Jul 2002 03:02:53 +0000
parents 491049fb8e31
children 6d7a45c8464a
comparison
equal deleted inserted replaced
824:34eacaa7e313 825:0779ea9f1f18
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.23 2002-06-20 23:51:48 richard Exp $ 18 # $Id: test_db.py,v 1.24 2002-07-09 03:02:53 richard Exp $
19 19
20 import unittest, os, shutil 20 import unittest, os, shutil
21 21
22 from roundup.hyperdb import String, Password, Link, Multilink, Date, \ 22 from roundup.hyperdb import String, Password, Link, Multilink, Date, \
23 Interval, Class, DatabaseError 23 Interval, Class, DatabaseError
24 from roundup.roundupdb import FileClass 24 from roundup.roundupdb import FileClass
25 from roundup import date, password 25 from roundup import date, password
26 from roundup.indexer import Indexer
26 27
27 def setupSchema(db, create): 28 def setupSchema(db, create):
28 status = Class(db, "status", name=String()) 29 status = Class(db, "status", name=String())
29 status.setkey("name") 30 status.setkey("name")
30 user = Class(db, "user", username=String(), password=Password()) 31 user = Class(db, "user", username=String(), password=Password())
31 file = FileClass(db, "file", name=String(), type=String()) 32 file = FileClass(db, "file", name=String(), type=String(),
32 issue = Class(db, "issue", title=String(), status=Link("status"), 33 comment=String(indexme="yes"))
33 nosy=Multilink("user"), deadline=Date(), foo=Interval()) 34 issue = Class(db, "issue", title=String(indexme="yes"),
35 status=Link("status"), nosy=Multilink("user"), deadline=Date(),
36 foo=Interval(), files=Multilink("file"))
37 db.post_init()
34 if create: 38 if create:
35 status.create(name="unread") 39 status.create(name="unread")
36 status.create(name="in-progress") 40 status.create(name="in-progress")
37 status.create(name="testing") 41 status.create(name="testing")
38 status.create(name="resolved") 42 status.create(name="resolved")
110 self.db.issue.create(title="spam", status='1') 114 self.db.issue.create(title="spam", status='1')
111 self.db.issue.addprop(fixer=Link("user")) 115 self.db.issue.addprop(fixer=Link("user"))
112 props = self.db.issue.getprops() 116 props = self.db.issue.getprops()
113 keys = props.keys() 117 keys = props.keys()
114 keys.sort() 118 keys.sort()
115 self.assertEqual(keys, ['deadline', 'fixer', 'foo', 'id', 'nosy', 119 self.assertEqual(keys, ['deadline', 'files', 'fixer', 'foo', 'id',
116 'status', 'title']) 120 'nosy', 'status', 'title'])
117 self.assertEqual(self.db.issue.get('1', "fixer"), None) 121 self.assertEqual(self.db.issue.get('1', "fixer"), None)
118 122
119 def testRetire(self): 123 def testRetire(self):
120 self.db.issue.create(title="spam", status='1') 124 self.db.issue.create(title="spam", status='1')
121 b = self.db.status.get('1', 'name') 125 b = self.db.status.get('1', 'name')
244 self.assertEqual(nodeid, '1') 248 self.assertEqual(nodeid, '1')
245 self.assertEqual(journaltag, 'test') 249 self.assertEqual(journaltag, 'test')
246 self.assertEqual(action, 'create') 250 self.assertEqual(action, 'create')
247 keys = params.keys() 251 keys = params.keys()
248 keys.sort() 252 keys.sort()
249 self.assertEqual(keys, ['deadline', 'fixer', 'foo', 'nosy', 253 self.assertEqual(keys, ['deadline', 'files', 'fixer', 'foo', 'nosy',
250 'status', 'title']) 254 'status', 'title'])
251 self.assertEqual(None,params['deadline']) 255 self.assertEqual(None,params['deadline'])
252 self.assertEqual(None,params['fixer']) 256 self.assertEqual(None,params['fixer'])
253 self.assertEqual(None,params['foo']) 257 self.assertEqual(None,params['foo'])
254 self.assertEqual([],params['nosy']) 258 self.assertEqual([],params['nosy'])
294 def testIDGeneration(self): 298 def testIDGeneration(self):
295 id1 = self.db.issue.create(title="spam", status='1') 299 id1 = self.db.issue.create(title="spam", status='1')
296 id2 = self.db2.issue.create(title="eggs", status='2') 300 id2 = self.db2.issue.create(title="eggs", status='2')
297 self.assertNotEqual(id1, id2) 301 self.assertNotEqual(id1, id2)
298 302
303 def testSearching(self):
304 self.db.file.create(content='hello', type="text/plain")
305 self.db.file.create(content='world', type="text/frozz",
306 comment='blah blah')
307 self.db.issue.create(files=['1', '2'], title="flebble plop")
308 self.db.issue.create(title="flebble frooz")
309 self.db.commit()
310 self.assertEquals(self.db.indexer.search(['hello'], self.db.issue),
311 {'1': {'files': ['1']}})
312 self.assertEquals(self.db.indexer.search(['world'], self.db.issue), {})
313 self.assertEquals(self.db.indexer.search(['frooz'], self.db.issue),
314 {'2': {}})
315 self.assertEquals(self.db.indexer.search(['flebble'], self.db.issue),
316 {'2': {}, '1': {}})
317 self.assertEquals(self.db.indexer.search(['blah'], self.db.issue),
318 {'1': {'files': ['2']}})
299 319
300 class anydbmReadOnlyDBTestCase(MyTestCase): 320 class anydbmReadOnlyDBTestCase(MyTestCase):
301 def setUp(self): 321 def setUp(self):
302 from roundup.backends import anydbm 322 from roundup.backends import anydbm
303 # remove previous test, ignore errors 323 # remove previous test, ignore errors
397 417
398 return unittest.TestSuite(l) 418 return unittest.TestSuite(l)
399 419
400 # 420 #
401 # $Log: not supported by cvs2svn $ 421 # $Log: not supported by cvs2svn $
422 # Revision 1.23 2002/06/20 23:51:48 richard
423 # Cleaned up the hyperdb tests
424 #
402 # Revision 1.22 2002/05/21 05:52:11 richard 425 # Revision 1.22 2002/05/21 05:52:11 richard
403 # Well whadya know, bsddb3 works again. 426 # Well whadya know, bsddb3 works again.
404 # The backend is implemented _exactly_ the same as bsddb - so there's no 427 # The backend is implemented _exactly_ the same as bsddb - so there's no
405 # using its transaction or locking support. It'd be nice to use those some 428 # using its transaction or locking support. It'd be nice to use those some
406 # day I suppose. 429 # day I suppose.

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