Ejemplo n.º 1
0
    def testUnionQuery(self):
        """ Test a union query """
        import osaf.pim.tests.GenerateItems as GenerateItems

        self.loadParcels(['parcel:osaf.pim'])

        #create test data
        view = self.rep.view
        GenerateItems.GenerateItems(view, 20, GenerateItems.GenerateNote)
        GenerateItems.GenerateItems(view,
                                    20,
                                    GenerateItems.GenerateCalendarEvent,
                                    days=5)
        GenerateItems.GenerateItems(view, 10, GenerateItems.GenerateContact)

        view.commit()

        results = self._compileQuery(
            'testUnionQuery',
            'union(for i in "//parcels/osaf/pim/calendar/CalendarEvent" where True, for i in "//parcels/osaf/pim/Note" where True, for i in "//parcels/osaf/pim/contacts/Contact" where True)'
        )
        # these checks could be more robust
        # check twice to make sure generator restarts
        self._checkQuery(lambda i: False, results)
        self._checkQuery(lambda i: False, results)
Ejemplo n.º 2
0
    def testCollectionEvents(self):

        self.loadParcel("parcel:osaf.pim.calendar")

        view = self.rep.view
        ic = pim.ItemCollection("TestCollectionEvents", view=view)
        for index in range(100):
            item = GenerateItems.GenerateCalendarEvent(view, 100)
            ic.add(item)

            # test __contains__
            self.assert_(item in ic)

        # test __len__
        self.assert_(len(ic) > 0)

        # pick a random item in the item collection
        item = random.choice(ic)

        # test index
        index = ic.index(item)

        # test __getitem__
        self.assert_(item == ic[index])

        del index

        # test exclude
        ic.remove(item)
        self.assert_(item not in ic)
Ejemplo n.º 3
0
    def testGeneratedContacts(self):

        self.loadParcels(["parcel:osaf.pim.contacts", "parcel:osaf.pim.mail"])

        view = self.rep.view
        GenerateItems.GenerateItems(view, 100, GenerateItems.GenerateContact)
        view.commit()
Ejemplo n.º 4
0
 def onGenerateContentItemsEvent(self, event):
     # triggered from "Test | Generate Some Content Items" and
     # "Test | Generate Many Content Items" menu items
     count = event.arguments['sender'].blockName == 'GenerateMuchDataItem' and 100 or 4
     sidebarCollection = Block.findBlockByName ("Sidebar").contents
     mainView = Globals.views[0]
     return GenerateItems.GenerateAllItems(self.itsView, count, mainView, sidebarCollection)
Ejemplo n.º 5
0
    def testDateQuery(self):
        """ Test a date range in the query predicate """
        import osaf.pim.tests.GenerateItems as GenerateItems

        self.loadParcels(['parcel:osaf.pim.calendar'])

        view = self.rep.view
        GenerateItems.GenerateItems(view, 100,
                                    GenerateItems.GenerateCalendarEvent)

        view.commit()

        # since GenerateCalenderEventItems generates events offset from now(),
        # need to dynamically compute the date range for the query
        from datetime import date, datetime
        now = date.today()
        year = now.year
        month = now.month
        startDate = datetime(year, month, 1)
        if month == 12:
            month = 1
            year = year + 1
        else:
            month = month + 1
        endDate = datetime(year, month, 1)

        queryString = u"for i in '//parcels/osaf/pim/calendar/CalendarEvent' where i.startTime > date(\"%s\") and i.startTime < date(\"%s\")" % (
            startDate.date(), endDate.date())
        results = self._compileQuery('testDateQuery', queryString)
        self._checkQuery(
            lambda i: not (i.startTime > startDate and i.startTime < endDate),
            results)
Ejemplo n.º 6
0
    def testGeneratedEvents(self):

        self.loadParcel("parcel:osaf.pim.calendar")

        view = self.rep.view
        GenerateItems.GenerateItems(view, 100, GenerateItems.GenerateCalendarEvent, days=100)
        view.commit()
Ejemplo n.º 7
0
    def testRule(self):
        import logging
        log = logging.getLogger("Test")
        log.setLevel(logging.DEBUG)

        self.loadParcel("parcel:osaf.pim.calendar")

        log.debug("Generating calendar events")
        view = self.rep.view
        item = GenerateItems.GenerateCalendarEvent(view, 100)
        view.commit()

        log.debug("Creating ItemCollection")
        ic = pim.ItemCollection("TestRule", view=view)
        ic.subscribe()

        # a newly initialized query with no string has a size 0 rsult
        self.assertEqual(0, len(ic))

        # give it a real query string
        log.debug("Setting rule attribute")
        ic.rule = 'for i inevery "//parcels/osaf/pim/calendar/CalendarEvent" where True'
        log.debug("Committing ItemCollection")
        view.commit()
        print "Rule/ItemCollection: %s, %s" % (ic.rule, ic.itsUUID)
        self.assertEqual(1, len([i for i in ic]))

        # test notification
        item = GenerateItems.GenerateCalendarEvent(view, 100)
        view.commit()
        self.assertEqual(2, len(ic))
        view.commit()

        # see if we can reload stored data
        uuid = ic.itsUUID
        ic = None
        self._reopenRepository()
        view = self.rep.view
        log.debug("reloading ItemCollection")
        ic = view.findUUID(uuid)
        self.assertEqual(2, len([i for i in ic]))
Ejemplo n.º 8
0
    def testItemTraversalQuery(self):
        """ Test a multiple item path traversal in the query predicate """
        import osaf.pim.tests.GenerateItems as GenerateItems

        self.loadParcels(['parcel:osaf.pim.contacts'])

        view = self.rep.view
        GenerateItems.GenerateItems(view, 100, GenerateItems.GenerateContact)

        view.commit()

        results = self._compileQuery(
            'testItemTraversalQuery',
            u"for i in '//parcels/osaf/pim/contacts/Contact' where contains(i.contactName.firstName,'a')"
        )
        self._checkQuery(lambda i: not 'a' in i.contactName.firstName, results)
Ejemplo n.º 9
0
    def testEnumerationQuery(self):
        """ Test an enumeration attribute in the query predicate """
        import osaf.pim.tests.GenerateItems as GenerateItems

        self.loadParcels(['parcel:osaf.pim.calendar'])

        view = self.rep.view
        GenerateItems.GenerateItems(view, 100,
                                    GenerateItems.GenerateCalendarEvent)

        view.commit()

        results = self._compileQuery(
            'testEnumerationQuery',
            u"for i in '//parcels/osaf/pim/calendar/CalendarEvent' where i.importance == 'fyi'"
        )
        self._checkQuery(lambda i: not i.importance == 'fyi', results)
Ejemplo n.º 10
0
    def testLoadGenerateCommitContacts(self):
        """ Test loading, generating, and commiting contacts """
        util.timing.reset()
        util.timing.begin("application.tests.testParcelPerf.testContacts-load")
        self.loadParcels(['parcel:osaf.pim.contacts'])
        util.timing.end("application.tests.testParcelPerf.testContacts-load")

        view = self.rep.view
        util.timing.begin(
            "application.tests.testParcelPerf.testContacts-generate")
        GenerateItems.GenerateItems(view, 100, GenerateItems.GenerateContact)
        util.timing.end(
            "application.tests.testParcelPerf.testContacts-generate")

        util.timing.begin(
            "application.tests.testParcelPerf.testContacts-commit")
        view.commit()
        util.timing.end("application.tests.testParcelPerf.testContacts-commit")
        util.timing.results(verbose=False)