def testNotifyNobody(self): # Check that notify won't raise an exception in absence of # of subscribers. events = [] item = Contained() evt = ObjectRemovedEvent(item) objectevent.objectEventNotify(evt) self.assertEqual([], events)
def testNotify(self): events = [] def record(*args): events.append(args) ztapi.subscribe([IContained, IObjectRemovedEvent], None, record) item = Contained() event = ObjectRemovedEvent(item) objectevent.objectEventNotify(event) self.assertEqual([(item, event)], events)
def __setitem__(self, key, val): if isinstance(key, str): key = decode(key) if self._child_scope is not ONELEVEL: # XXX: this would require a default location for new entries raise NotImplementedError( u"Adding with scope != ONELEVEL not supported.") if self._key_attr != 'rdn' and self._rdn_attr is None: raise RuntimeError(u"Adding with key != rdn needs _rdn_attr " u"to be set.") if not isinstance(val, LDAPNode): # create one from whatever we got val = self._create_suitable_node(val) # At this point we need to have an LDAPNode as val if self._key_attr != 'rdn' and \ val.attrs.get(self._rdn_attr) is None: raise ValueError(u"'%s' needed in node attributes for rdn." % \ (self._rdn_attr,)) val._session = self._session if self._keys is None: self._load_keys() try: # a value with key is already in the directory self._keys[key] except KeyError: # the value is not yet in the directory val._action = ACTION_ADD val.changed = True self.changed = True self._notify_suppress = True super(LDAPNode, self).__setitem__(key, val) self._notify_suppress = False self._keys[key] = val if self._key_attr == 'rdn': rdn = key else: rdn = '%s=%s' % (self._rdn_attr, val.attrs[self._rdn_attr]) self._child_dns[key] = ','.join((rdn, self.DN)) if self._child_objectClasses: current_ocs = val.attrs.get('objectClass', []) needed_ocs = self._child_objectClasses val.attrs['objectClass'] = [ x for x in current_ocs + needed_ocs if x not in current_ocs ] if val._action == ACTION_ADD: objectEventNotify(self.events['added'](val, newParent=self, newName=key))