Beispiel #1
0
 def testNotifyObservers_ForDifferentEventTypesWithOneEvent(self):
     self.publisher.registerObserver(self.onEvent, eventType='eventType1')
     self.publisher.registerObserver(self.onEvent2, eventType='eventType2')
     event = patterns.Event('eventType1', self)
     event.addSource(self, type='eventType2')
     event.send()
     self.assertEqual([patterns.Event('eventType1', self)], self.events)
     self.assertEqual([patterns.Event('eventType2', self)], self.events2)
Beispiel #2
0
 def testRemoveObserverForSpecificEventTypeAndSource(self):
     self.publisher.registerObserver(self.onEvent, eventType='eventType1', 
                                     eventSource='observable1')
     self.publisher.registerObserver(self.onEvent, eventType='eventType1', 
                                     eventSource='observable2')
     self.publisher.registerObserver(self.onEvent, eventType='eventType2',
                                     eventSource='observable1')
     self.publisher.removeObserver(self.onEvent, eventType='eventType1',
                                   eventSource='observable1')
     patterns.Event('eventType1', 'observable1').send()
     self.failIf(self.events)
     patterns.Event('eventType2', 'observable1').send()
     self.failUnless(self.events)
Beispiel #3
0
 def testRemoveObserver_RegisteredForSpecificSource(self):
     self.publisher.registerObserver(self.onEvent, eventType='eventType', 
                                     eventSource='observable1')
     self.publisher.removeObserver(self.onEvent)
     event = patterns.Event('eventType', 'observable1')
     event.send()
     self.failIf(self.events)
Beispiel #4
0
 def testLocationNotification(self):
     eventType = self.attachment.locationChangedEventType()
     patterns.Publisher().registerObserver(self.onEvent, eventType)
     self.attachment.setLocation('new location')
     self.assertEqual(
         [patterns.Event(eventType, self.attachment, 'new location')],
         self.events)
Beispiel #5
0
 def testRemoveChild(self):
     eventType = self.composite.removeChildEventType()
     self.registerObserver(eventType)    
     self.composite.addChild(self.child)
     self.composite.removeChild(self.child)
     self.assertEqual([patterns.Event(eventType, self.composite,
         self.child)], self.events)
Beispiel #6
0
 def testRevenueNotificationForEffortDurationChange_ChangeStart(self):
     self.task.setHourlyFee(100)
     patterns.Publisher().registerObserver(self.onEvent,
                                           eventType='effort.revenue')
     self.effort.setStart(date.DateTime(2004, 1, 1, 12, 0, 0))
     self.assertEqual(patterns.Event('effort.revenue', self.effort, 1200.0),
                      self.events[0])
Beispiel #7
0
 def expandAll(self):
     # Since the widget does not send EVT_TREE_ITEM_EXPANDED when expanding
     # all items, we have to do the bookkeeping ourselves:
     event = patterns.Event()
     for item in self.visibleItems():
         item.expand(True, context=self.settingsSection(), event=event)
     self.refresh()
Beispiel #8
0
 def testNotificationOfFirstObserverForEventType(self):
     self.publisher.registerObserver(self.onEvent, eventType='publisher.firstObserverRegisteredFor.eventType')
     self.publisher.registerObserver(self.onEvent, eventType='eventType')
     expectedEvent = patterns.Event( \
         'publisher.firstObserverRegisteredFor.eventType', self.publisher, 
         'eventType')
     self.assertEqual([expectedEvent], self.events)
Beispiel #9
0
 def testNotificationForLastObserverRemoved(self):
     self.publisher.registerObserver(self.onEvent, eventType='eventType')
     self.publisher.registerObserver(self.onEvent, eventType='publisher.lastObserverRemovedFor.eventType')
     self.publisher.removeObserver(self.onEvent, eventType='eventType')
     self.assertEqual([patterns.Event( \
         'publisher.lastObserverRemovedFor.eventType', self.publisher, 
         'eventType')], self.events)
Beispiel #10
0
    def __resolve_categories(self, categories, tasks, notes):
        def mapCategorizables(obj, resultMap, categoryMap):
            if isinstance(obj, categorizable.CategorizableCompositeObject):
                resultMap[obj.id()] = obj
            if isinstance(obj, category.Category):
                categoryMap[obj.id()] = obj
            if isinstance(obj, base.CompositeObject):
                for child in obj.children():
                    mapCategorizables(child, resultMap, categoryMap)
            if isinstance(obj, note.NoteOwner):
                for theNote in obj.notes():
                    mapCategorizables(theNote, resultMap, categoryMap)
            if isinstance(obj, attachment.AttachmentOwner):
                for theAttachment in obj.attachments():
                    mapCategorizables(theAttachment, resultMap, categoryMap)

        categorizableMap = dict()
        categoryMap = dict()
        for theCategory in categories:
            mapCategorizables(theCategory, categorizableMap, categoryMap)
        for theTask in tasks:
            mapCategorizables(theTask, categorizableMap, categoryMap)
        for theNote in notes:
            mapCategorizables(theNote, categorizableMap, categoryMap)

        event = patterns.Event()
        for categoryId, categorizableIds in self.__categorizables.items():
            theCategory = categoryMap[categoryId]
            for categorizableId in categorizableIds:
                if categorizableMap.has_key(categorizableId):
                    theCategorizable = categorizableMap[categorizableId]
                    theCategory.addCategorizable(theCategorizable)
                    theCategorizable.addCategory(theCategory, event=event)
        event.send()
Beispiel #11
0
 def set(self,
         section,
         option,
         value,
         new=False):  # pylint: disable-msg=W0221
     value = self.__escapePercentage(value)
     if new:
         currentValue = 'a new option, so use something as current value'\
             ' that is unlikely to be equal to the new value'
     else:
         currentValue = self.get(section, option)
     if value != currentValue:
         patterns.Event('before.%s.%s' % (section, option), self,
                        value).send()
         super(Settings, self).set(section, option, value)
         patterns.Event('%s.%s' % (section, option), self, value).send()
Beispiel #12
0
 def testClockNotificationResultsInRefreshedItem(self):
     self.updateViewer.widget = MockWidget()
     self.updateViewer.onEverySecond(
         patterns.Event('clock.second', date.Clock()))
     usingTaskViewer = self.ListViewerClass == gui.viewer.TaskViewer
     expected = self.trackedTask if usingTaskViewer else self.trackedEffort
     self.assertEqual([expected], self.updateViewer.widget.refreshedItems)
 def testAddTrackedEffortToTask(self):
     patterns.Publisher().registerObserver(
         self.onEvent, eventType=self.composite.trackStartEventType())
     self.task.addEffort(self.trackedEffort)
     self.assertEqual(
         patterns.Event(self.composite.trackStartEventType(),
                        self.composite, self.trackedEffort), self.events[0])
 def testThatAnHourlyFeeChangeCausesARevenueNotification(self):
     patterns.Publisher().registerObserver(self.onEvent,
                                           eventType='effort.revenue')
     self.child.setHourlyFee(100)
     self.failUnless(
         patterns.Event('effort.revenue', self.composite, 100.0) in
         self.events)
Beispiel #15
0
 def testNotifyObserver_ForSpecificSource(self):
     self.publisher.registerObserver(self.onEvent,
                                     eventType='eventType',
                                     eventSource='observable1')
     event = patterns.Event('eventType', 'observable1')
     event.send()
     self.assertEqual([event], self.events)
 def testAddEffortNotification(self):
     patterns.Publisher().registerObserver(self.onEvent,
                                           eventType='effort.duration')
     self.task.addEffort(self.effort1)
     self.assertEqual(
         patterns.Event('effort.duration', self.composite,
                        self.composite.duration()), self.events[0])
Beispiel #17
0
 def testRemoveChildNotification(self):
     patterns.Publisher().registerObserver(self.onEvent, 
         note.Note.removeChildEventType())
     self.note.addChild(self.child)
     self.note.removeChild(self.child)
     self.assertEqual(patterns.Event(note.Note.removeChildEventType(), 
         self.note, self.child), self.events[0])
Beispiel #18
0
 def testRemoveNoteNotification(self):
     self.noteOwner.addNote(self.note)
     self.registerObserver()
     self.noteOwner.removeNote(self.note)
     self.assertEqual([patterns.Event( \
         NoteOwnerUnderTest.notesChangedEventType(), self.noteOwner, self.note)], 
         self.events)
Beispiel #19
0
 def testDescriptionChangeNotification(self):
     patterns.Publisher().registerObserver(
         self.onEvent, self.note.descriptionChangedEventType())
     self.note.setDescription('Description')
     self.assertEqual(
         patterns.Event(self.note.descriptionChangedEventType(), self.note,
                        'Description'), self.events[0])
Beispiel #20
0
 def testSubjectChangeNotification(self):
     patterns.Publisher().registerObserver(
         self.onEvent, self.note.subjectChangedEventType())
     self.note.setSubject('Note')
     self.assertEqual(
         patterns.Event(self.note.subjectChangedEventType(), self.note,
                        'Note'), self.events[0])
Beispiel #21
0
 def testSelectedIconChangedNotification(self):
     eventType = categorizable.CategorizableCompositeObject.appearanceChangedEventType()
     self.registerObserver(eventType)
     self.category.addCategorizable(self.categorizable)
     self.category.setSelectedIcon('icon')
     self.assertEqual([patterns.Event(eventType, self.categorizable)],
                      self.events)
Beispiel #22
0
 def testDurationNotificationForSetStop(self):
     patterns.Publisher().registerObserver(self.onEvent,
                                           eventType='effort.duration')
     self.effort.setStop(date.DateTime.now())
     self.assertEqual(
         patterns.Event('effort.duration', self.effort,
                        self.effort.duration()), self.events[0])
Beispiel #23
0
 def testAddCompositeWithParentTriggersNotificationByParent(self):
     self.registerObserver(self.composite.addChildEventType())
     self.collection.append(self.composite)
     self.composite2.setParent(self.composite)
     self.collection.append(self.composite2)
     expectedEvent = patterns.Event(self.composite.addChildEventType(),
                                    self.composite, self.composite2)
     self.assertEqual([expectedEvent], self.events)
 def testRemoveChildWithEffortCausesEmptyNotification(self):
     patterns.Publisher().registerObserver(
         self.onEvent, eventType='effort.composite.empty')
     self.child.addEffort(self.childEffort)
     self.task.removeChild(self.child)
     self.assertEqual(
         patterns.Event('effort.composite.empty', self.composite),
         self.events[0])
 def testNoNotificationForStartTrackingIfActiveEffortOutsidePeriod(self):
     patterns.Publisher().registerObserver(
         self.onEvent, eventType=self.effort3.trackStartEventType())
     self.task.addEffort(self.effort3)
     self.effort3.setStop(date.DateTime())
     self.assertEqual(
         [patterns.Event(self.effort3.trackStartEventType(), self.effort3)],
         self.events)
 def testRemoveEffortFromChildNotification(self):
     self.child.addEffort(self.childEffort)
     patterns.Publisher().registerObserver(
         self.onEvent, eventType='effort.composite.empty')
     self.child.removeEffort(self.childEffort)
     self.assertEqual(
         patterns.Event('effort.composite.empty', self.composite),
         self.events[0])
 def testChangeTask_EmptyNotification(self):
     patterns.Publisher().registerObserver(
         self.onEvent, eventType='effort.composite.empty')
     self.task.addEffort(self.effort1)
     self.effort1.setTask(task.Task())
     self.assertEqual(
         [patterns.Event('effort.composite.empty', self.composite)],
         self.events)
 def testRemoveTrackedEffortFromChildTask(self):
     self.child.addEffort(self.trackedEffort)
     patterns.Publisher().registerObserver(
         self.onEvent, eventType=self.composite.trackStopEventType())
     self.child.removeEffort(self.trackedEffort)
     self.assertEqual(
         patterns.Event(self.composite.trackStopEventType(), self.composite,
                        self.trackedEffort), self.events[0])
Beispiel #29
0
 def testRemoveChildFromCollectionTriggersNotificationByParent(self):
     self.registerObserver(self.composite.removeChildEventType())
     self.collection.extend([self.composite, self.composite2])
     self.composite.addChild(self.composite2)
     self.collection.remove(self.composite2)
     expectedEvent = patterns.Event(self.composite.removeChildEventType(),
                                    self.composite, self.composite2)
     self.assertEqual([expectedEvent], self.events)
 def testAddEffortToChildTaskNotification(self):
     patterns.Publisher().registerObserver(self.onEvent,
                                           eventType='effort.duration')
     self.child.addEffort(self.childEffort)
     self.assertEqual(
         patterns.Event('effort.duration', self.composite,
                        self.composite.duration(recursive=True)),
         self.events[0])