[Commits] (twl) Add tests for date ranges and full text queries
commits at osafoundation.org
commits at osafoundation.org
Thu Sep 2 16:05:31 PDT 2004
Commit by: twl
Modified files:
chandler/repository/query/tests/TestSimpleQueries.py 1.9 1.10
Log message:
Add tests for date ranges and full text queries
ViewCVS links:
http://cvs.osafoundation.org/index.cgi/chandler/repository/query/tests/TestSimpleQueries.py.diff?r1=text&tr1=1.9&r2=text&tr2=1.10
Index: chandler/repository/query/tests/TestSimpleQueries.py
diff -u chandler/repository/query/tests/TestSimpleQueries.py:1.9 chandler/repository/query/tests/TestSimpleQueries.py:1.10
--- chandler/repository/query/tests/TestSimpleQueries.py:1.9 Wed Sep 1 15:38:10 2004
+++ chandler/repository/query/tests/TestSimpleQueries.py Thu Sep 2 16:05:29 2004
@@ -1,6 +1,6 @@
-__revision__ = "$Revision: 1.9 $"
-__date__ = "$Date: 2004/09/01 22:38:10 $"
+__revision__ = "$Revision: 1.10 $"
+__date__ = "$Date: 2004/09/02 23:05:29 $"
__copyright__ = "Copyright (c) 2004 Open Source Applications Foundation"
__license__ = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
@@ -145,6 +145,66 @@
q.execute()
self._checkQuery(lambda i: not pattern in i.itsName, q)
+ def testDateQuery(self):
+ """ Test a date range in the query predicate """
+ tools.timing.reset()
+ import osaf.contentmodel.tests.GenerateItems as GenerateItems
+
+ tools.timing.begin("Load Calendar Parcel")
+ self.loadParcels(
+ ['http://osafoundation.org/parcels/osaf/contentmodel/calendar']
+ )
+ tools.timing.end("Load Calendar Parcel")
+
+ tools.timing.begin("Generate Calendar Events")
+ GenerateItems.generateCalendarEventItems(100,30)
+ tools.timing.end("Generate Calendar Events")
+
+ tools.timing.begin("Commit Calendar Events")
+ self.rep.commit()
+ tools.timing.end("Commit Calendar Events")
+# tools.timing.results()
+
+ # since GenerateCalenderEventItems generates events offset from now(),
+ # need to dynamically compute the date range for the query
+ import mx.DateTime
+ now = mx.DateTime.now()
+ year = now.year
+ month = now.month
+ startDateString = "%d-%d-%d" % (year,month,1)
+ startDate = mx.DateTime.ISO.ParseDate(startDateString)
+ startDateString = startDate.date
+ endDateString = "%d-%d-%d" % (year,month+1,1)
+ endDate = mx.DateTime.ISO.ParseDate(endDateString) -1
+ endDateString = endDate.date
+
+ queryString = u"for i in '//parcels/osaf/contentmodel/calendar/CalendarEvent' where i.startTime > date(\"%s\") and i.startTime < date(\"%s\")" % (startDate.date,endDate.date)
+ results = self._executeQuery(queryString)
+ self._checkQuery(lambda i: not (i.startTime > startDate and i.startTime < endDate), results)
+
+ def testTextQuery(self):
+ """ Test a free text query """
+
+ def checkLob(lob, value):
+ reader = lob.getReader()
+ text = reader.read()
+ reader.close()
+ return value in text
+
+ #@@@ use cineguide pack until we can do this from parcel.xml
+ cineguidePack = os.path.join(self.rootdir,'repository', 'tests', 'data', 'packs', 'cineguide.pack')
+ self.rep.loadPack(cineguidePack)
+ self.rep.commit()
+
+ results = self._executeQuery(u"for i in ftcontains('femme AND homme') where True")
+ self._checkQuery(lambda i: not (checkLob(i.synopsis,"femme") and checkLob(i.synopsis,"homme")), results)
+
+ results = self._executeQuery(u"for i in ftcontains('femme AND homme','synopsis') where True")
+ self._checkQuery(lambda i: not (checkLob(i.synopsis,"femme") and checkLob(i.synopsis,"homme")), results)
+
+ results = self._executeQuery(u"for i in ftcontains('femme AND homme','synopsis') where len(i.title) < 10")
+ self._checkQuery(lambda i: not (checkLob(i.synopsis,"femme") and checkLob(i.synopsis,"homme") and len(i.title) < 10), results)
+
if __name__ == "__main__":
# import hotshot
# profiler = hotshot.Profile('/tmp/TestItems.hotshot')
More information about the Commits
mailing list